wav2vec2-base-persian / src /convert_flax_to_pytorch.py
m3hrdadfi's picture
Add pt version
b2f4c8b
raw
history blame
470 Bytes
import jax
import jax.numpy as jnp
from transformers import FlaxWav2Vec2ForPreTraining, Wav2Vec2ForPreTraining
def to_f32(t):
return jax.tree_map(lambda x: x.astype(jnp.float32) if x.dtype == jnp.bfloat16 else x, t)
model_fx = FlaxWav2Vec2ForPreTraining.from_pretrained("../v0")
model_fx.params = to_f32(model_fx.params)
model_fx.save_pretrained("./fx")
model_pt = Wav2Vec2ForPreTraining.from_pretrained("./fx", from_flax=True)
model_pt.save_pretrained("./pt")