faster-transformers-scripts / load-big-models.py
ariG23498's picture
ariG23498 HF Staff
Create load-big-models.py
90fd4a4 verified
raw
history blame
896 Bytes
import time
t_ini = time.time()
import torch
from transformers import AutoModelForCausalLM, Mxfp4Config
print(f"Time for the imports: {time.time() - t_ini:.2f} s")
model_id = "openai/gpt-oss-20b"
device = torch.device("cuda:1")
t0 = time.time()
torch.cuda.synchronize(device)
print(f"Time for cuda warmup before loading model: {time.time() - t0:.2f} s")
t0 = time.time()
model = AutoModelForCausalLM.from_pretrained(
model_id, dtype=torch.bfloat16, device_map=device,
quantization_config=Mxfp4Config(dequantize=True)
)
torch.cuda.synchronize(device)
dt = time.time() - t0
print(f"time to load the model: {dt:.2f}")
max_mem = torch.cuda.max_memory_allocated(device) / 1024**3
current_mem = torch.cuda.memory_allocated(device) / 1024**3
print(f"Max: {max_mem:.2f} GiB")
print(f"Current: {current_mem:.2f} GiB")
print(f"Full time: {time.time() - t_ini:.2f} s")
model.to("cpu")
del model