Google Research からのオーディオ生成に対する言語モデリング アプローチである AudioLM の Pytorch への実装
また、T5 による分類子なしのガイダンスによる調整作業も拡張されます。これにより、論文では提供されていないテキストからオーディオへの変換や TTS を行うことができます。はい、これは VALL-E がこのリポジトリからトレーニングできることを意味します。本質的には同じです。
この作品を公開で再現することに興味がある場合は、参加してください
このリポジトリには、SoundStream の MIT ライセンス版も含まれるようになりました。また、EnCodec とも互換性があり、この記事の執筆時点では MIT ライセンスを取得しています。
更新: AudioLM は基本的に、新しい MusicLM での音楽生成を「解決」するために使用されました
将来的には、このムービークリップは意味を成さなくなるでしょう。代わりに AI にプロンプトを表示するだけです。
Stability.ai は、最先端の人工知能研究をオープンソースで行うための寛大なスポンサーシップを提供しています
?素晴らしいアクセラレータとトランスフォーマーのライブラリに対するハグフェイス
MetaAI for Fairseq とリベラルライセンス
@eonglints と Joseph、専門的なアドバイスや専門知識、プル リクエストを提供してくれました。
サウンドストリームのデバッグを手伝ってくれた @djqualia、@yigityu、@inspirit、および @BlackFox1197
コードをレビューし、バグ修正を提出してくれた Allen と LWprogramming!
Ilya さん、マルチスケール弁別器のダウンサンプリングに関する問題の発見とサウンドストリーム トレーナーの改善について感謝します
Andrey はサウンドストリームの損失を特定し、適切なメル スペクトログラムのハイパーパラメータを教えてくれました。
Alejandro と Ilya は、トレーニング サウンドストリームで結果を共有し、ローカル アテンションの位置埋め込みに関するいくつかの問題に取り組んでくれました。
エンコーデック互換性を追加するための LWプログラミング!
FineTransformer
からサンプリングする際の EOS トークンの処理に関する問題を見つけるための LWprogramming !
@YoungloLee は、ストライドを考慮しないパディングに関連するサウンドストリームの 1D 因果畳み込みの大きなバグを特定してくれました。
Hayden 氏、Soundstream のマルチスケール弁別器のいくつかの矛盾を指摘してくれました
$ pip install audiolm-pytorch
ニューラル コーデックには 2 つのオプションがあります。事前トレーニングされた 24kHz エンコーデックを使用する場合は、次のように Encodec オブジェクトを作成するだけです。
from audiolm_pytorch import EncodecWrapper
encodec = EncodecWrapper ()
# Now you can use the encodec variable in the same way you'd use the soundstream variables below.
それ以外の場合は、元の論文により忠実に保つために、 SoundStream
使用できます。まず、 SoundStream
音声データの大規模なコーパスでトレーニングする必要があります。
from audiolm_pytorch import SoundStream , SoundStreamTrainer
soundstream = SoundStream (
codebook_size = 4096 ,
rq_num_quantizers = 8 ,
rq_groups = 2 , # this paper proposes using multi-headed residual vector quantization - https://arxiv.org/abs/2305.02765
use_lookup_free_quantizer = True , # whether to use residual lookup free quantization - there are now reports of successful usage of this unpublished technique
use_finite_scalar_quantizer = False , # whether to use residual finite scalar quantization
attn_window_size = 128 , # local attention receptive field at bottleneck
attn_depth = 2 # 2 local attention transformer blocks - the soundstream folks were not experts with attention, so i took the liberty to add some. encodec went with lstms, but attention should be better
)
trainer = SoundStreamTrainer (
soundstream ,
folder = '/path/to/audio/files' ,
batch_size = 4 ,
grad_accum_every = 8 , # effective batch size of 32
data_max_length_seconds = 2 , # train on 2 second audio
num_train_steps = 1_000_000
). cuda ()
trainer . train ()
# after a lot of training, you can test the autoencoding as so
soundstream . eval () # your soundstream must be in eval mode, to avoid having the residual dropout of the residual VQ necessary for training
audio = torch . randn ( 10080 ). cuda ()
recons = soundstream ( audio , return_recons_only = True ) # (1, 10080) - 1 channel
トレーニングされたSoundStream
、オーディオの汎用トークナイザーとして使用できます。
audio = torch . randn ( 1 , 512 * 320 )
codes = soundstream . tokenize ( audio )
# you can now train anything with the codebook ids
recon_audio_from_codes = soundstream . decode_from_codebook_indices ( codes )
# sanity check
assert torch . allclose (
recon_audio_from_codes ,
soundstream ( audio , return_recons_only = True )
)
AudioLMSoundStream
とMusicLMSoundStream
それぞれインポートすることで、 AudioLM
とMusicLM
に固有のサウンドストリームを使用することもできます。
from audiolm_pytorch import AudioLMSoundStream , MusicLMSoundStream
soundstream = AudioLMSoundStream (...) # say you want the hyperparameters as in Audio LM paper
# rest is the same as above
バージョン0.17.0
では、構成を覚えていなくても、 SoundStream
のクラス メソッドを呼び出してチェックポイント ファイルからロードできるようになりました。
from audiolm_pytorch import SoundStream
soundstream = SoundStream . init_and_load_from ( './path/to/checkpoint.pt' )
ウェイトとバイアスのトラッキングを使用するには、まずSoundStreamTrainer
でuse_wandb_tracking = True
を設定し、次に次の操作を実行します。
trainer = SoundStreamTrainer (
soundstream ,
...,
use_wandb_tracking = True
)
# wrap .train() with contextmanager, specifying project and run name
with trainer . wandb_tracker ( project = 'soundstream' , run = 'baseline' ):
trainer . train ()
次に、3 つの個別のトランスフォーマー ( SemanticTransformer
、 CoarseTransformer
、 FineTransformer
) をトレーニングする必要があります。
元。 SemanticTransformer
import torch
from audiolm_pytorch import HubertWithKmeans , SemanticTransformer , SemanticTransformerTrainer
# hubert checkpoints can be downloaded at
# https://github.com/facebookresearch/fairseq/tree/main/examples/hubert
wav2vec = HubertWithKmeans (
checkpoint_path = './hubert/hubert_base_ls960.pt' ,
kmeans_path = './hubert/hubert_base_ls960_L9_km500.bin'
)
semantic_transformer = SemanticTransformer (
num_semantic_tokens = wav2vec . codebook_size ,
dim = 1024 ,
depth = 6 ,
flash_attn = True
). cuda ()
trainer = SemanticTransformerTrainer (
transformer = semantic_transformer ,
wav2vec = wav2vec ,
folder = '/path/to/audio/files' ,
batch_size = 1 ,
data_max_length = 320 * 32 ,
num_train_steps = 1
)
trainer . train ()
元。 CoarseTransformer
import torch
from audiolm_pytorch import HubertWithKmeans , SoundStream , CoarseTransformer , CoarseTransformerTrainer
wav2vec = HubertWithKmeans (
checkpoint_path = './hubert/hubert_base_ls960.pt' ,
kmeans_path = './hubert/hubert_base_ls960_L9_km500.bin'
)
soundstream = SoundStream . init_and_load_from ( '/path/to/trained/soundstream.pt' )
coarse_transformer = CoarseTransformer (
num_semantic_tokens = wav2vec . codebook_size ,
codebook_size = 1024 ,
num_coarse_quantizers = 3 ,
dim = 512 ,
depth = 6 ,
flash_attn = True
)
trainer = CoarseTransformerTrainer (
transformer = coarse_transformer ,
codec = soundstream ,
wav2vec = wav2vec ,
folder = '/path/to/audio/files' ,
batch_size = 1 ,
data_max_length = 320 * 32 ,
num_train_steps = 1_000_000
)
trainer . train ()
元。 FineTransformer
import torch
from audiolm_pytorch import SoundStream , FineTransformer , FineTransformerTrainer
soundstream = SoundStream . init_and_load_from ( '/path/to/trained/soundstream.pt' )
fine_transformer = FineTransformer (
num_coarse_quantizers = 3 ,
num_fine_quantizers = 5 ,
codebook_size = 1024 ,
dim = 512 ,
depth = 6 ,
flash_attn = True
)
trainer = FineTransformerTrainer (
transformer = fine_transformer ,
codec = soundstream ,
folder = '/path/to/audio/files' ,
batch_size = 1 ,
data_max_length = 320 * 32 ,
num_train_steps = 1_000_000
)
trainer . train ()
今すぐみんな一緒に
from audiolm_pytorch import AudioLM
audiolm = AudioLM (
wav2vec = wav2vec ,
codec = soundstream ,
semantic_transformer = semantic_transformer ,
coarse_transformer = coarse_transformer ,
fine_transformer = fine_transformer
)
generated_wav = audiolm ( batch_size = 1 )
# or with priming
generated_wav_with_prime = audiolm ( prime_wave = torch . randn ( 1 , 320 * 8 ))
# or with text condition, if given
generated_wav_with_text_condition = audiolm ( text = [ 'chirping of birds and the distant echos of bells' ])
更新: 「VALL-E」を考慮すると、これは機能するようです
元。セマンティックトランスフォーマー
import torch
from audiolm_pytorch import HubertWithKmeans , SemanticTransformer , SemanticTransformerTrainer
wav2vec = HubertWithKmeans (
checkpoint_path = './hubert/hubert_base_ls960.pt' ,
kmeans_path = './hubert/hubert_base_ls960_L9_km500.bin'
)
semantic_transformer = SemanticTransformer (
num_semantic_tokens = 500 ,
dim = 1024 ,
depth = 6 ,
has_condition = True , # this will have to be set to True
cond_as_self_attn_prefix = True # whether to condition as prefix to self attention, instead of cross attention, as was done in 'VALL-E' paper
). cuda ()
# mock text audio dataset (as an example)
# you will have to extend your own from `Dataset`, and return an audio tensor as well as a string (the audio description) in any order (the framework will autodetect and route it into the transformer)
from torch . utils . data import Dataset
class MockTextAudioDataset ( Dataset ):
def __init__ ( self , length = 100 , audio_length = 320 * 32 ):
super (). __init__ ()
self . audio_length = audio_length
self . len = length
def __len__ ( self ):
return self . len
def __getitem__ ( self , idx ):
mock_audio = torch . randn ( self . audio_length )
mock_caption = 'audio caption'
return mock_caption , mock_audio
dataset = MockTextAudioDataset ()
# instantiate semantic transformer trainer and train
trainer = SemanticTransformerTrainer (
transformer = semantic_transformer ,
wav2vec = wav2vec ,
dataset = dataset ,
batch_size = 4 ,
grad_accum_every = 8 ,
data_max_length = 320 * 32 ,
num_train_steps = 1_000_000
)
trainer . train ()
# after much training above
sample = trainer . generate ( text = [ 'sound of rain drops on the rooftops' ], batch_size = 1 , max_length = 2 ) # (1, < 128) - may terminate early if it detects [eos]
すべてのトレーナー クラスが ? を使用しているためです。アクセラレータでは、 accelerate
コマンドを使用してマルチ GPU トレーニングを簡単に実行できます。
プロジェクトのルートで
$ accelerate config
次に、同じディレクトリ内に
$ accelerate launch train . py
完全な粗いトランスフォーマー
埋め込みにはfairseq vq-wav2vecを使用します
コンディショニングを追加する
分類子の無料ガイダンスを追加
一意の連続を追加します
eonglint が推奨する、Hubert 中間機能をセマンティック トークンとして使用する機能を組み込む
可変長オーディオに対応し、eos トークンを導入します
粗変圧器を使用してユニークな連続動作を確認します
すべての識別子の損失をログに出力します
セマンティック トークンを生成するときに処理します。一意の連続処理を考慮すると、最後のログが必ずしもシーケンスの最後であるとは限りません。
Coarse Transformer と Fine Transformer の両方の完全なサンプリング コードですが、これは注意が必要です
プロンプトの有無にかかわらず、完全な推論がAudioLM
クラスで機能することを確認します。
サウンドストリーム用の完全なトレーニング コードを完成し、弁別トレーニングを処理します。
サウンドストリームの弁別器に効率的な勾配ペナルティを追加します
サウンド データセット -> トランスフォーマーからサンプル Hz を接続し、トレーニング中に適切なリサンプリングを行います。データセットにさまざまなサウンド ファイルを含めることを許可するか、同じサンプル Hz を強制するかを検討します。
3 つの変圧器すべての完全な変圧器トレーニング コード
リファクタリングして、セマンティック トランスフォーマーに一意の連続したものと wav を Hubert または vq-wav2vec に処理するラッパーを持たせる
プロンプト側で EOS トークンを処理しないだけです (粗いトランスフォーマーのセマンティック、細かいトランスフォーマーの粗いセマンティック)
忘れっぽい因果マスキングによる構造化ドロップアウトを追加し、従来のドロップアウトよりもはるかに優れています
Fairseq でのログ記録を抑制する方法を理解する
audiolm に渡される 3 つのトランスフォーマーすべてに互換性があることをアサートします。
粗いものと細かいものの間の量子化器の絶対一致位置に基づいて、細かいトランスフォーマーに特殊な相対位置埋め込みを可能にします。
HiFi コーデックから、サウンドストリームでグループ化された残差 vq を許可します (vector-quantize-pytorch ライブラリのGroupedResidualVQ
を使用します)。
NoPE でフラッシュ アテンションを追加する
AudioLM
でプライム ウェーブをオーディオ ファイルへのパスとして受け入れ、セマンティックと音響の自動リサンプリングを行います。
すべてのトランスフォーマーにキー/値のキャッシュを追加し、推論を高速化します
階層的な粗いおよび細かいトランスフォーマーを設計する
仕様のデコードを調査し、最初に X-transformers でテストし、次に該当する場合は移植します
残りの vq にグループが存在する場合に位置埋め込みをやり直す
手始めに音声合成を使ってテストする
cli ツール、 audiolm generate <wav.file | text>
作成し、生成された wav ファイルをローカル ディレクトリに保存します
可変長オーディオの場合は wave のリストを返します。
生の波形がさまざまな周波数でリサンプリングされる、粗いトランスフォーマーのテキスト条件付きトレーニングのエッジケースに対処するだけです。長さに基づいてルート方法を自動決定する
@inproceedings { Borsos2022AudioLMAL ,
title = { AudioLM: a Language Modeling Approach to Audio Generation } ,
author = { Zal{'a}n Borsos and Rapha{"e}l Marinier and Damien Vincent and Eugene Kharitonov and Olivier Pietquin and Matthew Sharifi and Olivier Teboul and David Grangier and Marco Tagliasacchi and Neil Zeghidour } ,
year = { 2022 }
}
@misc { https://doi.org/10.48550/arxiv.2107.03312 ,
title = { SoundStream: An End-to-End Neural Audio Codec } ,
author = { Zeghidour, Neil and Luebs, Alejandro and Omran, Ahmed and Skoglund, Jan and Tagliasacchi, Marco } ,
publisher = { arXiv } ,
url = { https://arxiv.org/abs/2107.03312 } ,
year = { 2021 }
}
@misc { shazeer2020glu ,
title = { GLU Variants Improve Transformer } ,
author = { Noam Shazeer } ,
year = { 2020 } ,
url = { https://arxiv.org/abs/2002.05202 }
}
@article { Shazeer2019FastTD ,
title = { Fast Transformer Decoding: One Write-Head is All You Need } ,
author = { Noam M. Shazeer } ,
journal = { ArXiv } ,
year = { 2019 } ,
volume = { abs/1911.02150 }
}
@article { Ho2022ClassifierFreeDG ,
title = { Classifier-Free Diffusion Guidance } ,
author = { Jonathan Ho } ,
journal = { ArXiv } ,
year = { 2022 } ,
volume = { abs/2207.12598 }
}
@misc { crowson2022 ,
author = { Katherine Crowson } ,
url = { https://twitter.com/rivershavewings }
}
@misc { ding2021cogview ,
title = { CogView: Mastering Text-to-Image Generation via Transformers } ,
author = { Ming Ding and Zhuoyi Yang and Wenyi Hong and Wendi Zheng and Chang Zhou and Da Yin and Junyang Lin and Xu Zou and Zhou Shao and Hongxia Yang and Jie Tang } ,
year = { 2021 } ,
eprint = { 2105.13290 } ,
archivePrefix = { arXiv } ,
primaryClass = { cs.CV }
}
@article { Liu2022FCMFC ,
title = { FCM: Forgetful Causal Masking Makes Causal Language Models Better Zero-Shot Learners } ,
author = { Hao Liu and Xinyang Geng and Lisa Lee and Igor Mordatch and Sergey Levine and Sharan Narang and P. Abbeel } ,
journal = { ArXiv } ,
year = { 2022 } ,
volume = { abs/2210.13432 }
}
@inproceedings { anonymous2022normformer ,
title = { NormFormer: Improved Transformer Pretraining with Extra Normalization } ,
author = { Anonymous } ,
booktitle = { Submitted to The Tenth International Conference on Learning Representations } ,
year = { 2022 } ,
url = { https://openreview.net/forum?id=GMYWzWztDx5 } ,
note = { under review }
}
@misc { liu2021swin ,
title = { Swin Transformer V2: Scaling Up Capacity and Resolution } ,
author = { Ze Liu and Han Hu and Yutong Lin and Zhuliang Yao and Zhenda Xie and Yixuan Wei and Jia Ning and Yue Cao and Zheng Zhang and Li Dong and Furu Wei and Baining Guo } ,
year = { 2021 } ,
eprint = { 2111.09883 } ,
archivePrefix = { arXiv } ,
primaryClass = { cs.CV }
}
@article { Li2021LocalViTBL ,
title = { LocalViT: Bringing Locality to Vision Transformers } ,
author = { Yawei Li and K. Zhang and Jie Cao and Radu Timofte and Luc Van Gool } ,
journal = { ArXiv } ,
year = { 2021 } ,
volume = { abs/2104.05707 }
}
@article { Defossez2022HighFN ,
title = { High Fidelity Neural Audio Compression } ,
author = { Alexandre D'efossez and Jade Copet and Gabriel Synnaeve and Yossi Adi } ,
journal = { ArXiv } ,
year = { 2022 } ,
volume = { abs/2210.13438 }
}
@article { Hu2017SqueezeandExcitationN ,
title = { Squeeze-and-Excitation Networks } ,
author = { Jie Hu and Li Shen and Gang Sun } ,
journal = { 2018 IEEE/CVF Conference on Computer Vision and Pattern Recognition } ,
year = { 2017 } ,
pages = { 7132-7141 }
}
@inproceedings { Yang2023HiFiCodecGV ,
title = { HiFi-Codec: Group-residual Vector quantization for High Fidelity Audio Codec } ,
author = { Dongchao Yang and Songxiang Liu and Rongjie Huang and Jinchuan Tian and Chao Weng and Yuexian Zou } ,
year = { 2023 }
}
@article { Kazemnejad2023TheIO ,
title = { The Impact of Positional Encoding on Length Generalization in Transformers } ,
author = { Amirhossein Kazemnejad and Inkit Padhi and Karthikeyan Natesan Ramamurthy and Payel Das and Siva Reddy } ,
journal = { ArXiv } ,
year = { 2023 } ,
volume = { abs/2305.19466 }
}
@inproceedings { dao2022flashattention ,
title = { Flash{A}ttention: Fast and Memory-Efficient Exact Attention with {IO}-Awareness } ,
author = { Dao, Tri and Fu, Daniel Y. and Ermon, Stefano and Rudra, Atri and R{'e}, Christopher } ,
booktitle = { Advances in Neural Information Processing Systems } ,
year = { 2022 }
}
@misc { yu2023language ,
title = { Language Model Beats Diffusion -- Tokenizer is Key to Visual Generation } ,
author = { Lijun Yu and José Lezama and Nitesh B. Gundavarapu and Luca Versari and Kihyuk Sohn and David Minnen and Yong Cheng and Agrim Gupta and Xiuye Gu and Alexander G. Hauptmann and Boqing Gong and Ming-Hsuan Yang and Irfan Essa and David A. Ross and Lu Jiang } ,
year = { 2023 } ,
eprint = { 2310.05737 } ,
archivePrefix = { arXiv } ,
primaryClass = { cs.CV }
}
@inproceedings { Katsch2023GateLoopFD ,
title = { GateLoop: Fully Data-Controlled Linear Recurrence for Sequence Modeling } ,
author = { Tobias Katsch } ,
year = { 2023 } ,
url = { https://api.semanticscholar.org/CorpusID:265018962 }
}
@article { Fifty2024Restructuring ,
title = { Restructuring Vector Quantization with the Rotation Trick } ,
author = { Christopher Fifty, Ronald G. Junkins, Dennis Duan, Aniketh Iyengar, Jerry W. Liu, Ehsan Amid, Sebastian Thrun, Christopher Ré } ,
journal = { ArXiv } ,
year = { 2024 } ,
volume = { abs/2410.06424 } ,
url = { https://api.semanticscholar.org/CorpusID:273229218 }
}
@inproceedings { Zhou2024ValueRL ,
title = { Value Residual Learning For Alleviating Attention Concentration In Transformers } ,
author = { Zhanchao Zhou and Tianyi Wu and Zhiyun Jiang and Zhenzhong Lan } ,
year = { 2024 } ,
url = { https://api.semanticscholar.org/CorpusID:273532030 }
}