File size: 458 Bytes
853cd83 2835721 853cd83 2835721 853cd83 |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
from jax import numpy as jnp
from transformers import FlaxRobertaForMaskedLM, RobertaForMaskedLM
def to_f32(t):
return jax.tree_map(lambda x: x.astype(jnp.float32) if x.dtype == jnp.bfloat16 else x, t)
flax_model = FlaxRobertaForMaskedLM.from_pretrained("./")
flax_model.params = to_f32(flax_model.params)
flax_model.save_pretrained("./")
model = RobertaForMaskedLM.from_pretrained("./", from_flax=True)
model.save_pretrained("./", save_config=False)
|