-
Notifications
You must be signed in to change notification settings - Fork 23
Fix model id and upload to hub #162
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
37e59bc
fix model id
Yunnglin 85dbe59
fix model id
Yunnglin e68de24
Merge branch 'main' into fix_model_id_0416
Yunnglin b756f7e
update upload
Yunnglin d7b98be
update upload
Yunnglin 1640e3e
update upload
Yunnglin c427370
update upload
Yunnglin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # Tinker-Compatible Client - Upload Checkpoint to Hub Example | ||
| # | ||
| # This script demonstrates how to upload a Tinker checkpoint to ModelScope Hub. | ||
| # Tinker checkpoints use the same twinkle:// path format as Twinkle checkpoints, | ||
| # so the upload is handled identically via the Twinkle upload interface. | ||
| # | ||
| # How it works: | ||
| # 1. The server submits the upload as a background task and returns a | ||
| # request_id immediately, so the HTTP call never times out. | ||
| # 2. The client polls /upload_status/{request_id} every few seconds and | ||
| # blocks until the upload completes or raises on failure. | ||
| # | ||
| # Prerequisites: | ||
| # - Server must be running (see server.py / server_config.yaml) | ||
| # - A ModelScope API token with write access to the target repository | ||
|
|
||
| import dotenv | ||
|
|
||
| dotenv.load_dotenv('.env') | ||
|
|
||
| from twinkle import get_logger, init_twinkle_client | ||
| from twinkle_client.model import MultiLoraTransformersModel | ||
|
|
||
| logger = get_logger() | ||
|
|
||
| # ── Configuration ───────────────────────────────────────────────────────────── | ||
| base_model = 'Qwen/Qwen3.5-4B' | ||
| base_url = 'http://localhost:8000' | ||
| api_key = 'EMPTY_TOKEN' # token used for model training / server access | ||
|
|
||
| # Checkpoint to upload: the twinkle:// path returned by training_client.save_state(), | ||
| # e.g. 'twinkle://20260301_142318-Qwen_Qwen3-4B-199d2cdb/weights/my-lora-epoch-0' | ||
| tinker_path = 'twinkle://REPLACE_ME/weights/REPLACE_ME' | ||
|
|
||
| # ModelScope destination (must belong to your account) | ||
| hub_model_id = 'your_username/your-model-name' | ||
| hub_token = None # Set to your ModelScope API token, or None to use server default | ||
| # ── End of configuration ────────────────────────────────────────────────────── | ||
|
|
||
|
|
||
| def upload(): | ||
| # Step 1: Initialize the Twinkle client. | ||
| # Tinker checkpoints (twinkle:// paths) are resolved by the same checkpoint | ||
| # manager on the server, so init_twinkle_client is sufficient for upload. | ||
| init_twinkle_client(base_url=base_url, api_key=api_key) | ||
|
|
||
| # Step 2: Create the model client (no training state needed for upload) | ||
| model = MultiLoraTransformersModel(model_id=f'ms://{base_model}') | ||
|
|
||
| # Step 3: Upload checkpoint to ModelScope Hub. | ||
| # The client polls for completion automatically; progress is printed to stdout. | ||
| logger.info(f'Uploading {tinker_path!r} → {hub_model_id!r} ...') | ||
| model.upload_to_hub( | ||
| checkpoint_dir=tinker_path, | ||
| hub_model_id=hub_model_id, | ||
| hub_token=hub_token, | ||
| ) | ||
| logger.info(f'Upload complete: https://modelscope.cn/models/{hub_model_id}') | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| upload() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # Twinkle Client - Upload Checkpoint to Hub Example | ||
| # | ||
| # This script demonstrates how to upload a saved checkpoint to ModelScope Hub | ||
| # using the Twinkle client. No training is required: any existing checkpoint | ||
| # (obtained from a previous run via model.save()) can be uploaded directly. | ||
| # | ||
| # How it works: | ||
| # 1. The server submits the upload as a background task and returns a | ||
| # request_id immediately, so the HTTP call never times out. | ||
| # 2. The client polls /upload_status/{request_id} every few seconds and | ||
| # blocks until the upload completes or raises on failure. | ||
| # | ||
| # Prerequisites: | ||
| # - Server must be running (see server.py / server_config.yaml) | ||
| # - A ModelScope API token with write access to the target repository | ||
|
|
||
| import dotenv | ||
|
|
||
| dotenv.load_dotenv('.env') | ||
|
|
||
| from twinkle import get_logger, init_twinkle_client | ||
| from twinkle_client.model import MultiLoraTransformersModel | ||
|
|
||
| logger = get_logger() | ||
|
|
||
| # ── Configuration ───────────────────────────────────────────────────────────── | ||
| base_model = 'Qwen/Qwen3.5-4B' | ||
| base_url = 'http://localhost:8000' | ||
| api_key = 'EMPTY_TOKEN' # token used for model training / server access | ||
|
|
||
| # Checkpoint to upload: either a twinkle:// path or a local directory path. | ||
| # Example twinkle:// path (from model.save()): | ||
| # 'twinkle://20260410_131831-Qwen_Qwen3_5-4B-85279a20/weights/my-checkpoint' | ||
| twinkle_path = 'twinkle://REPLACE_ME/weights/REPLACE_ME' | ||
|
|
||
| # ModelScope destination (must belong to your account) | ||
| hub_model_id = 'your_username/your-model-name' | ||
| hub_token = None # Set to your ModelScope API token, or None to use server default | ||
| # ── End of configuration ────────────────────────────────────────────────────── | ||
|
|
||
|
|
||
| def upload(): | ||
| # Step 1: Initialize the Twinkle client | ||
| init_twinkle_client(base_url=base_url, api_key=api_key) | ||
|
|
||
| # Step 2: Create the model client (no training state needed for upload) | ||
| model = MultiLoraTransformersModel(model_id=f'ms://{base_model}') | ||
|
|
||
| # Step 3: Upload checkpoint to ModelScope Hub. | ||
| # The client polls for completion automatically; progress is printed to stdout. | ||
| logger.info(f'Uploading {twinkle_path!r} → {hub_model_id!r} ...') | ||
| model.upload_to_hub( | ||
| checkpoint_dir=twinkle_path, | ||
| hub_model_id=hub_model_id, | ||
| hub_token=hub_token, | ||
| ) | ||
| logger.info(f'Upload complete: https://modelscope.cn/models/{hub_model_id}') | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| upload() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.