Skip to content
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

feat: add deployment of nvidia nim #803

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Deploy NVIDIA NIMs on GKE
130 changes: 130 additions & 0 deletions best-practices/ml-platform/terraform/features/nim/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
data "google_container_cluster" "nim-llm" {
name = var.cluster-name
location = var.cluster-location
}

data "google_client_config" "current" {

}

resource "kubernetes_namespace" "nim" {
metadata {
name = var.kubernetes-namespace
}
}

resource "kubernetes_secret" "ngc-secret" {
metadata {
name = "ngc-secret"
namespace = kubernetes_namespace.nim.metadata.0.name
}

type = "kubernetes.io/dockerconfigjson"

data = {
".dockerconfigjson" = jsonencode({
"auths" = {
"nvcr.io" = {
"username" = "$oauthtoken"
"password" = var.ngc-api-key
"auth" = base64encode("$oauthtoken:${var.ngc-api-key}")
}
}
})
}

depends_on = [kubernetes_namespace.nim]
}

resource "kubernetes_secret" "ngc-api" {
metadata {
name = "ngc-api"
namespace = kubernetes_namespace.nim.metadata.0.name
}

type = "Opaque"

data = {
NGC_API_KEY = var.ngc-api-key
}

depends_on = [kubernetes_namespace.nim]
}

resource "kubernetes_storage_class" "name" {
metadata {
name = "hyperdisk-ml"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is HDML required or could another StorageClass also be used?

}

parameters = {
type = "hyperdisk-ml"
}

storage_provisioner = "pd.csi.storage.gke.io"
allow_volume_expansion = false
reclaim_policy = "Delete"
volume_binding_mode = "WaitForFirstConsumer"
}

resource "kubernetes_persistent_volume_claim" "name" {
metadata {
generate_name = "pvc-nim-"
namespace = kubernetes_namespace.nim.metadata.0.name
}

spec {
access_modes = ["ReadWriteOnce"]
storage_class_name = kubernetes_storage_class.name.metadata.0.name
resources {
requests = {
storage = "100Gi"
}
}
}
wait_until_bound = false
}

resource "helm_release" "nim-release" {
name = "nim"
namespace = kubernetes_namespace.nim.metadata.0.name
chart = "https://helm.ngc.nvidia.com/nim/charts/nim-llm-${var.chart-version}.tgz"
repository_username = "$oauthtoken"
repository_password = var.ngc-api-key

set {
name = "image.repository"
value = "nvcr.io/nim/${var.image-name}"
}

set {
name = "image.tag"
value = var.image-tag
}

set {
name = "model.name"
value = var.image-name
}

set {
name = "service.type"
value = "LoadBalancer"
}

set {
name = "resources.limits.nvidia\\.com/gpu"
value = var.gpu-limits
}

set {
name = "persistence.enabled"
value = true
}

set {
name = "persistence.existingClaim"
value = kubernetes_persistent_volume_claim.name.metadata.0.name
}

depends_on = [kubernetes_namespace.nim]
}
3 changes: 3 additions & 0 deletions best-practices/ml-platform/terraform/features/nim/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "inference-url" {
value = ""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this isn't going to be populated with a value, can you remove it?

}
18 changes: 18 additions & 0 deletions best-practices/ml-platform/terraform/features/nim/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
provider "google" {
project = var.google-project
}

provider "kubernetes" {
host = "https://${data.google_container_cluster.nim-llm.endpoint}"
cluster_ca_certificate = base64decode(data.google_container_cluster.nim-llm.master_auth.0.cluster_ca_certificate)
token = data.google_client_config.current.access_token
}

provider "helm" {
kubernetes {
host = "https://${data.google_container_cluster.nim-llm.endpoint}"
cluster_ca_certificate = base64decode(data.google_container_cluster.nim-llm.master_auth.0.cluster_ca_certificate)
token = data.google_client_config.current.access_token
}
}

50 changes: 50 additions & 0 deletions best-practices/ml-platform/terraform/features/nim/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
variable "cluster-name" {
description = "The name of the cluster NIM will be deployed to"
type = string
}

variable "cluster-location" {
description = "The location of the cluster NIM will be deployed to"
type = string
}

variable "google-project" {
description = "The name of the google project that contains the cluster NIM will be deployed to"
type = string
}

variable "kubernetes-namespace" {
description = "The namespace where NIM will be deployed"
default = "nim"
type = string
}

variable "gpu-limits" {
description = "Number of GPUs that will be presented to the model"
default = 1
type = number
}

variable "ngc-api-key" {
description = "Your NGC API key"
type = string
sensitive = true
}

variable "chart-version" {
description = "The version of the chart"
default = "1.1.2"
type = string
}

variable "image-name" {
description = "The name of the image to be deployed by NIM. Should be <org>/<model-name>"
default = "meta/llama3-8b-instruct"
type = string
}

variable "image-tag" {
description = "The tag of the image to be deployed by NIM"
default = "1.0.0"
type = string
}