Skip to content

Convert method for only for pytorch/safetensors to MLX #1374

@debasisdwivedy

Description

@debasisdwivedy

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,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions