versae's picture
Scripts for perplexity sampling and fixes
853cd83
raw
history blame
458 Bytes
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)