import torch.nn as nn
model = nn.Sequential(
nn.Linear(784, 256),
nn.ReLU(),
nn.Linear(256, 10)
).cuda()
optimizer = torch.optim.Adam(model.parameters(), lr=1e-3)
criterion = nn.CrossEntropyLoss()
for epoch in range(2):
with profiler.profile_context(f"epoch_{epoch+1}"):
# Your training step here
inputs = torch.randn(32, 784, device="cuda")
targets = torch.randint(0, 10, (32,), device="cuda")
optimizer.zero_grad()
outputs = model(inputs)
loss = criterion(outputs, targets)
loss.backward()
optimizer.step()