Instructions to use mlx-community/ChatMusician-hf-4bit-mlx with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use mlx-community/ChatMusician-hf-4bit-mlx with MLX:
# Make sure mlx-lm is installed # pip install --upgrade mlx-lm # if on a CUDA device, also pip install mlx[cuda] # Generate text with mlx-lm from mlx_lm import load, generate model, tokenizer = load("mlx-community/ChatMusician-hf-4bit-mlx") prompt = "Once upon a time in" text = generate(model, tokenizer, prompt=prompt, verbose=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- MLX LM
How to use mlx-community/ChatMusician-hf-4bit-mlx with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Generate some text mlx_lm.generate --model "mlx-community/ChatMusician-hf-4bit-mlx" --prompt "Once upon a time"
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
pip install mlx-lm
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())
- Downloads last month
- 23
Hardware compatibility
Log In to add your hardware
Quantized