@@ -50,7 +50,13 @@ func (p *ModelHubProvider) ModelName() string {
50
50
// - modelID: Qwen/Qwen2-0.5B-Instruct-GGUF
51
51
// fileName: qwen2-0_5b-instruct-q5_k_m.gguf
52
52
// modelPath: /workspace/models/qwen2-0_5b-instruct-q5_k_m.gguf
53
- func (p * ModelHubProvider ) ModelPath () string {
53
+ func (p * ModelHubProvider ) ModelPath (skipModelLoader bool ) string {
54
+ // Skip the model loader to allow the inference engine to handle loading models directly from model hub (e.g., Hugging Face, ModelScope).
55
+ // In this case, the model ID should be returned (e.g., facebook/opt-125m).
56
+ if skipModelLoader {
57
+ return p .modelID
58
+ }
59
+
54
60
if p .fileName != nil {
55
61
return CONTAINER_MODEL_PATH + * p .fileName
56
62
}
@@ -108,59 +114,87 @@ func (p *ModelHubProvider) InjectModelLoader(template *corev1.PodTemplateSpec, i
108
114
// Both HUGGING_FACE_HUB_TOKEN and HF_TOKEN works.
109
115
initContainer .Env = append (initContainer .Env ,
110
116
corev1.EnvVar {
111
- Name : " HUGGING_FACE_HUB_TOKEN" ,
117
+ Name : HUGGING_FACE_HUB_TOKEN ,
112
118
ValueFrom : & corev1.EnvVarSource {
113
119
SecretKeyRef : & corev1.SecretKeySelector {
114
120
LocalObjectReference : corev1.LocalObjectReference {
115
121
Name : MODELHUB_SECRET_NAME , // if secret not exists, the env is empty.
116
122
},
117
- Key : HUGGINGFACE_TOKEN_KEY ,
123
+ Key : HUGGING_FACE_TOKEN_KEY ,
118
124
Optional : ptr.To [bool ](true ),
119
125
},
120
126
},
121
- }, corev1.EnvVar {
122
- Name : "HF_TOKEN" ,
127
+ })
128
+
129
+ initContainer .Env = append (initContainer .Env ,
130
+ corev1.EnvVar {
131
+ Name : HUGGING_FACE_TOKEN_KEY ,
123
132
ValueFrom : & corev1.EnvVarSource {
124
133
SecretKeyRef : & corev1.SecretKeySelector {
125
134
LocalObjectReference : corev1.LocalObjectReference {
126
135
Name : MODELHUB_SECRET_NAME ,
127
136
},
128
- Key : HUGGINGFACE_TOKEN_KEY ,
137
+ Key : HUGGING_FACE_TOKEN_KEY ,
129
138
Optional : ptr.To [bool ](true ),
130
139
},
131
140
},
132
- },
133
- )
134
- template .Spec .InitContainers = append (template .Spec .InitContainers , * initContainer )
141
+ })
135
142
136
- // Return once not the main model, because all the below has already been injected.
137
- if index != 0 {
138
- return
139
- }
143
+ template .Spec .InitContainers = append (template .Spec .InitContainers , * initContainer )
144
+ }
140
145
141
- // Handle container.
146
+ func spreadEnvToInitContainer (containerEnv []corev1.EnvVar , initContainer * corev1.Container ) {
147
+ initContainer .Env = append (initContainer .Env , containerEnv ... )
148
+ }
142
149
150
+ func (p * ModelHubProvider ) InjectModelEnvVars (template * corev1.PodTemplateSpec ) {
143
151
for i := range template .Spec .Containers {
144
- // We only consider this container.
145
152
if template .Spec .Containers [i ].Name == MODEL_RUNNER_CONTAINER_NAME {
146
- template .Spec .Containers [i ].VolumeMounts = append (template .Spec .Containers [i ].VolumeMounts , corev1.VolumeMount {
147
- Name : MODEL_VOLUME_NAME ,
148
- MountPath : CONTAINER_MODEL_PATH ,
149
- ReadOnly : true ,
150
- })
153
+ // Check if HuggingFace token environment variables already exist
154
+ hfHubTokenExists := false
155
+ hfTokenExists := false
156
+ for _ , env := range template .Spec .Containers [i ].Env {
157
+ if env .Name == HUGGING_FACE_HUB_TOKEN {
158
+ hfHubTokenExists = true
159
+ }
160
+ if env .Name == HUGGING_FACE_TOKEN_KEY {
161
+ hfTokenExists = true
162
+ }
163
+ }
164
+
165
+ // Add HUGGING_FACE_HUB_TOKEN if it doesn't exist
166
+ if ! hfHubTokenExists {
167
+ template .Spec .Containers [i ].Env = append (template .Spec .Containers [i ].Env ,
168
+ corev1.EnvVar {
169
+ Name : HUGGING_FACE_HUB_TOKEN ,
170
+ ValueFrom : & corev1.EnvVarSource {
171
+ SecretKeyRef : & corev1.SecretKeySelector {
172
+ LocalObjectReference : corev1.LocalObjectReference {
173
+ Name : MODELHUB_SECRET_NAME , // if secret not exists, the env is empty.
174
+ },
175
+ Key : HUGGING_FACE_TOKEN_KEY ,
176
+ Optional : ptr.To [bool ](true ),
177
+ },
178
+ },
179
+ })
180
+ }
181
+
182
+ // Add HF_TOKEN if it doesn't exist
183
+ if ! hfTokenExists {
184
+ template .Spec .Containers [i ].Env = append (template .Spec .Containers [i ].Env ,
185
+ corev1.EnvVar {
186
+ Name : HUGGING_FACE_TOKEN_KEY ,
187
+ ValueFrom : & corev1.EnvVarSource {
188
+ SecretKeyRef : & corev1.SecretKeySelector {
189
+ LocalObjectReference : corev1.LocalObjectReference {
190
+ Name : MODELHUB_SECRET_NAME ,
191
+ },
192
+ Key : HUGGING_FACE_TOKEN_KEY ,
193
+ Optional : ptr.To [bool ](true ),
194
+ },
195
+ },
196
+ })
197
+ }
151
198
}
152
199
}
153
-
154
- // Handle spec.
155
-
156
- template .Spec .Volumes = append (template .Spec .Volumes , corev1.Volume {
157
- Name : MODEL_VOLUME_NAME ,
158
- VolumeSource : corev1.VolumeSource {
159
- EmptyDir : & corev1.EmptyDirVolumeSource {},
160
- },
161
- })
162
- }
163
-
164
- func spreadEnvToInitContainer (containerEnv []corev1.EnvVar , initContainer * corev1.Container ) {
165
- initContainer .Env = append (initContainer .Env , containerEnv ... )
166
200
}
0 commit comments