-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support to pull NIM profiles from GCS cache #93
Open
pwschuurman
wants to merge
1
commit into
NVIDIA:main
Choose a base branch
from
pwschuurman:gcs-url-extract-cache
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
cloud-service-providers/google-cloud/gke/infra/3-config/artifacts/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM debian:bookworm-slim | ||
RUN apt-get update && apt-get install -y aria2 pigz | ||
ENTRYPOINT ["/bin/sh"] |
14 changes: 14 additions & 0 deletions
14
cloud-service-providers/google-cloud/gke/infra/3-config/fetch-ngc-url.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/sh | ||
|
||
# use --token-format=full for print-identity-token if using GCE VM. | ||
cat <<EOF > req.cred.json | ||
{ | ||
"bucket": "${NIM_GCS_BUCKET}", | ||
"text": "${NGC_EULA_TEXT}", | ||
"textb64": "$(echo ${NGC_EULA_TEXT} | base64 -w0)", | ||
"jwt": "$(gcloud auth print-identity-token)" | ||
} | ||
EOF | ||
|
||
HTTP_URL="$(curl -s -X POST -H 'accept: application/json' -H 'Content-Type: application/json' -d @req.cred.json "https://${SERVICE_FQDN}/v1/request/${GCS_FILENAME}" | sed 's/.*\(https.*\)\\\\n.*/\1/g')" | ||
echo -n "$HTTP_URL" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
cloud-service-providers/google-cloud/gke/infra/3-config/helm/ngc-cache/files/ngc_pull.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
export CACHE_PATH="$NIM_CACHE_PATH" | ||
|
||
if [ -n "${NGC_BUNDLE_URL:-}" ]; then | ||
# Create a sub-directory, as tar tries to modify the parent folder permissions | ||
export CACHE_PATH="$NIM_CACHE_PATH/cache" | ||
mkdir "$CACHE_PATH" | ||
MODEL_BUNDLE_FILENAME="model.tar" | ||
# Fetch and extract from the provided URL, with max concurrency | ||
aria2c -x 16 -s 16 -j 10 --dir "$CACHE_PATH" --out="$MODEL_BUNDLE_FILENAME" "$NGC_BUNDLE_URL" | ||
tar xf "$CACHE_PATH/$MODEL_BUNDLE_FILENAME" -C "$CACHE_PATH" | ||
rm "$CACHE_PATH/$MODEL_BUNDLE_FILENAME" | ||
else | ||
# Fetch directly from NGC to $NIM_CACHE_PATH | ||
download-to-cache | ||
fi | ||
|
||
find $CACHE_PATH -type d -printf '%P\n' | xargs -P 100 -I {} mkdir -p /upload-dir/{} | ||
find $CACHE_PATH -type f,l -printf '%P\n' | xargs -P 100 -I {} cp --no-dereference $CACHE_PATH/{} /upload-dir/{} |
11 changes: 11 additions & 0 deletions
11
...service-providers/google-cloud/gke/infra/3-config/helm/ngc-cache/templates/configmap.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: {{ .Release.Name }}-scripts-configmap | ||
labels: | ||
{{- include "nim-llm.labels" . | nindent 4 }} | ||
data: | ||
ngc_pull.sh: |- | ||
{{ .Files.Get "files/ngc_pull.sh" | indent 4 }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ data "google_project" "current" { | |
locals { | ||
cluster_name = data.terraform_remote_state.gke-cluster.outputs.cluster_name | ||
cluster_location = data.terraform_remote_state.gke-cluster.outputs.cluster_location | ||
use_bundle_url = var.ngc_bundle_gcs_bucket != "" && var.ngc_bundle_filename != "" | ||
} | ||
|
||
provider "kubernetes" { | ||
|
@@ -48,13 +49,39 @@ resource "null_resource" "get-credentials" { | |
|
||
} | ||
|
||
data "local_file" "ngc-eula" { | ||
filename = "${path.module}/NIM_GKE_GCS_SIGNED_URL_EULA" | ||
} | ||
|
||
resource "null_resource" "get-signed-ngc-bundle-url" { | ||
count = local.use_bundle_url ? 1 : 0 | ||
triggers = { | ||
shell_hash = "${sha256(file("${path.module}/fetch-ngc-url.sh"))}" | ||
} | ||
provisioner "local-exec" { | ||
command = "./fetch-ngc-url.sh > ${path.module}/ngc_signed_url.txt" | ||
environment = { | ||
NGC_EULA_TEXT = "${data.local_file.ngc-eula.content}" | ||
NIM_GCS_BUCKET = "${var.ngc_bundle_gcs_bucket}" | ||
GCS_FILENAME = "${var.ngc_bundle_filename}" | ||
SERVICE_FQDN = "nim-gke-gcs-signed-url-722708171432.us-central1.run.app" | ||
} | ||
} | ||
} | ||
|
||
data "local_file" "ngc-bundle-url" { | ||
count = local.use_bundle_url ? 1 : 0 | ||
filename = "${path.module}/ngc_signed_url.txt" | ||
depends_on = [null_resource.get-signed-ngc-bundle-url] | ||
} | ||
|
||
resource "kubernetes_namespace" "nim" { | ||
metadata { | ||
name = "nim" | ||
} | ||
} | ||
|
||
resource "kubernetes_secret" "registry_secret" { | ||
resource "kubernetes_secret" "ngc_registry_secret" { | ||
metadata { | ||
name = "registry-secret" | ||
namespace = "nim" | ||
|
@@ -65,7 +92,7 @@ resource "kubernetes_secret" "registry_secret" { | |
data = { | ||
".dockerconfigjson" = jsonencode({ | ||
"auths" = { | ||
"${var.registry_server}" = { | ||
"${var.ngc_registry_server}" = { | ||
"username" = var.ngc_username | ||
"password" = var.ngc_api_key | ||
"auth" = base64encode("${var.ngc_username}:${var.ngc_api_key}") | ||
|
@@ -90,7 +117,22 @@ resource "kubernetes_secret" "ngc_api" { | |
} | ||
|
||
depends_on = [kubernetes_namespace.nim] | ||
} | ||
|
||
resource "kubernetes_secret" "ngc_bundle_url" { | ||
count = local.use_bundle_url ? 1 : 0 | ||
metadata { | ||
name = "ngc-bundle-url" | ||
namespace = "nim" | ||
} | ||
|
||
type = "Opaque" # Generic secret type | ||
|
||
data = { | ||
"NGC_BUNDLE_URL" = "${data.local_file.ngc-bundle-url[0].content}" | ||
} | ||
|
||
depends_on = [kubernetes_namespace.nim] | ||
} | ||
|
||
resource "kubernetes_service_account" "ngc_gcs_ksa" { | ||
|
@@ -101,9 +143,12 @@ resource "kubernetes_service_account" "ngc_gcs_ksa" { | |
depends_on = [kubernetes_namespace.nim] | ||
} | ||
|
||
resource "random_uuid" "gcs_cache_uuid" { | ||
} | ||
|
||
resource "google_storage_bucket" "ngc_gcs_cache" { | ||
project = data.google_project.current.name | ||
name = "${data.google_project.current.name}-ngc-gcs-cache" | ||
name = "ngc-gcs-cache-${random_uuid.gcs_cache_uuid.result}" | ||
location = "US" | ||
force_destroy = true | ||
|
||
|
@@ -143,12 +188,12 @@ resource "helm_release" "ngc_to_gcs_transfer" { | |
|
||
set { | ||
name = "image.repository" | ||
value = var.repository | ||
value = var.ngc_transfer_repository | ||
} | ||
|
||
set { | ||
name = "image.tag" | ||
value = var.tag | ||
value = var.ngc_transfer_tag | ||
} | ||
|
||
set { | ||
|
@@ -166,9 +211,9 @@ resource "helm_release" "ngc_to_gcs_transfer" { | |
value = var.gpu_limits | ||
} | ||
|
||
depends_on = [kubernetes_secret.ngc_api, google_storage_bucket_iam_binding.ngc_gcs_ksa_binding] | ||
depends_on = [kubernetes_secret.ngc_api, kubernetes_secret.ngc_bundle_url, google_storage_bucket_iam_binding.ngc_gcs_ksa_binding] | ||
|
||
timeout = 900 | ||
timeout = 3600 | ||
wait = true | ||
} | ||
|
||
|
@@ -184,17 +229,17 @@ resource "helm_release" "my_nim" { | |
|
||
set { | ||
name = "csi.volumeAttributes.bucketName" | ||
value = google_storage_bucket.ngc_gcs_cache.name | ||
value = "ngc-gcs-cache-5f0f6937-fad0-1df7-025e-a912ebf61647" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we mean for this to be a static value? Is there anything significant about this specific bucket? |
||
} | ||
|
||
set { | ||
name = "image.repository" | ||
value = var.repository | ||
value = var.ngc_nim_repository | ||
} | ||
|
||
set { | ||
name = "image.tag" | ||
value = var.tag | ||
value = var.ngc_nim_tag | ||
} | ||
|
||
set { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be mkdir -p?