Skip to content

Commit c2e82f0

Browse files
visheshtanksaleshivamerla
authored andcommitted
Adding support for NIMBuild to use buildable LORA profiles
Signed-off-by: Vishesh Tanksale <[email protected]>
1 parent d569298 commit c2e82f0

File tree

2 files changed

+145
-0
lines changed

2 files changed

+145
-0
lines changed

internal/controller/nimbuild_controller.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,16 @@ func (r *NIMBuildReconciler) constructEngineBuildPod(nimBuild *appsv1alpha1.NIMB
722722
// Merge env with the user provided values
723723
pod.Spec.Containers[0].Env = utils.MergeEnvVars(pod.Spec.Containers[0].Env, nimBuild.Spec.Env)
724724

725+
// If LORA is enabled, set NIM_PEFT_SOURCE to run NIM with LORA enabled
726+
if inputNimProfile.Config["feat_lora"] == "true" {
727+
pod.Spec.Containers[0].Env = utils.MergeEnvVars(pod.Spec.Containers[0].Env, []corev1.EnvVar{
728+
{
729+
Name: "NIM_PEFT_SOURCE",
730+
Value: "/tmp",
731+
},
732+
})
733+
}
734+
725735
return pod, nil
726736
}
727737

internal/controller/nimbuild_controller_test.go

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,5 +1080,140 @@ var _ = Describe("NIMBuild Controller", func() {
10801080
Expect(customModelPathFound).To(BeTrue(), "NIM_MODEL_PATH should be overridden in created pod")
10811081
Expect(defaultCachePathFound).To(BeTrue(), "Default NIM_CACHE_PATH should be preserved in created pod")
10821082
})
1083+
1084+
It("should set NIM_PEFT_SOURCE when LORA is enabled in profile", func() {
1085+
// Create a profile with LORA enabled
1086+
loraProfile := appsv1alpha1.NIMProfile{
1087+
Name: "lora-profile",
1088+
Model: "test-model",
1089+
Config: map[string]string{"feat_lora": "true", "trtllm_buildable": "true"},
1090+
}
1091+
1092+
nimBuild := &appsv1alpha1.NIMBuild{
1093+
ObjectMeta: metav1.ObjectMeta{
1094+
Name: "test-nimbuild",
1095+
Namespace: "default",
1096+
},
1097+
Spec: appsv1alpha1.NIMBuildSpec{
1098+
NIMCache: appsv1alpha1.NIMCacheReference{
1099+
Name: nimCache.Name,
1100+
},
1101+
Image: appsv1alpha1.Image{
1102+
Repository: "nvcr.io/nim/test",
1103+
Tag: "latest",
1104+
},
1105+
Resources: &appsv1alpha1.ResourceRequirements{
1106+
Requests: corev1.ResourceList{
1107+
"nvidia.com/gpu": resource.MustParse("8"),
1108+
},
1109+
Limits: corev1.ResourceList{
1110+
"nvidia.com/gpu": resource.MustParse("8"),
1111+
},
1112+
},
1113+
},
1114+
}
1115+
1116+
// Test pod construction with LORA-enabled profile
1117+
pod, err := reconciler.constructEngineBuildPod(nimBuild, nimCache, k8sutil.K8s, loraProfile)
1118+
Expect(err).ToNot(HaveOccurred())
1119+
1120+
// Check that NIM_PEFT_SOURCE environment variable is set
1121+
envVars := pod.Spec.Containers[0].Env
1122+
var nimPeftSourceFound bool
1123+
for _, env := range envVars {
1124+
if env.Name == "NIM_PEFT_SOURCE" {
1125+
Expect(env.Value).To(Equal("/tmp"))
1126+
nimPeftSourceFound = true
1127+
break
1128+
}
1129+
}
1130+
Expect(nimPeftSourceFound).To(BeTrue(), "NIM_PEFT_SOURCE should be set when LORA is enabled")
1131+
})
1132+
1133+
It("should not set NIM_PEFT_SOURCE when LORA is disabled in profile", func() {
1134+
// Create a profile with LORA disabled
1135+
noLoraProfile := appsv1alpha1.NIMProfile{
1136+
Name: "no-lora-profile",
1137+
Model: "test-model",
1138+
Config: map[string]string{"feat_lora": "false", "trtllm_buildable": "true"},
1139+
}
1140+
1141+
nimBuild := &appsv1alpha1.NIMBuild{
1142+
ObjectMeta: metav1.ObjectMeta{
1143+
Name: "test-nimbuild",
1144+
Namespace: "default",
1145+
},
1146+
Spec: appsv1alpha1.NIMBuildSpec{
1147+
NIMCache: appsv1alpha1.NIMCacheReference{
1148+
Name: nimCache.Name,
1149+
},
1150+
Image: appsv1alpha1.Image{
1151+
Repository: "nvcr.io/nim/test",
1152+
Tag: "latest",
1153+
},
1154+
Resources: &appsv1alpha1.ResourceRequirements{
1155+
Requests: corev1.ResourceList{
1156+
"nvidia.com/gpu": resource.MustParse("8"),
1157+
},
1158+
Limits: corev1.ResourceList{
1159+
"nvidia.com/gpu": resource.MustParse("8"),
1160+
},
1161+
},
1162+
},
1163+
}
1164+
1165+
// Test pod construction with LORA-disabled profile
1166+
pod, err := reconciler.constructEngineBuildPod(nimBuild, nimCache, k8sutil.K8s, noLoraProfile)
1167+
Expect(err).ToNot(HaveOccurred())
1168+
1169+
// Check that NIM_PEFT_SOURCE environment variable is NOT set
1170+
envVars := pod.Spec.Containers[0].Env
1171+
for _, env := range envVars {
1172+
Expect(env.Name).NotTo(Equal("NIM_PEFT_SOURCE"), "NIM_PEFT_SOURCE should not be set when LORA is disabled")
1173+
}
1174+
})
1175+
1176+
It("should not set NIM_PEFT_SOURCE when LORA config is missing from profile", func() {
1177+
// Create a profile without LORA config
1178+
noLoraConfigProfile := appsv1alpha1.NIMProfile{
1179+
Name: "no-lora-config-profile",
1180+
Model: "test-model",
1181+
Config: map[string]string{"trtllm_buildable": "true"},
1182+
}
1183+
1184+
nimBuild := &appsv1alpha1.NIMBuild{
1185+
ObjectMeta: metav1.ObjectMeta{
1186+
Name: "test-nimbuild",
1187+
Namespace: "default",
1188+
},
1189+
Spec: appsv1alpha1.NIMBuildSpec{
1190+
NIMCache: appsv1alpha1.NIMCacheReference{
1191+
Name: nimCache.Name,
1192+
},
1193+
Image: appsv1alpha1.Image{
1194+
Repository: "nvcr.io/nim/test",
1195+
Tag: "latest",
1196+
},
1197+
Resources: &appsv1alpha1.ResourceRequirements{
1198+
Requests: corev1.ResourceList{
1199+
"nvidia.com/gpu": resource.MustParse("8"),
1200+
},
1201+
Limits: corev1.ResourceList{
1202+
"nvidia.com/gpu": resource.MustParse("8"),
1203+
},
1204+
},
1205+
},
1206+
}
1207+
1208+
// Test pod construction with profile missing LORA config
1209+
pod, err := reconciler.constructEngineBuildPod(nimBuild, nimCache, k8sutil.K8s, noLoraConfigProfile)
1210+
Expect(err).ToNot(HaveOccurred())
1211+
1212+
// Check that NIM_PEFT_SOURCE environment variable is NOT set
1213+
envVars := pod.Spec.Containers[0].Env
1214+
for _, env := range envVars {
1215+
Expect(env.Name).NotTo(Equal("NIM_PEFT_SOURCE"), "NIM_PEFT_SOURCE should not be set when LORA config is missing")
1216+
}
1217+
})
10831218
})
10841219
})

0 commit comments

Comments
 (0)