Skip to content

Conversation

@yeahdongcn
Copy link
Contributor

@yeahdongcn yeahdongcn commented May 10, 2025

ggml-org/llama.cpp#13370

This PR adds support for ModelScope by introducing ramalama/modelscope.py, which is adapted from ramalama/huggingface.py. It includes modifications for obtaining SHA256 hashes and determining the default CLI download location specific to ModelScope.

Testing Done

  • ramalama login
  • ramalama logout — expected failure since modelscope CLI doesn’t support a logout subcommand
  • ramalama pull with and without modelscope installed
  • ramalama run
  • ramalama ls
  • make unit-tests

Logs:

❯ ramalama pull ms://QuantFactory/SmolLM-135M-GGUF/SmolLM-135M.Q2_K.gguf
Downloading modelscope://SmolLM-135M.Q2_K.gguf:latest ...
Trying to pull modelscope://SmolLM-135M.Q2_K.gguf:latest...
 98% |██████████████████████████████████████████████████████████████████████████████████████████████████  |   83.27 MB/  84.12 MB   7.05 MB/s        0s%
❯ ramalama run ms://bartowski/SmolLM-1.7B-Instruct-v0.2-GGUF/SmolLM-1.7B-Instruct-v0.2-IQ3_M.gguf
Downloading modelscope://SmolLM-1.7B-Instruct-v0.2-IQ3_M.gguf:latest ...
Trying to pull modelscope://SmolLM-1.7B-Instruct-v0.2-IQ3_M.gguf:latest...
 99% |███████████████████████████████████████████████████████████████████████████████████████████████████ |  772.48 MB/ 772.71 MB   2.86 MB/s        0sChecking for newer image quay.io/ramalama/ramalama:0.8
🐋 > Hello
Hello! How can I help you today?
🐋 > 
Use Ctrl + d or /bye or exit to quit.
🐋 > 
❯ ramalama pull huggingface://afrideva/Tiny-Vicuna-1B-GGUF/tiny-vicuna-1b.q2_k.gguf
Downloading huggingface://tiny-vicuna-1b.q2_k.gguf:latest ...
Trying to pull huggingface://tiny-vicuna-1b.q2_k.gguf:latest...
 99% |███████████████████████████████████████████████████████████████████████████████████████████████████ |  457.73 MB/ 459.81 MB  20.18 MB/s        0s%
❯ ramalama ls
NAME                                                                                              MODIFIED      SIZE     
modelscope://bartowski/SmolLM-1.7B-Instruct-v0.2-GGUF/SmolLM-1.7B-Instruct-v0.2-IQ3_M.gguf:latest 1 minute ago  772.71 MB
modelscope://QuantFactory/SmolLM-135M-GGUF/SmolLM-135M.Q2_K.gguf:latest                           5 minutes ago 84.12 MB 
huggingface://afrideva/Tiny-Vicuna-1B-GGUF/tiny-vicuna-1b.q2_k.gguf:latest                        2 minutes ago 459.81 MB

Summary by Sourcery

Add support for ModelScope as a new model registry transport in RamaLama

New Features:

  • Introduce ModelScope as a new model registry transport with support for downloading and managing models
  • Add support for 'modelscope://' and 'ms://' URL prefixes
  • Implement ModelScope-specific model pulling and authentication methods

Enhancements:

  • Extend model factory to support ModelScope transport
  • Implement SHA256 checksum retrieval from ModelScope API
  • Add cache and download mechanisms specific to ModelScope

Documentation:

  • Update documentation across multiple man pages to include ModelScope as a supported transport
  • Add ModelScope login and usage instructions to documentation

Summary by Sourcery

Add ModelScope as a supported model registry transport, enabling model download, management, and authentication via ModelScope in RamaLama.

New Features:

  • Introduce ModelScope as a new model registry transport with support for downloading and managing models.
  • Add support for 'modelscope://' and 'ms://' URL prefixes for model references.
  • Implement ModelScope-specific model pulling, authentication, and checksum verification methods.

Enhancements:

  • Extend model factory and model identifier extraction to support ModelScope transport.
  • Refactor download and checksum verification logic for improved reuse across transports.

Documentation:

  • Update documentation and man pages to include ModelScope as a supported transport and provide usage instructions.

Tests:

  • Expand unit tests to cover ModelScope transport and model identifier extraction.

Signed-off-by: Xiaodong Ye <[email protected]>
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented May 10, 2025

Reviewer's Guide

