-
Notifications
You must be signed in to change notification settings - Fork 49
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
Fall back to huggingface-cli when pulling via URL fails #475
Conversation
Reviewer's Guide by SourceryThis PR implements a fallback mechanism for pulling models from HuggingFace. When pulling via direct URL fails, it attempts to use the huggingface-cli. The changes also include fixes for VLLM model serving and error handling improvements. Sequence diagram for model pulling with fallbacksequenceDiagram
participant User
participant System
participant HuggingFace
User->>System: Request to pull model
System->>HuggingFace: Attempt URL pull
alt URL pull fails
System->>System: Log error
System->>HuggingFace: Attempt CLI pull
alt CLI not available
System->>User: Raise NotImplementedError
else CLI available
System->>HuggingFace: Execute CLI pull
end
else URL pull succeeds
System->>User: Return model path
end
Updated class diagram for HuggingFace model handlingclassDiagram
class HuggingFaceModel {
+login(args)
+logout(args)
+pull(args)
+hf_pull(args, model_path, directory_path)
+url_pull(args, model_path, directory_path)
}
note for HuggingFaceModel "Added hf_pull and url_pull methods for fallback mechanism"
class Model {
+remove(args)
+_image(args)
+serve(args)
}
note for Model "Modified serve method for VLLM model serving"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey @rhatdan - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
ramalama/model.py
Outdated
@@ -94,13 +94,13 @@ def remove(self, args): | |||
except OSError as e: | |||
if not args.ignore: | |||
raise KeyError(f"removing {self.model}: {e}") | |||
return |
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.
issue (bug_risk): This early return skips garbage collection when args.ignore is True
Consider moving the return after garbage_collection() to ensure it runs in all cases when args.ignore is True
@@ -68,7 +66,28 @@ def pull(self, args): | |||
|
|||
symlink_dir = os.path.dirname(model_path) | |||
os.makedirs(symlink_dir, exist_ok=True) | |||
try: |
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.
issue (complexity): Consider restructuring the error handling flow to use specific exception types and sequential checks
The nested try-except blocks and generic exception handling make the fallback flow harder to follow. Consider restructuring to make the fallback strategy more explicit while maintaining the same behavior:
def pull(self, args):
model_path = self.model_path(args)
directory_path = os.path.join(args.store, "repos", "huggingface", self.directory, self.filename)
os.makedirs(directory_path, exist_ok=True)
symlink_dir = os.path.dirname(model_path)
os.makedirs(symlink_dir, exist_ok=True)
try:
return self.url_pull(args, model_path, directory_path)
except (urllib.error.HTTPError, urllib.error.URLError) as e:
if self.hf_cli_available:
return self.hf_pull(args, model_path, directory_path)
perror("URL pull failed and huggingface-cli not available")
raise KeyError(f"Failed to pull model: {str(e)}")
This version:
- Catches specific URL-related exceptions rather than generic Exception
- Checks CLI availability before attempting fallback
- Provides clearer error context
- Eliminates nested exception handling
655cbaa
to
5bf5fe0
Compare
@bentito PTAL |
When I run latest, I am seeing: $ bin/ramalama --debug pull huggingface://ibm-granite/granite-3.0-8b-instruct
URL pull failed and huggingface-cli not available
Error: "Failed to pull model: 'failed to pull https://huggingface.co/ibm-granite/raw/main/granite-3.0-8b-instruct: HTTP Error 401: Unauthorized'"
ramalama fork/rhatdan/huggingface $ huggingface-cli version
usage: huggingface-cli <command> [<args>]
huggingface-cli: error: argument {env,login,whoami,logout,repo,upload,download,lfs-enable-largefiles,lfs-multipart-upload,scan-cache,delete-cache}: invalid choice: 'version' (choose from 'env', 'login', 'whoami', 'logout', 'repo', 'upload', 'download', 'lfs-enable-largefiles', 'lfs-multipart-upload', 'scan-cache', 'delete-cache') Did the usage of hf-cli change from before, because with my suggest mods it was working. See my line comment. |
ramalama/huggingface.py
Outdated
try: | ||
return self.url_pull(args, model_path, directory_path) | ||
except (urllib.error.HTTPError, urllib.error.URLError, KeyError) as e: | ||
if not self.hf_cli_available: |
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.
This isn't working for me, I'm ending up with it showing my hf_cli is not available even though it is.
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 not self.hf_cli_available: | |
if self.hf_cli_available: |
not is reversing the logic, right?
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.
yep
Handle non GGUF files as well. Signed-off-by: Daniel J Walsh <[email protected]>
@bentito PTANL |
/lgtm Works for me now! |
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.
all working for me locally now!
Handle non GGUF files as well.
Summary by Sourcery
Implement a fallback mechanism to use 'huggingface-cli' for model pulling when URL-based pulling fails, and fix the argument path for the 'vllm serve' command. Update system tests to reflect these changes.
Bug Fixes:
Enhancements:
Tests: