Jupyter Notebooks
Last updated
import torch
print(f"CUDA available: {torch.cuda.is_available()}")
print(f"GPU: {torch.cuda.get_device_name(0)}")
print(f"VRAM: {torch.cuda.get_device_properties(0).total_mem / 1e9:.1f} GB")from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "meta-llama/Llama-3.2-1B"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.float16,
device_map="auto"
)
inputs = tokenizer("Hello, world!", return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=50)
print(tokenizer.decode(outputs[0]))import mlx.core as mx
print(f"MLX backend: {mx.default_device()}")a = mx.random.normal((1000, 1000))
b = mx.random.normal((1000, 1000))
c = a @ b # Matrix multiplication on Metal GPU
mx.eval(c)
print(f"Result shape: {c.shape}")from mlx_lm import load, generate
model, tokenizer = load("mlx-community/Llama-3.2-1B-Instruct-4bit")
response = generate(
model,
tokenizer,
prompt="Explain quantum computing in simple terms:",
max_tokens=200
)
print(response)!pip install datasets scikit-learn matplotlib seaborn