Create load-big-models.py
Browse files- load-big-models.py +30 -0
load-big-models.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import time
|
| 2 |
+
|
| 3 |
+
t_ini = time.time()
|
| 4 |
+
import torch
|
| 5 |
+
from transformers import AutoModelForCausalLM, Mxfp4Config
|
| 6 |
+
print(f"Time for the imports: {time.time() - t_ini:.2f} s")
|
| 7 |
+
|
| 8 |
+
model_id = "openai/gpt-oss-20b"
|
| 9 |
+
device = torch.device("cuda:1")
|
| 10 |
+
|
| 11 |
+
t0 = time.time()
|
| 12 |
+
torch.cuda.synchronize(device)
|
| 13 |
+
print(f"Time for cuda warmup before loading model: {time.time() - t0:.2f} s")
|
| 14 |
+
t0 = time.time()
|
| 15 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 16 |
+
model_id, dtype=torch.bfloat16, device_map=device,
|
| 17 |
+
quantization_config=Mxfp4Config(dequantize=True)
|
| 18 |
+
)
|
| 19 |
+
torch.cuda.synchronize(device)
|
| 20 |
+
dt = time.time() - t0
|
| 21 |
+
print(f"time to load the model: {dt:.2f}")
|
| 22 |
+
|
| 23 |
+
max_mem = torch.cuda.max_memory_allocated(device) / 1024**3
|
| 24 |
+
current_mem = torch.cuda.memory_allocated(device) / 1024**3
|
| 25 |
+
print(f"Max: {max_mem:.2f} GiB")
|
| 26 |
+
print(f"Current: {current_mem:.2f} GiB")
|
| 27 |
+
print(f"Full time: {time.time() - t_ini:.2f} s")
|
| 28 |
+
|
| 29 |
+
model.to("cpu")
|
| 30 |
+
del model
|