tsumugi-mrl
Pretrained music audio encoder from Tsumugi-MRL, with utilities for LoRA fine-tuning. The encoder reads stereo audio at 22,050 Hz and returns 512-dimensional frame features at 25 Hz.
Install
pip install tsumugi-mrl
The package requires PyTorch 2.7 or later. For GPU support, install the CUDA
build of torch and torchaudio for your platform from
pytorch.org first.
Extract features
import torch
from tsumugi_mrl import TsumugiMRLModel
model = TsumugiMRLModel.from_pretrained("anime-song/tsumugi-mrl").eval()
audio = torch.randn(1, 2, 22_050 * 4) # [batch, 2, samples], stereo 22,050 Hz
with torch.no_grad():
hidden = model(audio) # [batch, frames, 512]
clip = model.mean_pool(hidden) # [batch, 512]
Convert mono audio by repeating the channel. No pretraining objective trains
audio_projection, so use the frame features or their mean rather than
encode_embedding() unless you fine-tune that head.
Fine-tune with LoRA
import torch
from tsumugi_mrl import TsumugiMRLModel, apply_lora, load_lora, save_lora
encoder = TsumugiMRLModel.from_pretrained("anime-song/tsumugi-mrl")
apply_lora(encoder, rank=8, alpha=16) # q/k/v in all layers; other weights frozen
head = torch.nn.Linear(encoder.config.d_model, 10)
parameters = [p for p in encoder.parameters() if p.requires_grad] + list(head.parameters())
optimizer = torch.optim.AdamW(parameters, lr=1e-4)
# ... train ...
save_lora(encoder, "lora") # lora_config.json + lora.safetensors
restored = load_lora(TsumugiMRLModel.from_pretrained("anime-song/tsumugi-mrl"), "lora")
LoRAConfig selects other targets (to_out.0, to_gates, feed-forward
net.1/net.4), a subset of layers, per-pattern ranks, and extra trainable
parameters. merge_lora(model, unload=True) folds the adapters into ordinary
nn.Linear layers. See the
repository README
for details.
License
The code is released under the MIT License. The pretrained weights on the Hugging Face Hub are released separately under CC BY-NC 4.0.
Metadata
Release files for tsumugi-mrl 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tsumugi_mrl-0.1.0.tar.gz | 15.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tsumugi_mrl-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.9 kB
Release files / tsumugi_mrl-0.1.0.tar.gz
| Download URL | tsumugi_mrl-0.1.0.tar.gz |
|---|---|
| Size | 15.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
046c7c5e140a9760429ba40209831a3698f21791bf4b95edd79c06cf9c20edf3
|
|
BLAKE2b-256 checksum How to use checksums |
ffada085145ad43c91ea9cdbef30a40be76549b1f666a4a7db0b7357d5d0c2a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.19
|
Release files / tsumugi_mrl-0.1.0-py3-none-any.whl
| Download URL | tsumugi_mrl-0.1.0-py3-none-any.whl |
|---|---|
| Size | 16.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c096b4067b07969f1c1a55b69c089e23e5fcd57dd09a239d016941cd9be25714
|
|
BLAKE2b-256 checksum How to use checksums |
beb0f251c4d5ddfef2394450e6be3ffc41d87932704d5e875b9a26a425678fb2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.19
|