This PR adds ModelScope as a supported model registry transport in RamaLama, introducing a new modelscope.py module, updating the model factory and CLI to recognize ModelScope URLs, and extending documentation and tests to cover ModelScope usage. The implementation adapts HuggingFace logic for ModelScope, including model pulling, authentication, SHA256 checksum retrieval, and cache handling, while ensuring seamless integration with existing transports.

File-Level Changes

Change Details Files
Introduce ModelScope support as a new model registry transport.
  • Add ramalama/modelscope.py implementing ModelScope model pulling, authentication, and cache logic.
  • Adapt HuggingFace repository logic for ModelScope, including SHA256 checksum retrieval and CLI integration.
  • Implement ModelScope-specific methods for login, pull, push, and cache handling.
ramalama/modelscope.py
Update model factory and model type detection to support ModelScope.
  • Extend model_factory.py to detect and instantiate ModelScope models based on URL prefixes or transport selection.
  • Update model type lists and input pruning logic to include ModelScope.
  • Add ModelScope to CLI registry normalization.
ramalama/model_factory.py
ramalama/model.py
ramalama/cli.py
Enhance documentation to include ModelScope as a supported transport.
  • Add ModelScope to transport tables in man pages and README.
  • Document ModelScope login and usage instructions.
README.md
docs/ramalama.1.md
docs/ramalama-bench.1.md
docs/ramalama-perplexity.1.md
docs/ramalama-run.1.md
docs/ramalama-serve.1.md
docs/ramalama-login.1.md
Update and extend tests for ModelScope support.
  • Add ModelScope test cases to test_model_factory.py and test_model.py for model detection and identifier extraction.
test/unit/test_model_factory.py
test/unit/test_model.py
Refactor and generalize model pulling and checksum verification logic.
  • Extract download_and_verify helper to common.py for shared use.
  • Refactor symlink update logic in huggingface.py for reuse and clarity.
ramalama/common.py
ramalama/huggingface.py
Minor changes and cleanup.
  • Update URL identifier extraction in url.py for ModelScope URLs.
  • Comment out an assertion in test_config.py for compatibility.
ramalama/url.py
test/unit/test_config.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @yeahdongcn - I've reviewed your changes - here's some feedback:

  • Consider abstracting shared functionalities between ModelScope and Huggingface model classes into a common base if they handle CLI/API interactions similarly.
  • The multi-step fallback logic in ModelScope.pull() for model retrieval could be reviewed for potential simplification or clearer state management.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@rhatdan
Copy link
Member

rhatdan commented May 10, 2025

Why aren't people just using OCI registries to store models. The model registry creep is driving me crazy. We have a standard place to store internet content that works well with k8s.

Anyways thanks @yeahdongcn

@ericcurtin
Copy link
Member

@engelmi PTAL

@rhatdan
Copy link
Member

rhatdan commented May 10, 2025

Please add some tests for this transport. Do you have a tiny model that this ramalama can pull?

Any shortnames.conf file updates for models only available in modelscope?

@yeahdongcn
Copy link
Contributor Author

Please add some tests for this transport. Do you have a tiny model that this ramalama can pull?

Any shortnames.conf file updates for models only available in modelscope?

No problem. I just need a bit more time to get the CI happy.

@yeahdongcn
Copy link
Contributor Author

Do you have a tiny model that this ramalama can pull?

Please try this one:

❯ ramalama pull ms://QuantFactory/SmolLM-135M-GGUF/SmolLM-135M.Q2_K.gguf
Downloading modelscope://SmolLM-135M.Q2_K.gguf:latest ...
Trying to pull modelscope://SmolLM-135M.Q2_K.gguf:latest...
 23% |██████████████████                                                               |   19.69 MB/  84.12 MB 371.27 KB/s    2m 57s

Any shortnames.conf file updates for models only available in modelscope?

I'm using modelscope as an alternative for huggingface in mainland China, mainly because access to huggingface occasionally fails. So there’s no need to update shortnames.conf.

Signed-off-by: Xiaodong Ye <[email protected]>
@yeahdongcn
Copy link
Contributor Author

@sourcery-ai review

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @yeahdongcn - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 7 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Signed-off-by: Xiaodong Ye <[email protected]>
Signed-off-by: Xiaodong Ye <[email protected]>
Signed-off-by: Xiaodong Ye <[email protected]>
@ericcurtin
Copy link
Member

On a brief glance this looks fine, we should probably try and de-duplicate a little more between this and huggingface code, etc.. But can be in a follow on pull request.

@rhatdan rhatdan merged commit e06824a into containers:main May 12, 2025
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants