Instructions to use tensorfiend/TuneLM-LFM3-1.7B-code2music-2011 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tensorfiend/TuneLM-LFM3-1.7B-code2music-2011 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="tensorfiend/TuneLM-LFM3-1.7B-code2music-2011", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("tensorfiend/TuneLM-LFM3-1.7B-code2music-2011", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("tensorfiend/TuneLM-LFM3-1.7B-code2music-2011", trust_remote_code=True, device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use tensorfiend/TuneLM-LFM3-1.7B-code2music-2011 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tensorfiend/TuneLM-LFM3-1.7B-code2music-2011" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tensorfiend/TuneLM-LFM3-1.7B-code2music-2011", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/tensorfiend/TuneLM-LFM3-1.7B-code2music-2011
- SGLang
How to use tensorfiend/TuneLM-LFM3-1.7B-code2music-2011 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "tensorfiend/TuneLM-LFM3-1.7B-code2music-2011" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tensorfiend/TuneLM-LFM3-1.7B-code2music-2011", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "tensorfiend/TuneLM-LFM3-1.7B-code2music-2011" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tensorfiend/TuneLM-LFM3-1.7B-code2music-2011", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use tensorfiend/TuneLM-LFM3-1.7B-code2music-2011 with Docker Model Runner:
docker model run hf.co/tensorfiend/TuneLM-LFM3-1.7B-code2music-2011
TuneLM-LFM3-1.7B-code2music-2011
TuneLM writes executable Strudel code from a music description. It returns composition notes and a complete JavaScript program that a Strudel runtime can play. Users can inspect the program, edit its musical parts, and render the result as audio.
This repository contains the merged GRPO step 250 checkpoint from the TuneLM project. It copies the weights and runtime files from the original checkpoint at revision b34fef426e5864617c9ebabff424668f8303819d.
Try TuneLM · Source code · code2music dataset
Model details
| Property | Value |
|---|---|
| Base model | LiquidAI LFM3-1.7B |
| Task | Music description to Strudel JavaScript |
| Training stages | SFT, Song Describer SFT continuation, and GRPO |
| Adaptation | LoRA, merged into the full model for this release |
| Selected RL checkpoint | Optimizer step 250 |
| Weight format | Safetensors, bfloat16 |
| TuneLM context budget | 6,144 tokens |
| Generation budget | Up to 3,072 new tokens |
| Original checkpoint | tensorfiend/tunelm-v2-lfm3-1.7B-grpo-step250 |
Use with Transformers
Use the checkpoint's chat template and enable its custom LFM3 implementation. The project used Transformers 5.20.2. Install a PyTorch build suitable for your machine.
pip install "transformers==5.20.2" accelerate torch
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "tensorfiend/TuneLM-LFM3-1.7B-code2music-2011"
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
model_id,
trust_remote_code=True,
dtype=torch.bfloat16,
device_map="auto",
)
model.eval()
system = """You are TuneLM, an algorithmic Strudel composer.
Return your musical choices in a <think> block, followed by one fenced
strudel code block containing the complete program.
Use setcpm(BPM/4) and a final pattern, stack, or arrange expression.
Use registered sounds. Avoid imports, network access, browser APIs,
loops, samples() calls, and external side effects.
"""
messages = [
{"role": "system", "content": system},
{"role": "user", "content": "A 120 BPM groove in C minor with drums and a soft bass line."},
]
inputs = tokenizer.apply_chat_template(
messages,
tokenize=True,
add_generation_prompt=True,
enable_thinking=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
with torch.inference_mode():
output = model.generate(
**inputs,
max_new_tokens=3072,
do_sample=False,
repetition_penalty=1.0,
use_cache=True,
pad_token_id=tokenizer.pad_token_id,
eos_token_id=tokenizer.eos_token_id,
)
text = tokenizer.decode(
output[0, inputs["input_ids"].shape[1]:],
skip_special_tokens=True,
)
if not text.lstrip().startswith("<think>"):
text = "<think>" + text
print(text)
Keep the input prompt within the remaining context budget. For the project's full system prompt, response parser, and conversation handling, use the TuneLM response implementation.
Output format
<think>
Composition notes describing the musical choices.
</think>
```strudel
setcpm(120/4);
stack(s("bd*4").gain(0.4), note("c2 g2").s("sawtooth").gain(0.3))
```
The example above illustrates the format. Run the returned program through the TuneLM verifier or a Strudel environment before playback. The TuneLM web app validates generated code and can request a repair when compilation or rendering fails.
Training
Initial SFT used 2,016 training examples and 200 validation examples. A second SFT stage used 510 accepted Song Describer training examples and 50 validation examples. Gemini teachers wrote the Strudel programs and composition notes. Both SFT stages used rank-16 LoRA adapters. The published code2music dataset combines these supervised examples for convenient reuse.
GRPO started from the merged Song Describer SFT model and used 1,764 separate RL training requests. It sampled four responses per request and rewarded executable programs that met checkable musical constraints. The reward also checked agreement between composition notes and code, applied craft guards, and penalized near-limit completions. The recorded run used a learning rate of 0.000005, temperature 0.8, KL coefficient 0.02, and a 3,072-token completion limit. This model is the checkpoint saved at step 250. See the reward design.
Evaluation
On the fixed 48-prompt validation monitor, this checkpoint produced 45 executable responses out of 48 (93.75%), a mean contract score of 0.7772, and a mean base reward of 0.7697. This monitor was used during checkpoint selection.
The audio evaluation used the first ten seconds of saved clips on the same 103 shared MusicPrefs prompts for every checkpoint. CLAP is higher-is-better. FAD, FAD-CLAP, and MAD are lower-is-better.
| Checkpoint | CLAP ↑ | FAD ↓ | FAD-CLAP ↓ | MAD ↓ |
|---|---|---|---|---|
| Song Describer SFT | 0.2559 | 5.4116 | 0.4645 | 2.2908 |
| GRPO step 250 | 0.2765 | 5.3979 | 0.4547 | 1.2422 |
Scores condition on the shared availability of rendered clips. They describe TuneLM's evaluation on the public MusicPrefs snapshot. A human preference study for TuneLM has not been conducted. See the evaluation protocol and MusicPrefs paper.
License and attribution
The model weights are distributed under the LFM Open License v1.0, inherited from Liquid AI's base model. Its commercial-use provisions depend on the license's revenue threshold. Read LICENSE for the complete terms. Bundled model implementation files retain their existing Apache-2.0 headers. The TuneLM application uses AGPL-3.0-or-later, and the training dataset has its own component-specific licenses. See NOTICE, LiquidAI LFM3-1.7B, and the dataset license.
Limitations
TuneLM can generate invalid APIs, unsupported sounds, inaccurate composition notes, or music that fails to match subjective preferences. It focuses on instrumental compositions within TuneLM's supported Strudel subset. Its response contains code that requires a separate audio runtime. Execution checks and musical constraint scores provide partial measures of composition quality. The source code and runtime files in this repository require review when enabling trust_remote_code=True.
- Downloads last month
- 29