music generation model

提供商nagayama0706
分类audio-generation
许可证apache-2.0
下载量8
星标0

简介

这是一个基于 Apache-2.0 开源协议的音乐生成模型,旨在为开发者提供灵活的音频创作能力。与常见的商业音乐 AI 不同,它更侧重于通过模型权重实现可定制的音乐合成,适合需要将音频生成能力集成到自有应用中的开发者。无论是为短视频制作背景音乐,还是开发简单的 AI 作曲工具,该模型都提供了较低的准入门槛。对于习惯使用 Python 的用户来说,上手难度适中,可以将其视作音频领域的“生成式基座”,通过简单的参数调整或 Prompt 引导来探索不同的旋律风格。

核心亮点

  • 采用 Apache-2.0 协议,支持商业化自由部署
  • 专注音频生成,适合快速构建 AI 作曲应用
  • 轻量化集成,降低开发者构建音乐工具的门槛
  • 支持多种音乐风格探索,适配多样化创作场景

使用方法

安装依赖
# 安装 Hugging Face transformers
pip install transformers torch
SDK 使用
# 使用 transformers 加载模型
from transformers import AutoModel, AutoTokenizer

model = AutoModel.from_pretrained("nagayama0706/music_generation_model")
tokenizer = AutoTokenizer.from_pretrained("nagayama0706/music_generation_model")

Hugging Face 下载

我们推荐使用命令行或者 Hugging Face Hub SDK 来进行模型的下载。

操作指引:在下载前,请先通过如下命令安装 huggingface_hub:

操作指引
pip install -U huggingface_hub

命令行下载

下载完整模型库

下载完整模型库
huggingface-cli download nagayama0706/music_generation_model

下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)

下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)
huggingface-cli download nagayama0706/music_generation_model config.json --local-dir ./dir

更多命令行下载选项,可参见官方文档

SDK 下载

SDK 下载
# 模型下载
from huggingface_hub import snapshot_download
model_dir = snapshot_download('nagayama0706/music_generation_model')

Git 下载

请确保 lfs 已经被正确安装

Git 下载
git lfs install
git clone https://huggingface.co/nagayama0706/music_generation_model

如果您希望跳过 lfs 大文件下载,可以使用如下命令

跳过 LFS
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/nagayama0706/music_generation_model

模型文件托管在 Hugging Face Hub,使用 HF CLI / SDK / Git 直接下载,不经过本站。

PyTorch / Transformers 使用

安装 Transformers

安装 Transformers
pip install -U transformers torch

模型加载和推理

模型加载和推理
from transformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained('nagayama0706/music_generation_model')
tokenizer = AutoTokenizer.from_pretrained('nagayama0706/music_generation_model')

完整文档

来源: HuggingFace

---
tags:

  • merge

  • mergekit

  • lazymergekit

  • TheBloke/openchat_3.5-GPTQ

  • asigalov61/Allegro-Music-Transformer

base_model:
  • TheBloke/openchat_3.5-GPTQ

  • asigalov61/Allegro-Music-Transformer

license: apache-2.0
pipeline_tag: text-to-audio
---

music_generation_model

music_generation_model is a merge of the following models using LazyMergekit:


🧩 Configuration

yaml
slices:
  - sources:
      - model: TheBloke/openchat_3.5-GPTQ
        layer_range: [0, 32]
      - model: asigalov61/Allegro-Music-Transformer
        layer_range: [0, 32]
merge_method: slerp
base_model: TheBloke/openchat_3.5-GPTQ
parameters:
  t:
    - filter: self_attn
      value: [0, 0.5, 0.3, 0.7, 1]
    - filter: mlp
      value: [1, 0.5, 0.7, 0.3, 0]
    - value: 0.5
dtype: bfloat16

💻 Usage

python
!pip install -qU transformers accelerate

from transformers import AutoTokenizer
import transformers
import torch

model = "nagayama0706/music_generation_model"
messages = [{"role": "user", "content": "What is a large language model?"}]

tokenizer = AutoTokenizer.from_pretrained(model)
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
pipeline = transformers.pipeline(
"text-generation",
model=model,
torch_dtype=torch.float16,
device_map="auto",
)

outputs = pipeline(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
print(outputs[0]["generated_text"])