|
import torch |
|
from transformers import AutoConfig, AutoModelForCausalLM |
|
|
|
|
|
config_path = "config.json" |
|
config = AutoConfig.from_pretrained(config_path) |
|
model = AutoModelForCausalLM.from_config(config) |
|
|
|
|
|
|
|
def reinitialize_weights(module): |
|
if hasattr(module, "weight") and not isinstance(module, torch.nn.LayerNorm): |
|
torch.nn.init.normal_(module.weight, mean=0.0, std=0.02) |
|
if hasattr(module, "bias") and module.bias is not None: |
|
torch.nn.init.constant_(module.bias, 0.0) |
|
|
|
|
|
model.apply(reinitialize_weights) |
|
|
|
|
|
model = model.to( |
|
dtype=torch.bfloat16 |
|
) |
|
|
|
|
|
model.save_pretrained("./micro_mistral", save_in_safe_tensors_format=True) |
|
|