-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_conda.py
37 lines (26 loc) · 984 Bytes
/
test_conda.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import torch
from lightning import LightningModule, Trainer
class SimpleModel(LightningModule):
def __init__(self):
super(SimpleModel, self).__init__()
self.layer = torch.nn.Linear(10, 1)
def forward(self, x):
return self.layer(x)
def training_step(self, batch, batch_idx):
x, y = batch
y_hat = self(x)
loss = torch.nn.functional.mse_loss(y_hat, y)
return loss
def configure_optimizers(self):
return torch.optim.Adam(self.parameters(), lr=1e-3)
# Create larger random data
x = torch.randn(64000, 10) # Increase the number of samples
y = torch.randn(64000, 1)
# Create DataLoader
train_loader = torch.utils.data.DataLoader(list(zip(x, y)), batch_size=32)
# Initialize the model
model = SimpleModel()
# Check if CUDA is availableprint(f"CUDA available: {torch.cuda.is_available()}")
# Run a simple training loop with Lightning
trainer = Trainer(max_epochs=100)
trainer.fit(model, train_loader)