Skip to content

mlx fixes #1673

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 1 commit into from
Jul 8, 2025
Merged

mlx fixes #1673

merged 1 commit into from
Jul 8, 2025

Conversation

ericcurtin
Copy link
Member

@ericcurtin ericcurtin commented Jul 8, 2025

mlx_lm.server is the only one in my path at least on my system.

Also, printing output like this which doesn't make sense:

Downloading huggingface://RedHatAI/Llama-3.2-1B-Instruct-FP8-dynamic/model.safetensors:latest ... Trying to pull huggingface://RedHatAI/Llama-3.2-1B-Instruct-FP8-dynamic/model.safetensors:latest ...

Summary by Sourcery

Normalize model URIs and streamline subcommand invocation.

Bug Fixes:

  • Prevent redundant huggingface:// prefix and :latest suffix from appearing in output logs

Enhancements:

  • Introduce trim_model_name to abbreviate model URIs by replacing full prefixes and stripping default tags
  • Use trim_model_name in CLI listings and download messages for consistent model naming
  • Switch subcommand execution from python -m mlx_lm to direct mlx_lm.server invocation

Copy link
Contributor

sourcery-ai bot commented Jul 8, 2025

Reviewer's Guide

Refactors model name normalization by introducing a shared trim_model_name helper and replaces the module-based server invocation with a direct mlx_lm.server call to streamline execution args and normalize output.

Class diagram for trim_model_name refactor and usage

classDiagram
    class ModelBase {
    }
    class ModelInfoBase {
    }
    class trim_model_name {
        +str trim_model_name(str model)
    }
    class _list_models_from_store {
    }
    class print_pull_message {
    }

    _list_models_from_store ..> trim_model_name : uses
    print_pull_message ..> trim_model_name : uses
Loading

Class diagram for _build_mlx_exec_args change

classDiagram
    class ModelBase {
        - _build_mlx_exec_args(subcommand, model_path, args, extra)
    }
    ModelBase : -exec_args changed to use 'mlx_lm.server' instead of 'python -m mlx_lm'
Loading

Flow diagram for model name normalization with trim_model_name

flowchart TD
    A[Start] --> B{Is model from huggingface?}
    B -- Yes --> C[Replace 'huggingface://' with 'hf://']
    B -- No --> D
    C --> D{Is model from ollama or oci?}
    D -- No --> E[Remove ':latest' suffix]
    D -- Yes --> F[Do not remove suffix]
    E --> G[Return normalized model name]
    F --> G
Loading

File-Level Changes

Change Details Files
Centralize model name normalization in trim_model_name and apply it across code paths
  • Added trim_model_name: replaces huggingface://→hf:// and strips :latest except for ollama:// and oci://
  • Replaced inline normalization in print_pull_message with trim_model_name
  • Refactored model listing to call trim_model_name instead of duplicating logic
ramalama/model.py
ramalama/cli.py
Switch MLX server execution from module invocation to direct CLI command
  • Replaced ['python','-m','mlx_lm',subcommand] with ['mlx_lm.server',subcommand] in exec_args
ramalama/model.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

@ericcurtin
Copy link
Member Author

ericcurtin commented Jul 8, 2025

@kush-gupt PTAL

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @ericcurtin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request primarily aims to resolve issues related to the execution of mlx_lm commands and enhance the user experience by standardizing how model names are displayed. It refactors existing logic for trimming model names into a dedicated utility function, which is then applied consistently across the codebase for cleaner output.

Highlights

  • MLX Execution Path Fix: The command used to execute mlx_lm has been updated from python -m mlx_lm to directly invoke mlx_lm.server. This addresses an issue where the previous command might not be reliably found or preferred on certain systems, ensuring the correct mlx_lm server is launched.
  • Model Name Trimming Utility: A new utility function, trim_model_name, has been introduced in ramalama/model.py. This function centralizes the logic for converting huggingface:// prefixes to hf:// and removing the :latest suffix from model names, improving consistency and readability.
  • Improved Model Name Display: The newly introduced trim_model_name function is now used when listing models and in user-facing pull messages. This ensures that model names are presented in a cleaner, more consistent format (e.g., hf:// instead of huggingface:// and without :latest suffix), addressing the reported issue of confusing output during downloads.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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 @ericcurtin - I've reviewed your changes - here's some feedback:

  • Avoid using shlex.quote on model_path when building exec_args as a list, since the literal quotes will be passed to the subprocess and may break path resolution.
  • Verify that the mlx_lm.server entry point is always available in target environments or provide a fallback to python -m mlx_lm to prevent invocation errors.
  • Consider centralizing the supported URI schemes (e.g. ollama://, oci://) into a shared constant rather than hardcoding them in trim_model_name to keep the logic easier to extend.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Avoid using shlex.quote on model_path when building exec_args as a list, since the literal quotes will be passed to the subprocess and may break path resolution.
- Verify that the `mlx_lm.server` entry point is always available in target environments or provide a fallback to `python -m mlx_lm` to prevent invocation errors.
- Consider centralizing the supported URI schemes (e.g. ollama://, oci://) into a shared constant rather than hardcoding them in `trim_model_name` to keep the logic easier to extend.

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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces a trim_model_name function to handle model name formatting and applies it in several places to ensure consistency. It also fixes an issue where the wrong executable was being called for mlx models.

@kush-gupt
Copy link
Contributor

LGTM, the reason why I wanted to leave python in cmd was the explicit declaration that we're using that python mlx-lm for it, but it should be fine on path

@ericcurtin ericcurtin force-pushed the mlx-fixes branch 2 times, most recently from cc1a7ba to 4c5af96 Compare July 8, 2025 14:45
mlx_lm.server is the only one in my path at least on my system.

Also, printing output like this which doesn't make sense:

Downloading huggingface://RedHatAI/Llama-3.2-1B-Instruct-FP8-dynamic/model.safetensors:latest ...
Trying to pull huggingface://RedHatAI/Llama-3.2-1B-Instruct-FP8-dynamic/model.safetensors:latest ...

Also remove recommendation to install via `brew install ramalama`, skips installing Apple specific
dependancies.

Signed-off-by: Eric Curtin <[email protected]>
@rhatdan
Copy link
Member

rhatdan commented Jul 8, 2025

LGTM

@rhatdan rhatdan merged commit bf0af80 into main Jul 8, 2025
28 of 37 checks passed
@ericcurtin ericcurtin deleted the mlx-fixes branch July 8, 2025 15:54
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