-
Notifications
You must be signed in to change notification settings - Fork 99
feat: enhance tokenizer handling in model configuration #147
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -61,7 +61,7 @@ def print_color(message, color): | |||||||||||||||||||||||||||||||||||||||
| variables.worker_manager_rkllm = WorkerManager() | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| def create_modelfile(huggingface_path, From, system="", model_name=None): | ||||||||||||||||||||||||||||||||||||||||
| def create_modelfile(huggingface_path, From, system="", model_name=None, tokenizer_repo=None): | ||||||||||||||||||||||||||||||||||||||||
| struct_modelfile = f""" | ||||||||||||||||||||||||||||||||||||||||
| FROM="{From}" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
@@ -96,6 +96,9 @@ def create_modelfile(huggingface_path, From, system="", model_name=None): | |||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| if tokenizer_repo: | ||||||||||||||||||||||||||||||||||||||||
| struct_modelfile += f'TOKENIZER="{tokenizer_repo}"\n\n' | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Use config for models path | ||||||||||||||||||||||||||||||||||||||||
| path = os.path.join(rkllama.config.get_path("models"), model_name) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
@@ -108,6 +111,107 @@ def create_modelfile(huggingface_path, From, system="", model_name=None): | |||||||||||||||||||||||||||||||||||||||
| f.write(struct_modelfile) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| def hf_repo_has_config(repo: str, fs=None) -> bool: | ||||||||||||||||||||||||||||||||||||||||
| fs = fs or HfFileSystem() | ||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||
| fs.info(f"{repo}/config.json") | ||||||||||||||||||||||||||||||||||||||||
| return True | ||||||||||||||||||||||||||||||||||||||||
| except Exception: | ||||||||||||||||||||||||||||||||||||||||
| return False | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+114
to
+120
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| def get_hf_model_metadata(repo: str) -> dict | None: | ||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||
| response = requests.get(f"https://huggingface.co/api/models/{repo}", timeout=10) | ||||||||||||||||||||||||||||||||||||||||
| if response.status_code == 200: | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+123
to
+126
|
||||||||||||||||||||||||||||||||||||||||
| return response.json() | ||||||||||||||||||||||||||||||||||||||||
| except Exception as e: | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+126
to
+128
|
||||||||||||||||||||||||||||||||||||||||
| if response.status_code == 200: | |
| return response.json() | |
| except Exception as e: | |
| response.raise_for_status() | |
| try: | |
| return response.json() | |
| except ValueError as e: | |
| logger.debug(f"Unable to parse Hugging Face metadata JSON for {repo}: {e}") | |
| except requests.HTTPError as e: | |
| response = e.response | |
| status_code = response.status_code if response is not None else "unknown" | |
| response_body = "" | |
| if response is not None: | |
| response_body = response.text[:500].replace("\n", "\\n") | |
| logger.debug( | |
| f"Unable to load Hugging Face metadata for {repo}: HTTP {status_code}" | |
| + (f" - {response_body}" if response_body else "") | |
| ) | |
| except requests.RequestException as e: |
Copilot
AI
Apr 27, 2026
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.
In /pull, you already instantiate fs = HfFileSystem() for the file download metadata, but hf_repo_has_config(repo) / resolve_tokenizer_repo(repo) create their own HfFileSystem instances. Pass the existing fs into these helpers to avoid redundant client setup and extra remote calls (and to ensure consistent auth/caching behavior).
| if hf_repo_has_config(repo): | |
| yield f"Repository {repo} contains config.json; TOKENIZER not required.\n" | |
| else: | |
| tokenizer_repo = resolve_tokenizer_repo(repo) | |
| try: | |
| repo_has_config = hf_repo_has_config(repo, fs=fs) | |
| except TypeError: | |
| repo_has_config = hf_repo_has_config(repo) | |
| if repo_has_config: | |
| yield f"Repository {repo} contains config.json; TOKENIZER not required.\n" | |
| else: | |
| try: | |
| tokenizer_repo = resolve_tokenizer_repo(repo, fs=fs) | |
| except TypeError: | |
| tokenizer_repo = resolve_tokenizer_repo(repo) |
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.
Spelling in the comment: “Huggin Face” should be “Hugging Face”.