reach-vb HF staff commited on
Commit
3939743
β€’
1 Parent(s): b178bb3

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +7 -6
README.md CHANGED
@@ -55,22 +55,23 @@ Try out MusicGen yourself!
55
 
56
  ## πŸ€— Transformers Usage
57
 
58
- You can run MusicGen locally with the πŸ€— Transformers library from version 4.31.0 onwards.
59
 
60
  1. First install the πŸ€— [Transformers library](https://github.com/huggingface/transformers) and scipy:
61
 
62
  ```
63
  pip install --upgrade pip
64
- pip install --upgrade transformers scipy
65
  ```
66
 
67
  2. Run inference via the `Text-to-Audio` (TTA) pipeline. You can infer the MusicGen model via the TTA pipeline in just a few lines of code!
68
 
69
  ```python
70
- from transformers import pipeline
71
  import scipy
 
 
72
 
73
- synthesiser = pipeline("text-to-audio", "facebook/musicgen-stereo-large")
74
 
75
  music = synthesiser("lo-fi music with a soothing melody", forward_params={"do_sample": True})
76
 
@@ -83,13 +84,13 @@ scipy.io.wavfile.write("musicgen_out.wav", rate=music["sampling_rate"], music=au
83
  from transformers import AutoProcessor, MusicgenForConditionalGeneration
84
 
85
  processor = AutoProcessor.from_pretrained("facebook/musicgen-stereo-large")
86
- model = MusicgenForConditionalGeneration.from_pretrained("facebook/musicgen-stereo-large")
87
 
88
  inputs = processor(
89
  text=["80s pop track with bassy drums and synth", "90s rock song with loud guitars and heavy drums"],
90
  padding=True,
91
  return_tensors="pt",
92
- )
93
 
94
  audio_values = model.generate(**inputs, max_new_tokens=256)
95
  ```
 
55
 
56
  ## πŸ€— Transformers Usage
57
 
58
+ You can run MusicGen Stereo models locally with the πŸ€— Transformers library from `main` onward.
59
 
60
  1. First install the πŸ€— [Transformers library](https://github.com/huggingface/transformers) and scipy:
61
 
62
  ```
63
  pip install --upgrade pip
64
+ pip install --upgrade git+https://github.com/huggingface/transformers.git scipy
65
  ```
66
 
67
  2. Run inference via the `Text-to-Audio` (TTA) pipeline. You can infer the MusicGen model via the TTA pipeline in just a few lines of code!
68
 
69
  ```python
 
70
  import scipy
71
+ import torch
72
+ from transformers import pipeline
73
 
74
+ synthesiser = pipeline("text-to-audio", "facebook/musicgen-stereo-large", torch_dtype=torch.float16, device="cuda")
75
 
76
  music = synthesiser("lo-fi music with a soothing melody", forward_params={"do_sample": True})
77
 
 
84
  from transformers import AutoProcessor, MusicgenForConditionalGeneration
85
 
86
  processor = AutoProcessor.from_pretrained("facebook/musicgen-stereo-large")
87
+ model = MusicgenForConditionalGeneration.from_pretrained("facebook/musicgen-stereo-large").to("cuda")
88
 
89
  inputs = processor(
90
  text=["80s pop track with bassy drums and synth", "90s rock song with loud guitars and heavy drums"],
91
  padding=True,
92
  return_tensors="pt",
93
+ ).to("cuda")
94
 
95
  audio_values = model.generate(**inputs, max_new_tokens=256)
96
  ```