ml-explore / ml-explore/mlx-examples

Convert method for only for pytorch/safetensors to MLX

Open
#1,374 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
9k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

Hi,

Currently the convert method implementation converts from pytorch/safetensors to MLX format:

CONVERT

We would like the convert to also do the reverse e.g., convert from MLX to pytorch/safetensors.

mlx_lm.convert --help

usage: mlx_lm.convert [-h] [--hf-path HF_PATH] [--mlx-path MLX_PATH] [-q] [--q-group-size Q_GROUP_SIZE] [--q-bits Q_BITS]
                      [--quant-predicate {mixed_2_6,mixed_3_4,mixed_3_6,mixed_4_6}] [--dtype {float16,bfloat16,float32}] [--upload-repo UPLOAD_REPO]
                      [-d]

Convert Hugging Face model to MLX format

options:
  -h, --help            show this help message and exit
  --hf-path HF_PATH     Path to the Hugging Face model.
  --mlx-path MLX_PATH   Path to save the MLX model.
  -q, --quantize        Generate a quantized model.
  --q-group-size Q_GROUP_SIZE
                        Group size for quantization.
  --q-bits Q_BITS       Bits per weight for quantization.
  --quant-predicate {mixed_2_6,mixed_3_4,mixed_3_6,mixed_4_6}
                        Mixed-bit quantization recipe.
  --dtype {float16,bfloat16,float32}
                        Type to save the non-quantized parameters. Defaults to config.json's `torch_dtype` or the current model weights dtype.
  --upload-repo UPLOAD_REPO
                        The Hugging Face repo to upload the model to.
  -d, --dequantize      Dequantize a quantized model.

We can add a flag --convert-to where we specify to which format we want the conversion to happen.

Regards,

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with llms/mlx_lm/convert.py and run mlx_lm.convert --help to understand the existing Hugging Face-to-MLX options. Define how a --convert-to option should select MLX-to-PyTorch/safetensors conversion, including the expected output path and supported cases; done means the reverse conversion works and the command help documents it.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.