Skip to content

Instantly share code, notes, and snippets.

@ytxmobile98
Created July 14, 2025 06:06
Show Gist options
  • Select an option

  • Save ytxmobile98/5b1a22a089a16aacb884a9bc5e835fcd to your computer and use it in GitHub Desktop.

Select an option

Save ytxmobile98/5b1a22a089a16aacb884a9bc5e835fcd to your computer and use it in GitHub Desktop.
How to find out the parameter size for a transformers model
from transformers import AutoModel
import torch
model_path = "./my_downloaded_model"
model = AutoModel.from_pretrained(model_path, local_files_only=True)
total_params = sum(p.numel() for p in model.parameters())
trainable_params = sum(p.numel() for p in model.parameters() if p.requires_grad)
print(f"Total parameters: {total_params}")
print(f"Trainable parameters: {trainable_params}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment