-
Notifications
You must be signed in to change notification settings - Fork 10
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:update model loader #178
Conversation
Will review this ASAP. Thanks for the work. |
/kind feature |
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.
We may also need an e2e test to make sure the pattern works as expected, but it can be a follow up until I publish a official image tag for model-builder.
api/core/v1alpha1/model_types.go
Outdated
@@ -49,6 +49,12 @@ type ModelHub struct { | |||
// +kubebuilder:default=main | |||
// +optional | |||
Revision *string `json:"revision,omitempty"` | |||
// AllowPatterns refers to only files matching at least one pattern are downloaded. | |||
// +optional | |||
AllowPatterns *string `json:"allowPatterns,omitempty"` |
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.
Let's make it a slice because huggingface_hub accepted list.
api/core/v1alpha1/model_types.go
Outdated
AllowPatterns *string `json:"allowPatterns,omitempty"` | ||
// IgnorePatterns refers to files matching any of the patterns are not downloaded. | ||
// +optional | ||
IgnorePatterns *string `json:"ignorePatterns,omitempty"` |
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.
ditto
revision=revision, | ||
).add_done_callback(handle_completion) | ||
) | ||
if filename: |
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.
Let's be more simple here, if filename, the allow_patterns will be the filename. Actually, In OP is not that accurate, we may have pattern like *.json
.
And we should add a validation in the webhook as Once filename is set, the both patterns should be nil
.
revision=revision, | ||
).add_done_callback(handle_completion) | ||
) | ||
if filename: |
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.
The same here.
coreapi "github.com/inftyai/llmaz/api/core/v1alpha1" | ||
"github.com/inftyai/llmaz/pkg/util" | ||
corev1 "k8s.io/api/core/v1" | ||
"strings" |
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.
Let's make sure the libs is grouped like this:
important (
# the base libs golang provided
fmt
strings
# the third part libs
corev1 "k8s.io/api/core/v1"
# project libs
coreapi "github.com/inftyai/llmaz/api/core/v1alpha1"
)
@@ -59,12 +60,28 @@ type ModelSourceProvider interface { | |||
|
|||
func NewModelSourceProvider(model *coreapi.OpenModel) ModelSourceProvider { | |||
if model.Spec.Source.ModelHub != nil { | |||
|
|||
// fileName should not in ignorePatterns | |||
if model.Spec.Source.ModelHub.Filename != nil && model.Spec.Source.ModelHub.IgnorePatterns != nil { |
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.
can we verify this in webhooks? As I mentioned, once filename is set, the other patterns should not be configured anyway. It's useless.
} | ||
if p.modelIgnorePatterns != nil { | ||
initContainer.Env = append(initContainer.Env, | ||
corev1.EnvVar{Name: "MODEL_IGNORE_PATTERNS", Value: *p.modelIgnorePatterns}, |
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.
Doesn't this a String value, but we want a Optional[List[str]] in python side, will this work?
I just want to highlight that we hardcoded the loader image name in pkg/defaults.go
, so what we changed in python side will only be tested part of them:
- what we have tested is the refactors in controller side is correct
- what we haven't tested is the new added patterns
So you may have to do the extra steps to make sure the code is working:
- make loader-image-load -> to build the right loader image
- replace the image name in
pkg/defaults.go
- run the e2e tests(you may need to run
kind load image
to load the image since you didn't push to the remote registry)
I'm sorry for the trivial steps, but I have't found better ways right now.
Tks for your review, Please hold on this. |
kind ping @qinguoyi would like to publish a new release, and happy to include this feature? Do you still work on this? |
yes, i will finish this work util 10.20 |
ff79237
to
10bee4c
Compare
hi, i have finish this work. PTAL. @kerthcet ------- What changes: ---------
------- What tests: ----------- llama.cpp infers with huggingface model
apiVersion: llmaz.io/v1alpha1
kind: OpenModel
metadata:
name: qwen2-0--5b-gguf
spec:
familyName: qwen2
source:
modelHub:
modelID: Qwen/Qwen2-0.5B-Instruct-GGUF
allowPatterns:
- "*"
ignorePatterns:
- "*.gguf"
|
b4acd87
to
380f7f7
Compare
I will take a look today. |
On the way now, sorry for the late response, I was busy with other things yesterday. |
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.
Thanks @qinguoyi this is awesome!
I just left some nits, others are great to me. And once we merged this PR, I'll update the model-loader official image
pkg/webhook/openmodel_webhook.go
Outdated
if model.Spec.Source.ModelHub.AllowPatterns != nil && len(model.Spec.Source.ModelHub.AllowPatterns) != 0 { | ||
allErrs = append(allErrs, field.Invalid(sourcePath.Child("modelHub.allowPatterns"), model.Spec.Source.ModelHub.AllowPatterns, "Once Filename is set, allowPatterns should be nil")) | ||
} | ||
if model.Spec.Source.ModelHub.IgnorePatterns != nil && len(model.Spec.Source.ModelHub.IgnorePatterns) != 0 { |
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.
ditto
}, | ||
failed: false, | ||
}), | ||
ginkgo.Entry("set filename and allowPatterns when modelHub is Huggingface", &testValidatingCase{ |
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.
Let's add one more case as both allowPatterns and ignorePatterns are set
.
api/core/v1alpha1/model_types.go
Outdated
@@ -49,6 +49,12 @@ type ModelHub struct { | |||
// +kubebuilder:default=main | |||
// +optional | |||
Revision *string `json:"revision,omitempty"` | |||
// AllowPatterns refers to only files matching at least one pattern are downloaded. |
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.
Nit:
// AllowPatterns refers to only files matching at least one pattern are downloaded. | |
// AllowPatterns refers to files matched with at least one pattern will be downloaded. |
api/core/v1alpha1/model_types.go
Outdated
// AllowPatterns refers to only files matching at least one pattern are downloaded. | ||
// +optional | ||
AllowPatterns []string `json:"allowPatterns,omitempty"` | ||
// IgnorePatterns refers to files matching any of the patterns are not downloaded. |
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.
// IgnorePatterns refers to files matching any of the patterns are not downloaded. | |
// IgnorePatterns refers to files matched with any of the patterns will not be downloaded. |
pkg/webhook/openmodel_webhook.go
Outdated
@@ -118,5 +118,15 @@ func (w *OpenModelWebhook) generateValidate(obj runtime.Object) field.ErrorList | |||
allErrs = append(allErrs, field.Invalid(sourcePath.Child("modelHub.filename"), *model.Spec.Source.ModelHub.Filename, "Filename can only set once modeHub is Huggingface")) | |||
} | |||
} | |||
|
|||
if model.Spec.Source.ModelHub != nil && model.Spec.Source.ModelHub.Filename != nil { | |||
if model.Spec.Source.ModelHub.AllowPatterns != nil && len(model.Spec.Source.ModelHub.AllowPatterns) != 0 { |
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.
if model.Spec.Source.ModelHub.AllowPatterns != nil && len(model.Spec.Source.ModelHub.AllowPatterns) != 0 { | |
if model.Spec.Source.ModelHub.AllowPatterns != nil { |
@@ -49,6 +49,12 @@ type ModelHub struct { | |||
// +kubebuilder:default=main | |||
// +optional | |||
Revision *string `json:"revision,omitempty"` |
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.
Let's update the comment of Filename as well,
// Filename refers to a specified model file rather than the whole repo.
// This is helpful to download a specified GGUF model rather than downloading
// the whole repo which includes all kinds of quantized models.
// TODO: this is only supported with Huggingface, add support for ModelScope
// in the near future.
// Note: once filename is set, allowPatterns and ignorePatterns should be left unset.
I just tested with the model yaml:
It failed just because we didn't specify the model file name, are you the same. I'm ok with that because we suggest people to use the filename rather than the patterns when only one file is needed. The error looks like:
|
yes, i am same with you. with the llama.cp to infer, there needs to specify the filename path not the directory path. so, if we specify the dir path,there will be wrong. another, let we can see, when filename is not set, the model path will be the directory. when i develop, i have already find this , but i have no good idea to fit it. how do you think about it ? llmaz/pkg/controller_helper/model_source/modelhub.go Lines 43 to 57 in da979a1
|
62f0ace
to
d72333e
Compare
Let's be simple at first and we can evolve in the future, so the idea is:
Just as we do today. |
Some kind tips, let's address the comments with new commits, then the reviewers can find the append changes and understand what's going on there, we can squash the commits in the last minute. |
d72333e
to
04eaa65
Compare
thanks for your kind tips, i have revert the square commits. PTAL one more. |
So, the current code does not need to be changed. In addition, we need to give user-friendly tips in the documentation to use |
@@ -147,6 +147,12 @@ var _ = ginkgo.Describe("model default and validation", func() { | |||
}, | |||
failed: true, | |||
}), | |||
ginkgo.Entry("set filename, allowPatterns and ignorePatterns when modelHub is Huggingface", &testValidatingCase{ |
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.
What I mean is adding a model repo, and allowPatters and ignorePatterns both set but the filename is empty, to make sure we will not failed.
Squash as well, I'm LGTM with the other parts. |
7a3d9eb
to
a64129c
Compare
/lgtm Great work! |
What this PR does / why we need it
#163 (comment)
Which issue(s) this PR fixes
None
Special notes for your reviewer
this pr, it mainly includes things:
Does this PR introduce a user-facing change?