update-notebooks (#19337)
This commit is contained in:
1 parent
de65abc6b3
commit
6cd70af7c2
9 files changed
+1743
-3
No files matched your search
@@ -0,0 +1,574 @@
|
||||
Controllable Music Generation with MusicGen and OpenVINO
|
||||
========================================================
|
||||
|
||||
.. _top:
|
||||
|
||||
MusicGen is a single-stage auto-regressive Transformer model capable of
|
||||
generating high-quality music samples conditioned on text descriptions
|
||||
or audio prompts. The text prompt is passed to a text encoder model (T5)
|
||||
to obtain a sequence of hidden-state representations. These hidden
|
||||
states are fed to MusicGen, which predicts discrete audio tokens (audio
|
||||
codes). Finally, audio tokens are then decoded using an audio
|
||||
compression model (EnCodec) to recover the audio waveform.
|
||||
|
||||
.. figure:: https://user-images.githubusercontent.com/76463150/260439306-81c81c8d-1f9c-41d0-b881-9491766def8e.png
|
||||
:alt: pipeline
|
||||
|
||||
pipeline
|
||||
|
||||
`The MusicGen model <https://arxiv.org/abs/2306.05284>`__ does not
|
||||
require a self-supervised semantic representation of the text/audio
|
||||
prompts; it operates over several streams of compressed discrete music
|
||||
representation with efficient token interleaving patterns, thus
|
||||
eliminating the need to cascade multiple models to predict a set of
|
||||
codebooks (e.g. hierarchically or upsampling). Unlike prior models
|
||||
addressing music generation, it is able to generate all the codebooks in
|
||||
a single forward pass.
|
||||
|
||||
In this tutorial, we consider how to run the MusicGen model using
|
||||
OpenVINO.
|
||||
|
||||
We will use a model implementation from the `Hugging Face
|
||||
Transformers <https://huggingface.co/docs/transformers/index>`__
|
||||
library.
|
||||
|
||||
**Table of contents**:
|
||||
|
||||
- `Requirements and Imports <#prerequisites>`__
|
||||
- `Original Pipeline Inference <#musicgen-in-hf-transformers>`__
|
||||
- `Converting the Models to OpenVINO IR <#convert-models-to-openvino-intermediate-representation-ir-format>`__
|
||||
- `Convert Text Encoder <#convert-text-encoder>`__
|
||||
- `Convert MusicGen Language Model <#convert-musicgen-language-model>`__
|
||||
- `Convert Audio Decoder <#convert-audio-decoder>`__
|
||||
- `Embedding the Converted Models into the Pipeline <#embedding-the-converted-models-into-the-original-pipeline>`__
|
||||
- `Run Gradio App <#try-out-the-converted-pipeline>`__
|
||||
|
||||
Prerequisites `⇑ <#top>`__
|
||||
###############################################################################################################################
|
||||
|
||||
Install requirements `⇑ <#top>`__
|
||||
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
.. code:: ipython3
|
||||
|
||||
!pip install -q "openvino==2023.1.0.dev20230811"
|
||||
!pip install -q torch onnx gradio
|
||||
!pip install -q transformers
|
||||
|
||||
Imports `⇑ <#top>`__
|
||||
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
.. code:: ipython3
|
||||
|
||||
from collections import namedtuple
|
||||
import gc
|
||||
from pathlib import Path
|
||||
from typing import Optional, Tuple
|
||||
import warnings
|
||||
|
||||
from IPython.display import Audio
|
||||
from openvino import Core, convert_model, PartialShape, save_model, Type
|
||||
import numpy as np
|
||||
import torch
|
||||
from torch.jit import TracerWarning
|
||||
from transformers import AutoProcessor, MusicgenForConditionalGeneration
|
||||
from transformers.modeling_outputs import BaseModelOutputWithPastAndCrossAttentions, CausalLMOutputWithCrossAttentions
|
||||
|
||||
# Ignore tracing warnings
|
||||
warnings.filterwarnings("ignore", category=TracerWarning)
|
||||
|
||||
MusicGen in HF Transformers `⇑ <#top>`__
|
||||
###############################################################################################################################
|
||||
|
||||
To work with
|
||||
`MusicGen <https://huggingface.co/facebook/musicgen-small>`__ by Meta
|
||||
AI, we will use `Hugging Face Transformers
|
||||
package <https://github.com/huggingface/transformers>`__. Transformers
|
||||
package exposes the ``MusicgenForConditionalGeneration`` class,
|
||||
simplifying the model instantiation and weights loading. The code below
|
||||
demonstrates how to create a ``MusicgenForConditionalGeneration`` and
|
||||
generate a text-conditioned music sample.
|
||||
|
||||
.. code:: ipython3
|
||||
|
||||
# Load the pipeline
|
||||
model = MusicgenForConditionalGeneration.from_pretrained("facebook/musicgen-small", torchscript=True, return_dict=False)
|
||||
|
||||
In the cell below user is free to change PyTorch model inference device
|
||||
and the desired music sample length.
|
||||
|
||||
.. code:: ipython3
|
||||
|
||||
device = "cpu"
|
||||
sample_length = 8 # seconds
|
||||
|
||||
n_tokens = sample_length * model.config.audio_encoder.frame_rate + 3
|
||||
sampling_rate = model.config.audio_encoder.sampling_rate
|
||||
print('Sampling rate is', sampling_rate, 'Hz')
|
||||
|
||||
model.to(device)
|
||||
model.eval();
|
||||
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
Sampling rate is 32000 Hz
|
||||
|
||||
|
||||
Original Pipeline Inference `⇑ <#top>`__
|
||||
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
Text Preprocessing prepares the text prompt to be fed into the model,
|
||||
the ``processor`` object abstracts this step for us. Text tokenization
|
||||
is performed under the hood, it assigning tokens or IDs to the words; in
|
||||
other words, token IDs are just indices of the words in the model
|
||||
vocabulary. It helps the model understand the context of a sentence.
|
||||
|
||||
.. code:: ipython3
|
||||
|
||||
processor = AutoProcessor.from_pretrained("facebook/musicgen-small")
|
||||
|
||||
inputs = processor(
|
||||
text=["80s pop track with bassy drums and synth"],
|
||||
return_tensors="pt",
|
||||
)
|
||||
|
||||
audio_values = model.generate(**inputs.to(device), do_sample=True, guidance_scale=3, max_new_tokens=n_tokens)
|
||||
|
||||
Audio(audio_values[0].cpu().numpy(), rate=sampling_rate)
|
||||
|
||||
|
||||
|
||||
|
||||
.. raw:: html
|
||||
|
||||
|
||||
<audio controls="controls" >
|
||||
<source src="data:audio/wav;base64,UklGRiTQBwBXQVZFZm10IBAAAAABAAEAAH0AAAD6AAACABAAZGF0YQDQBwA1+gX4WQK5AEEA4AS5+ALwxvsR/4wRhw8l8gHg2dZN/sn2xOOwAJsO7PrV7gj8/+1q+Sj4N/kgETcJywgbFWT7wgSgGSb9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JNhCBFTIhVx4dF8wYbxgAGRoK2Q4yHr4UaxTSD4ABtQ9pGYkVkxTBEEwTxhVfEfYOFhjwHPUW6Q4BDz4SgRjnE6YIRw3eBPIHRBIaCGAFNQaqBQcINgLf/rUENwT/BEUGzgZzA6n7efes/NcIHgUYB3YLMwVlB0sCYf98AwsB//1H/TsGMRFLD9QDPfxB8h30O/4LADP5De298H70UP8FABPwDvYA8WfyL/sy8FbxC/Bu7aT52/YI9Nvttt/v6Ff3cfFR7x30Z+r09jnyruWw8sno9O3N+TTsM/Bf99PrW+tQ9iz2mvAU9AP0Ounx7N70Ie6Q8O3wge8Q9ALyXe4i9G35tPQ094nz0eeq7rTzSvQI9bHxHvUIBqUC0OtF7b3tLfUJ9wjt6u907avpLegP7jH8J/xh/Fz1Red48Eb21PmM9P7tJ/PR6w7wVvS77s3xOu8m82j4cPBi8ELzm+8h93j00+xI9UDxFvyvAk/0pvmA927xvPk27xTutvZrLine truncated
|
||||
Your browser does not support the audio element.
|
||||
</audio>
|
||||
|
||||
|
||||
|
||||
|
||||
Convert models to OpenVINO Intermediate representation (IR) format `⇑ <#top>`__
|
||||
###############################################################################################################################
|
||||
|
||||
Model conversion API enables direct conversion of PyTorch models. We
|
||||
will utilize the ``openvino.convert_model`` method to acquire OpenVINO
|
||||
IR versions of the models. The method requires a model object and
|
||||
example input for model tracing. Under the hood, the converter will use
|
||||
the PyTorch JIT compiler, to build a frozen model graph.
|
||||
|
||||
The pipeline consists of three important parts:
|
||||
|
||||
- The `T5 text encoder <https://huggingface.co/google/flan-t5-base>`__
|
||||
that translates user prompts into vectors in the latent space that
|
||||
the next model - the MusicGen decoder can utilize.
|
||||
- The `MusicGen Language
|
||||
Model <https://huggingface.co/docs/transformers/model_doc/musicgen#transformers.MusicgenForCausalLM>`__
|
||||
that auto-regressively generates audio tokens (codes).
|
||||
- The `EnCodec model <https://huggingface.co/facebook/encodec_24khz>`__
|
||||
(we will use only the decoder part of it) is used to decode the audio
|
||||
waveform from the audio tokens predicted by the MusicGen Language
|
||||
Model.
|
||||
|
||||
Let us convert each model step by step.
|
||||
|
||||
0. Set Up Variables `⇑ <#top>`__
|
||||
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
.. code:: ipython3
|
||||
|
||||
models_dir = Path("./models")
|
||||
t5_ir_path = models_dir / "t5.xml"
|
||||
musicgen_0_ir_path = models_dir / "mg_0.xml"
|
||||
musicgen_ir_path = models_dir / "mg.xml"
|
||||
audio_decoder_onnx_path = models_dir / "encodec.onnx"
|
||||
audio_decoder_ir_path = models_dir / "encodec.xml"
|
||||
|
||||
1. Convert Text Encoder `⇑ <#top>`__
|
||||
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
The text encoder is responsible for converting the input prompt, such as
|
||||
“90s rock song with loud guitars and heavy drums” into an embedding
|
||||
space that can be fed to the next model. Typically, it is a
|
||||
transformer-based encoder that maps a sequence of input tokens to a
|
||||
sequence of text embeddings.
|
||||
|
||||
The input for the text encoder consists of a tensor ``input_ids``, which
|
||||
contains token indices from the text processed by the tokenizer and
|
||||
``attention_mask`` that we will ignore as we will process one prompt at
|
||||
a time and this vector will just consist of ones.
|
||||
|
||||
We use OpenVINO Converter (OVC) below to convert the PyTorch model to
|
||||
the OpenVINO Intermediate Representation format (IR), which you can
|
||||
infer later with `OpenVINO
|
||||
runtime <https://docs.openvino.ai/latest/openvino_docs_OV_UG_OV_Runtime_User_Guide.html#doxid-openvino-docs-o-v-u-g-o-v-runtime-user-guide>`__
|
||||
|
||||
.. code:: ipython3
|
||||
|
||||
if not t5_ir_path.exists():
|
||||
t5_ov = convert_model(model.text_encoder, example_input={'input_ids': inputs['input_ids']})
|
||||
|
||||
save_model(t5_ov, t5_ir_path)
|
||||
del t5_ov
|
||||
gc.collect()
|
||||
|
||||
2. Convert MusicGen Language Model `⇑ <#top>`__
|
||||
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
This model is the central part of the whole pipeline, it takes the
|
||||
embedded text representation and generates audio codes that can be then
|
||||
decoded into actual music. The model outputs several streams of audio
|
||||
codes - tokens sampled from the pre-trained codebooks representing music
|
||||
efficiently with a lower frame rate. The model employs innovative codes
|
||||
intervaling strategy, that makes single-stage generation possible.
|
||||
|
||||
On the 0th generation step the model accepts ``input_ids`` representing
|
||||
the indices of audio codes, ``encoder_hidden_states`` and
|
||||
``encoder_attention_mask`` that were provided by the text encoder.
|
||||
|
||||
.. code:: ipython3
|
||||
|
||||
# Set model config `torchscript` to True, so the model returns a tuple as output
|
||||
model.decoder.config.torchscript = True
|
||||
|
||||
if not musicgen_0_ir_path.exists():
|
||||
decoder_input = {
|
||||
'input_ids': torch.ones(8, 1, dtype=torch.int64),
|
||||
'encoder_hidden_states': torch.ones(2, 12, 1024, dtype=torch.float32),
|
||||
'encoder_attention_mask': torch.ones(2, 12, dtype=torch.int64),
|
||||
}
|
||||
mg_ov_0_step = convert_model(model.decoder, example_input=decoder_input)
|
||||
|
||||
save_model(mg_ov_0_step, musicgen_0_ir_path)
|
||||
del mg_ov_0_step
|
||||
gc.collect()
|
||||
|
||||
On further iterations, the model is also provided with a
|
||||
``past_key_values`` argument that contains previous outputs of the
|
||||
attention block, it allows us to save on computations. But for us, it
|
||||
means that the signature of the model’s ``forward`` method changed.
|
||||
Models in OpenVINO IR have frozen calculation graphs and do not allow
|
||||
optional arguments, that is why the MusicGen model must be converted a
|
||||
second time, with an increased number of inputs.
|
||||
|
||||
.. code:: ipython3
|
||||
|
||||
# Add additional argument to the example_input dict
|
||||
if not musicgen_ir_path.exists():
|
||||
# Add `past_key_values` to the converted model signature
|
||||
decoder_input['past_key_values'] = tuple(
|
||||
[(
|
||||
torch.ones(2, 16, 1, 64, dtype=torch.float32),
|
||||
torch.ones(2, 16, 1, 64, dtype=torch.float32),
|
||||
torch.ones(2, 16, 12, 64, dtype=torch.float32),
|
||||
torch.ones(2, 16, 12, 64, dtype=torch.float32),
|
||||
)] * 24
|
||||
)
|
||||
|
||||
mg_ov = convert_model(model.decoder, example_input=decoder_input)
|
||||
|
||||
Moreover, the ``past_key_values`` argument is passed as
|
||||
``Tuple[Tuple[torch.tensor]]`` which is a hard call for the converter.
|
||||
The converter flattens these tuples, but have hard time identifying the
|
||||
correct shapes for the tensors. The code below goes over raveled
|
||||
``past_key_values``-related model inputs and sets the correct shape and
|
||||
type for them.
|
||||
|
||||
.. code:: ipython3
|
||||
|
||||
if not musicgen_ir_path.exists():
|
||||
for input in mg_ov.inputs[3:]:
|
||||
input.get_node().set_partial_shape(PartialShape([-1, 16, -1, 64]))
|
||||
input.get_node().set_element_type(Type.f32)
|
||||
|
||||
mg_ov.validate_nodes_and_infer_types()
|
||||
|
||||
save_model(mg_ov, musicgen_ir_path)
|
||||
del mg_ov
|
||||
gc.collect()
|
||||
|
||||
3. Convert Audio Decoder `⇑ <#top>`__
|
||||
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
The audio decoder which is a part of the EnCodec model is used to
|
||||
recover the audio waveform from the audio tokens predicted by the
|
||||
MusicGen decoder. To learn more about the model please refer to the
|
||||
corresponding `OpenVINO
|
||||
example <https://github.com/openvinotoolkit/openvino_notebooks/tree/main/notebooks/234-encodec-audio-compression>`__.
|
||||
|
||||
The audio decoder computation graph contains an LSTM sub-network which
|
||||
currently should be converted through ONNX. To do this we create a
|
||||
wrapper class with its ``forward()`` method calling
|
||||
``encodec.decode()``.
|
||||
|
||||
.. code:: ipython3
|
||||
|
||||
if not audio_decoder_onnx_path.exists():
|
||||
class AudioDecoder(torch.nn.Module):
|
||||
def __init__(self, model):
|
||||
super().__init__()
|
||||
self.model = model
|
||||
|
||||
def forward(self, output_ids):
|
||||
return self.model.decode(output_ids, [None])
|
||||
|
||||
audio_decoder_input = {'output_ids': torch.ones(1, 1, 4, n_tokens - 3, dtype=torch.int64),}
|
||||
|
||||
with torch.no_grad():
|
||||
torch.onnx.export(
|
||||
model=AudioDecoder(model.audio_encoder),
|
||||
args=audio_decoder_input,
|
||||
f=audio_decoder_onnx_path,
|
||||
input_names=['output_ids',],
|
||||
output_names=['decoded_audio'],
|
||||
dynamic_axes={
|
||||
'output_ids': {3: 'sequence_length'},
|
||||
'decoded_audio': {2: 'audio_values'}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
/home/idavidyu/.virtualenvs/test/lib/python3.10/site-packages/torch/onnx/symbolic_opset9.py:4476: UserWarning: Exporting a model to ONNX with a batch_size other than 1, with a variable length with LSTM can cause an error when running the ONNX model with a different batch size. Make sure to save the model with a batch size of 1, or define the initial states (h0/c0) as inputs of the model.
|
||||
warnings.warn(
|
||||
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
============= Diagnostic Run torch.onnx.export version 2.0.1+cu117 =============
|
||||
verbose: False, log level: Level.ERROR
|
||||
======================= 0 NONE 0 NOTE 0 WARNING 0 ERROR ========================
|
||||
|
||||
|
||||
|
||||
Now we can convert the frozen ONNX computation graph to OpenVINO IR.
|
||||
|
||||
.. code:: ipython3
|
||||
|
||||
# Now we can convert the model to OpenVINO IR
|
||||
if not audio_decoder_ir_path.exists():
|
||||
audio_decoder_ov = convert_model(str(audio_decoder_onnx_path))
|
||||
|
||||
save_model(audio_decoder_ov, audio_decoder_ir_path)
|
||||
del audio_decoder_ov
|
||||
gc.collect()
|
||||
|
||||
Embedding the converted models into the original pipeline `⇑ <#top>`__
|
||||
###############################################################################################################################
|
||||
|
||||
OpenVINO™ Runtime Python API is used to compile the model in OpenVINO IR
|
||||
format. The
|
||||
`Core <https://docs.openvino.ai/2022.3/api/ie_python_api/_autosummary/openvino.runtime.Core.html>`__
|
||||
class provides access to the OpenVINO Runtime API. The ``core`` object,
|
||||
which is an instance of the ``Core`` class represents the API and it is
|
||||
used to compile the model.
|
||||
|
||||
.. code:: ipython3
|
||||
|
||||
core = Core()
|
||||
|
||||
Select inference device `⇑ <#top>`__
|
||||
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
Select device that will be used to do models inference using OpenVINO
|
||||
from the dropdown list:
|
||||
|
||||
.. code:: ipython3
|
||||
|
||||
import ipywidgets as widgets
|
||||
|
||||
DEVICE = widgets.Dropdown(
|
||||
options=core.available_devices + ["AUTO"],
|
||||
value='AUTO',
|
||||
description='Device:',
|
||||
disabled=False,
|
||||
)
|
||||
|
||||
DEVICE
|
||||
|
||||
|
||||
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
Dropdown(description='Device:', index=2, options=('CPU', 'GPU', 'AUTO'), value='AUTO')
|
||||
|
||||
|
||||
|
||||
Adapt OpenVINO models to the original pipeline `⇑ <#top>`__
|
||||
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
Here we create wrapper classes for all three OpenVINO models that we
|
||||
want to embed in the original inference pipeline. Here are some of the
|
||||
things to consider when adapting an OV model: - Make sure that
|
||||
parameters passed by the original pipeline are forwarded to the compiled
|
||||
OV model properly; sometimes the OV model uses only a portion of the
|
||||
input arguments and some are ignored, sometimes you need to convert the
|
||||
argument to another data type or unwrap some data structures such as
|
||||
tuples or dictionaries. - Guarantee that the wrapper class returns
|
||||
results to the pipeline in an expected format. In the example below you
|
||||
can see how we pack OV model outputs into special classes declared in
|
||||
the HF repo. - Pay attention to the model method used in the original
|
||||
pipeline for calling the model - it may be not the ``forward`` method!
|
||||
Refer to the ``AudioDecoderWrapper`` to see how we wrap OV model
|
||||
inference into the ``decode`` method.
|
||||
|
||||
.. code:: ipython3
|
||||
|
||||
class TextEncoderWrapper(torch.nn.Module):
|
||||
def __init__(self, encoder_ir, config):
|
||||
super().__init__()
|
||||
self.encoder = core.compile_model(encoder_ir, DEVICE.value)
|
||||
self.config = config
|
||||
|
||||
def forward(self, input_ids, **kwargs):
|
||||
last_hidden_state = self.encoder(input_ids)[self.encoder.outputs[0]]
|
||||
last_hidden_state = torch.tensor(last_hidden_state)
|
||||
return BaseModelOutputWithPastAndCrossAttentions(last_hidden_state=last_hidden_state)
|
||||
|
||||
|
||||
class MusicGenWrapper(torch.nn.Module):
|
||||
def __init__(self, music_gen_lm_0_ir, music_gen_lm_ir, config, num_codebooks, build_delay_pattern_mask,
|
||||
apply_delay_pattern_mask):
|
||||
super().__init__()
|
||||
self.music_gen_lm_0 = core.compile_model(music_gen_lm_0_ir, DEVICE.value)
|
||||
self.music_gen_lm = core.compile_model(music_gen_lm_ir, DEVICE.value)
|
||||
self.config = config
|
||||
self.num_codebooks = num_codebooks
|
||||
self.build_delay_pattern_mask = build_delay_pattern_mask
|
||||
self.apply_delay_pattern_mask = apply_delay_pattern_mask
|
||||
|
||||
def forward(
|
||||
self,
|
||||
input_ids: torch.LongTensor = None,
|
||||
encoder_hidden_states: torch.FloatTensor = None,
|
||||
encoder_attention_mask: torch.LongTensor = None,
|
||||
past_key_values: Optional[Tuple[torch.FloatTensor]] = None,
|
||||
**kwargs
|
||||
):
|
||||
if past_key_values is None:
|
||||
model = self.music_gen_lm_0
|
||||
arguments = (input_ids, encoder_hidden_states, encoder_attention_mask)
|
||||
else:
|
||||
model = self.music_gen_lm
|
||||
arguments = (input_ids, encoder_hidden_states, encoder_attention_mask, *past_key_values)
|
||||
|
||||
output = model(arguments)
|
||||
return CausalLMOutputWithCrossAttentions(
|
||||
logits=torch.tensor(output[model.outputs[0]]),
|
||||
past_key_values=tuple([output[model.outputs[i]] for i in range(1, 97)]),
|
||||
)
|
||||
|
||||
class AudioDecoderWrapper(torch.nn.Module):
|
||||
def __init__(self, decoder_ir, config):
|
||||
super().__init__()
|
||||
self.decoder = core.compile_model(decoder_ir, DEVICE.value)
|
||||
self.config = config
|
||||
self.output_type = namedtuple("AudioDecoderOutput", ["audio_values"])
|
||||
|
||||
def decode(self, output_ids, audio_scales):
|
||||
output = self.decoder(output_ids)[self.decoder.outputs[0]]
|
||||
return self.output_type(audio_values=torch.tensor(output))
|
||||
|
||||
Now we initialize the wrapper objects and load them to the HF pipeline
|
||||
|
||||
.. code:: ipython3
|
||||
|
||||
text_encode_ov = TextEncoderWrapper(t5_ir_path, model.text_encoder.config)
|
||||
musicgen_decoder_ov = MusicGenWrapper(
|
||||
musicgen_0_ir_path,
|
||||
musicgen_ir_path,
|
||||
model.decoder.config,
|
||||
model.decoder.num_codebooks,
|
||||
model.decoder.build_delay_pattern_mask,
|
||||
model.decoder.apply_delay_pattern_mask
|
||||
)
|
||||
audio_encoder_ov = AudioDecoderWrapper(audio_decoder_ir_path, model.audio_encoder.config)
|
||||
|
||||
del model.text_encoder
|
||||
del model.decoder
|
||||
del model.audio_encoder
|
||||
gc.collect()
|
||||
|
||||
model.text_encoder = text_encode_ov
|
||||
model.decoder = musicgen_decoder_ov
|
||||
model.audio_encoder = audio_encoder_ov
|
||||
|
||||
We can now infer the pipeline backed by OpenVINO models.
|
||||
|
||||
.. code:: ipython3
|
||||
|
||||
processor = AutoProcessor.from_pretrained("facebook/musicgen-small")
|
||||
|
||||
inputs = processor(
|
||||
text=["80s pop track with bassy drums and synth"],
|
||||
return_tensors="pt",
|
||||
)
|
||||
|
||||
audio_values = model.generate(**inputs.to(device), do_sample=True, guidance_scale=3, max_new_tokens=n_tokens)
|
||||
|
||||
Audio(audio_values[0].cpu().numpy(), rate=sampling_rate)
|
||||
|
||||
|
||||
|
||||
|
||||
.. raw:: html
|
||||
|
||||
|
||||
<audio controls="controls" >
|
||||
<source src="data:audio/wav;base64,UklGRiTQBwBXQVZFZm10IBAAAAABAAEAAH0AAAD6AAACABAAZGF0YQDQBwCi/BH8RQAHAF//0gCW/Kr4jP02AJgIJQik/CL1efO/BBEApfdiAs0I/gAW+/X/7/p//hr9bf3VBU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f/o/GX91gIQBb0DywAnAC8BJgBi/kEByQRz/qj9rvyF+mf/1QBK/vv7if2D/Zf+df7vAPoGugMX/oP/ZQJgA1MFNwUrAVb+8QCGAbr/AwCv/Bj+xAKjBXYGSP/r/JL9swCqBEsAaQHmBOwGSgST/ab4pfhU/jv+gP/IANj9wf9eBBkGyQRaAMT5cPkYABMEFAGJ/rb+9fyy/QgBvALqBDkDsf0L/6H/KACDBJQCv/3H/8QBEf2s/LT/LAOd//z+WAR1AaD/l/4a/C/9qACIBp8HcP0C+Hb7ngNLAyQCIQO9/UYBRgQkBJ38mvsfBZUBuPka+a4AoAOXAZ8BOwBQ/lIBYgE5/hT/iv2X/wABtgA0A4YBBf7E/Ir+LALcAjABWv/+/jAAzf5I+kX8GAOKA47/FwGfA9T/AAJL/8j7s/uG/hUFJgS5ANP+zv4B/qsDTwaiAs4AaP7LADIFvAF3ANgDGQCQ/wv/1fxv/qkAHwGn/7QCKgS1AhECQwJbATMBbgKC/Yb6avxx/54CWABc+jr4Tfx6/g4C8gPlASr/kflaLine truncated
|
||||
Your browser does not support the audio element.
|
||||
</audio>
|
||||
|
||||
|
||||
|
||||
|
||||
Try out the converted pipeline `⇑ <#top>`__
|
||||
###############################################################################################################################
|
||||
|
||||
The demo app below is created using `Gradio
|
||||
package <https://www.gradio.app/docs/interface>`__
|
||||
|
||||
.. code:: ipython3
|
||||
|
||||
def _generate(prompt):
|
||||
inputs = processor(
|
||||
text=[prompt,],
|
||||
padding=True,
|
||||
return_tensors="pt",
|
||||
)
|
||||
audio_values = model.generate(**inputs.to(device), do_sample=True, guidance_scale=3, max_new_tokens=n_tokens)
|
||||
waveform = audio_values[0].cpu().squeeze() * 2**15
|
||||
return (sampling_rate, waveform.numpy().astype(np.int16))
|
||||
|
||||
.. code:: ipython3
|
||||
|
||||
import gradio as gr
|
||||
|
||||
demo = gr.Interface(
|
||||
_generate,
|
||||
inputs=[
|
||||
gr.Textbox(label="Text Prompt"),
|
||||
],
|
||||
outputs=[
|
||||
"audio"
|
||||
],
|
||||
examples=[
|
||||
["80s pop track with bassy drums and synth"],
|
||||
["Earthy tones, environmentally conscious, ukulele-infused, harmonic, breezy, easygoing, organic instrumentation, gentle grooves"],
|
||||
["90s rock song with loud guitars and heavy drums"],
|
||||
["Heartful EDM with beautiful synths and chords"],
|
||||
],
|
||||
)
|
||||
try:
|
||||
demo.launch(debug=True)
|
||||
except Exception:
|
||||
demo.launch(share=True, debug=True)
|
||||
|
||||
# If you are launching remotely, specify server_name and server_port
|
||||
# EXAMPLE: `demo.launch(server_name='your server name', server_port='server port in int')`
|
||||
# To learn more please refer to the Gradio docs: https://gradio.app/docs/
|
||||
File diff suppressed because it is too large.
Load diff
+3
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:5d4313551a427c44d4bba572717be2134c99e0e8785a8f11d5fd2993ccfb10da
|
||||
size 470354
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:e97e1e206d64979d8fc9aaa6e46786172062c9a9eb1817a351af2a38557a012f
|
||||
size 835162
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:7e4fb5a7c284be4de90e648badd409935c29b561b30f728ff905f522dd5a99f9
|
||||
size 699062
|
||||
Whitespace-only changes.
@@ -30,6 +30,7 @@
|
||||
229-distilbert-sequence-classification
|
||||
243-tflite-selfie-segmentation
|
||||
247-code-language-id
|
||||
250-music-generation
|
||||
401-object-detection
|
||||
402-pose-estimation
|
||||
403-action-recognition-webcam
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
232-clip-language-saliency-map
|
||||
243-tflite-selfie-segmentation
|
||||
244-named-entity-recognition
|
||||
250-music-generation
|
||||
251-tiny-sd-image-generation
|
||||
305-tensorflow-quantization-aware-training
|
||||
401-object-detection
|
||||
404-style-transfer
|
||||
|
||||
+21
-3
@@ -257,6 +257,10 @@ Demos that demonstrate inference on a particular model.
|
||||
+-------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------+
|
||||
| `249-oneformer-segmentation <notebooks/249-oneformer-segmentation-with-output.html>`__ | Universal segmentation with OneFormer and OpenVINO™. | |n249-img1| |
|
||||
+-------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------+
|
||||
| `250-music-generation <notebooks/250-music-generation-with-output.html>`__ |br| |n250| |br| |c250| | Controllable Music Generation with MusicGen and OpenVINO™. | |n250-img1| |
|
||||
+-------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------+
|
||||
| `251-tiny-sd-image-generation <notebooks/251-tiny-sd-image-generation-with-output.html>`__ |br| |c251| | Image Generation with Tiny-SD and OpenVINO™. | |n251-img1| |
|
||||
+-------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------+
|
||||
|
||||
|
||||
Model Training
|
||||
@@ -318,7 +322,7 @@ The following tutorials are guaranteed to provide a great experience with infere
|
||||
+-------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------+
|
||||
| `Whisper - Subtitles generation <notebooks/227-whisper-subtitles-generation-with-output.html>`__ |br| |c227| | Generate subtitles for video with OpenAI Whisper and OpenVINO. | |n227-img1| |
|
||||
+-------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------+
|
||||
| `CLIP - zero-shot-image-classification <notebooks/228-clip-zero-shot-image-classification-with-output.html>`__ | Perform Zero-shot image classification with CLIP and OpenVINO. | |n228-img1| |
|
||||
| `CLIP - zero-shot-image-classification <notebooks/228-clip-zero-shot-convert-with-output.html>`__ | Perform Zero-shot image classification with CLIP and OpenVINO. | |n228-img1| |
|
||||
+-------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------+
|
||||
| `BLIP - Visual-language-processing <notebooks/233-blip-visual-language-processing-with-output.html>`__ | Visual question answering and image captioning using BLIP and OpenVINO™. | |n233-img1| |
|
||||
+-------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------+
|
||||
@@ -326,11 +330,15 @@ The following tutorials are guaranteed to provide a great experience with infere
|
||||
+-------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------+
|
||||
| `DeepFloyd IF - Text-to-Image generation <notebooks/238-deep-floyd-if-with-output.html>`__ | Text-to-image generation with DeepFloyd IF and OpenVINO™. | |n238-img1| |
|
||||
+-------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------+
|
||||
| `ImageBind <notebooks/239-image-bind-with-output.html>`__ | Binding multimodal data, using ImageBind and OpenVINO™. | |n239-img1| |
|
||||
| `ImageBind <notebooks/239-image-bind-convert-with-output.html>`__ | Binding multimodal data, using ImageBind and OpenVINO™. | |n239-img1| |
|
||||
+-------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------+
|
||||
| `Dolly v2 <notebooks/240-dolly-2-instruction-following-with-output.html>`__ | Instruction following using Databricks Dolly 2.0 and OpenVINO™. | |n240-img1| |
|
||||
+-------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------+
|
||||
| `248-stable-diffusion-xl <notebooks/248-stable-diffusion-xl-with-output.html>`__ | Image generation with Stable Diffusion XL and OpenVINO™. | |n248-img1| |
|
||||
| `Stable Diffusion XL <notebooks/248-stable-diffusion-xl-with-output.html>`__ | Image generation with Stable Diffusion XL and OpenVINO™. | |n248-img1| |
|
||||
+-------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------+
|
||||
| `MusicGen <notebooks/250-music-generation-with-output.html>`__ |br| |n250| |br| |c250| | Controllable Music Generation with MusicGen and OpenVINO™. | |n250-img1| |
|
||||
+-------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------+
|
||||
| `Tiny SD <notebooks/251-tiny-sd-image-generation-with-output.html>`__ |br| |c251| | Image Generation with Tiny-SD and OpenVINO™. | |n251-img1| |
|
||||
+-------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------+
|
||||
|
||||
|
||||
@@ -487,6 +495,10 @@ Made with `contributors-img <https://contrib.rocks>`__.
|
||||
:target: https://user-images.githubusercontent.com/29454499/258651862-28b63016-c5ff-4263-9da8-73ca31100165.jpeg
|
||||
.. |n249-img1| image:: https://camo.githubusercontent.com/f46c3642d3266e9d56d8ea8a943e67825597de3ff51698703ea2ddcb1086e541/68747470733a2f2f6769746875622d70726f64756374696f6e2d757365722d61737365742d3632313064662e73332e616d617a6f6e6177732e636f6d2f37363136313235362f3235383634303731332d66383031626430392d653932372d346162642d616132662d3939393064653463616638642e676966
|
||||
:target: https://camo.githubusercontent.com/f46c3642d3266e9d56d8ea8a943e67825597de3ff51698703ea2ddcb1086e541/68747470733a2f2f6769746875622d70726f64756374696f6e2d757365722d61737365742d3632313064662e73332e616d617a6f6e6177732e636f6d2f37363136313235362f3235383634303731332d66383031626430392d653932372d346162642d616132662d3939393064653463616638642e676966
|
||||
.. |n250-img1| image:: https://user-images.githubusercontent.com/76463150/260439306-81c81c8d-1f9c-41d0-b881-9491766def8e.png
|
||||
:target: https://user-images.githubusercontent.com/76463150/260439306-81c81c8d-1f9c-41d0-b881-9491766def8e.png
|
||||
.. |n251-img1| image:: https://user-images.githubusercontent.com/29454499/260904650-274fc2f9-24d2-46a3-ac3d-d660ec3c9a19.png
|
||||
:target: https://user-images.githubusercontent.com/29454499/260904650-274fc2f9-24d2-46a3-ac3d-d660ec3c9a19.png
|
||||
.. |n301-img1| image:: https://user-images.githubusercontent.com/15709723/127779607-8fa34947-1c35-4260-8d04-981c41a2a2cc.png
|
||||
:target: https://user-images.githubusercontent.com/15709723/127779607-8fa34947-1c35-4260-8d04-981c41a2a2cc.png
|
||||
.. |n401-img1| image:: https://user-images.githubusercontent.com/4547501/141471665-82b28c86-cf64-4bfe-98b3-c314658f2d96.gif
|
||||
@@ -647,6 +659,12 @@ Made with `contributors-img <https://contrib.rocks>`__.
|
||||
:target: https://colab.research.google.com/github/openvinotoolkit/openvino_notebooks/blob/main/notebooks/244-named-entity-recognition/244-named-entity-recognition.ipynb
|
||||
.. |n247| image:: https://mybinder.org/badge_logo.svg
|
||||
:target: https://mybinder.org/v2/gh/openvinotoolkit/openvino_notebooks/HEAD?filepath=notebooks%2F247-code-language-id%2F247-code-language-id.ipynb
|
||||
.. |n250| image:: https://mybinder.org/badge_logo.svg
|
||||
:target: https://mybinder.org/v2/gh/openvinotoolkit/openvino_notebooks/HEAD?filepath=notebooks%2F250-music-generation%2F250-music-generation.ipynb
|
||||
.. |c250| image:: https://camo.githubusercontent.com/84f0493939e0c4de4e6dbe113251b4bfb5353e57134ffd9fcab6b8714514d4d1/68747470733a2f2f636f6c61622e72657365617263682e676f6f676c652e636f6d2f6173736574732f636f6c61622d62616467652e737667
|
||||
:target: https://colab.research.google.com/github/openvinotoolkit/openvino_notebooks/blob/main/notebooks/250-music-generation/250-music-generation.ipynb
|
||||
.. |c251| image:: https://camo.githubusercontent.com/84f0493939e0c4de4e6dbe113251b4bfb5353e57134ffd9fcab6b8714514d4d1/68747470733a2f2f636f6c61622e72657365617263682e676f6f676c652e636f6d2f6173736574732f636f6c61622d62616467652e737667
|
||||
:target: https://colab.research.google.com/github/openvinotoolkit/openvino_notebooks/blob/main/notebooks/251-tiny-sd-image-generation/251-tiny-sd-image-generation.ipynb
|
||||
.. |c305| image:: https://camo.githubusercontent.com/84f0493939e0c4de4e6dbe113251b4bfb5353e57134ffd9fcab6b8714514d4d1/68747470733a2f2f636f6c61622e72657365617263682e676f6f676c652e636f6d2f6173736574732f636f6c61622d62616467652e737667
|
||||
:width: 109
|
||||
:target: https://colab.research.google.com/github/openvinotoolkit/openvino_notebooks/blob/main/notebooks/305-tensorflow-quantization-aware-training/305-tensorflow-quantization-aware-training.ipynb
|
||||
|
||||
Reference in new issue
Block a user