TRM-coding/PythonCopilot
039
1from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer2model_ckpt = "codeparrot"3org = "transformersbook"4def model_size(model):5 return sum(t.numel() for t in model.parameters())6tokenizer = AutoTokenizer.from_pretrained(org + "/" + model_ckpt)7config_small = AutoConfig.from_pretrained("gpt2", vocab_size=len(tokenizer))8model_small = AutoModelForCausalLM.from_config(config_small)9 10print(f'GPT-2 size: {model_size(model_small)/1000**2:.1f}M parameters')11 12model_small.save_pretrained("models/" + model_ckpt + "-small", push_to_hub=True)