| 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 |