Spaces:
Running on Zero
Running on Zero
Commit ·
019f062
1
Parent(s): dcdc33f
fix: added spaces.GPU decorator to choose_action for ZeroGPU compatibility
Browse files- requirements.txt +1 -0
- simulation/model.py +2 -0
requirements.txt
CHANGED
|
@@ -5,3 +5,4 @@ numpy==1.26.4
|
|
| 5 |
traci==1.20.0
|
| 6 |
sumolib==1.20.0
|
| 7 |
huggingface_hub>=1.16.0,<3.0
|
|
|
|
|
|
| 5 |
traci==1.20.0
|
| 6 |
sumolib==1.20.0
|
| 7 |
huggingface_hub>=1.16.0,<3.0
|
| 8 |
+
spaces
|
simulation/model.py
CHANGED
|
@@ -14,6 +14,7 @@ import numpy as np
|
|
| 14 |
import torch
|
| 15 |
import torch.nn as nn
|
| 16 |
from torch.distributions import Categorical
|
|
|
|
| 17 |
|
| 18 |
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 19 |
|
|
@@ -47,6 +48,7 @@ class PPOPolicy:
|
|
| 47 |
if seed is not None:
|
| 48 |
torch.manual_seed(seed)
|
| 49 |
|
|
|
|
| 50 |
def choose_action(self, state: np.ndarray) -> int:
|
| 51 |
with torch.no_grad():
|
| 52 |
tensor = torch.FloatTensor(state).unsqueeze(0).to(DEVICE)
|
|
|
|
| 14 |
import torch
|
| 15 |
import torch.nn as nn
|
| 16 |
from torch.distributions import Categorical
|
| 17 |
+
import spaces
|
| 18 |
|
| 19 |
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 20 |
|
|
|
|
| 48 |
if seed is not None:
|
| 49 |
torch.manual_seed(seed)
|
| 50 |
|
| 51 |
+
@spaces.GPU
|
| 52 |
def choose_action(self, state: np.ndarray) -> int:
|
| 53 |
with torch.no_grad():
|
| 54 |
tensor = torch.FloatTensor(state).unsqueeze(0).to(DEVICE)
|