---
title: ChatMusician-hf-4bit-mlx
canonical_url: "https://www.modelscope.cn/models/mlx-community/ChatMusician-hf-4bit-mlx"
md_url: "https://www.modelscope.cn/models/mlx-community/ChatMusician-hf-4bit-mlx.md"
repository: mlx-community/ChatMusician-hf-4bit-mlx
last_updated: 2024-12-20
license: mit
pipeline_tag: text-generation
tasks:
  - text-generation
model_type:
  - llama
architectures:
  - LlamaForCausalLM
parameters: 1.2B
tensor_type:
  - U32
  - F16
library_name:
  - mlx
  - safetensors
  - pytorch
frameworks:
  - pytorch
language:
  - en
inference_backends:
  - "deploy_task text/emb"
  - "lmdeploy 0.9.1"
  - "lmdeploy_turbomind 0.9.1"
  - "sglang 0.5.2"
  - "vllm 0.9.2"
downloads: 1001
stars: 0
tags:
  - mlx
---

# ChatMusician-hf-4bit-mlx

> ChatMusician-hf-4bit-mlx - mlx-community 在 ModelScope 开源的模型。mlx-community/ChatMusician-hf-4bit-mlx This model was converted to MLX format from m-a-p/ChatMusician. Refer to the original model card for more details on the model. Use with mlx

mlx-community/ChatMusician-hf-4bit-mlx 是 ModelScope 魔搭社区上的 1.2B 参数text-generation模型，采用 mit 许可，可用 deploy_task text/emb、lmdeploy 0.9.1、lmdeploy_turbomind 0.9.1 部署。

- **Repository**: mlx-community/ChatMusician-hf-4bit-mlx
- **License**: mit
- **Tasks**: text-generation
- **Parameters**: 1.2B
- **Inference backends**: deploy_task text/emb, lmdeploy 0.9.1, lmdeploy_turbomind 0.9.1, sglang 0.5.2, vllm 0.9.2
- **Tags**: mlx
- **Downloads**: 1001
- **Stars**: 0
- **Last updated**: 2024-12-20

Source: https://www.modelscope.cn/models/mlx-community/ChatMusician-hf-4bit-mlx

---

# mlx-community/ChatMusician-hf-4bit-mlx
This model was converted to MLX format from [`m-a-p/ChatMusician`]().
Refer to the [original model card](https://huggingface.co/m-a-p/ChatMusician) for more details on the model.
## Use with mlx

```bash
pip install mlx-lm
```

```python
import re
from string import Template
from mlx_lm.utils import generate, load

prompt_template = Template("Human: ${inst} </s> Assistant: ")


model, tokenizer = load("mlx-community/ChatMusician-hf-4bit-mlx")

instruction = """"Develop a musical piece using the given chord progression.
'Dm', 'C', 'Dm', 'Dm', 'C', 'Dm', 'C', 'Dm'
"""
prompt = prompt_template.safe_substitute({"inst": instruction})

response = generate(
    model=model,
    tokenizer=tokenizer,
    prompt=prompt,
    temp=0.6,
    top_p=0.9,
    max_tokens=1000,
    repetition_penalty=1.1,
)

# pip install symusic
from symusic import Score, Synthesizer
import wave

abc_pattern = r"(X:\d+\n(?:[^\n]*\n)+)"
abc_notation = re.findall(abc_pattern, response + "\n")[0]
s = Score.from_abc(abc_notation)
audio = Synthesizer().render(s, stereo=True)

sample_rate = 44100
audio = (audio * 32767).astype("int16")
with wave.open("cm_music_piece.wav", "w") as wf:
    wf.setnchannels(2)
    wf.setsampwidth(2)
    wf.setframerate(sample_rate)
    wf.writeframes(audio.tobytes())

```
