|
import jax.numpy as jnp |
|
from transformers import AutoFeatureExtractor, AutoTokenizer |
|
from models.modeling_flax_speech_encoder_decoder import FlaxSpeechEncoderDecoderModel |
|
|
|
encoder_id = "hf-internal-testing/tiny-random-wav2vec2" |
|
decoder_id = "hf-internal-testing/tiny-random-bart" |
|
|
|
model = FlaxSpeechEncoderDecoderModel.from_encoder_decoder_pretrained( |
|
encoder_id, decoder_id, encoder_from_pt=True, decoder_from_pt=True, encoder_add_adapter=True |
|
) |
|
|
|
model.config.encoder.feat_proj_dropout = 0.0 |
|
model.config.encoder.final_dropout = 0.0 |
|
model.config.encoder.mask_time_prob = 0.1 |
|
model.config.decoder_start_token_id = model.config.decoder.bos_token_id |
|
model.config.pad_token_id = model.config.decoder.pad_token_id |
|
model.config.eos_token_id = model.config.decoder.eos_token_id |
|
model.config.max_length = 20 |
|
model.config.num_beams = 1 |
|
model.config.encoder.layerdrop = 0.0 |
|
model.config.use_cache = False |
|
model.config.processor_class = "Wav2Vec2Processor" |
|
|
|
|
|
out = model.generate(jnp.ones((1, 2000))) |
|
|
|
model.save_pretrained("./") |
|
|
|
feature_extractor = AutoFeatureExtractor.from_pretrained(encoder_id) |
|
feature_extractor.save_pretrained("./") |
|
tokenizer = AutoTokenizer.from_pretrained(decoder_id) |
|
tokenizer.save_pretrained("./") |
|
|