Aliazimi00 commited on
Commit
4497238
·
verified ·
1 Parent(s): 07adf8e

Upload core/train_eval.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. core/train_eval.py +3 -6
core/train_eval.py CHANGED
@@ -1,4 +1,3 @@
1
- import spaces
2
  import numpy as np
3
  import pandas as pd
4
  import torch
@@ -18,6 +17,7 @@ import logging
18
  import torch.optim.lr_scheduler as lr_scheduler
19
  from io import StringIO
20
  import sys
 
21
 
22
  try:
23
  from torchsummary import summary
@@ -123,7 +123,7 @@ def select_features(df, features, target, selector_method, importance_threshold)
123
  logging.warning(f"Unsupported selector_method: {selector_method}, using all features")
124
  return features
125
 
126
- @spaces.GPU(duration=60) # Adjust duration as needed
127
  def train_and_evaluate(
128
  df,
129
  features,
@@ -143,13 +143,10 @@ def train_and_evaluate(
143
  selector_method="RandomForest",
144
  importance_threshold=0.0,
145
  scheduler_type="None",
146
- device=None,
147
  verbose=True
148
  ):
149
  try:
150
- # Ensure device is set to cuda if available
151
- if device is None:
152
- device = 'cuda' if torch.cuda.is_available() else 'cpu'
153
  logging.info(f"Starting train_and_evaluate: model={model_cls.__name__}, features={len(features)}, window={window}, horizon={horizon}, scheduler={scheduler_type}, selector_method={selector_method}")
154
  from .data import preprocess_data
155
 
 
 
1
  import numpy as np
2
  import pandas as pd
3
  import torch
 
17
  import torch.optim.lr_scheduler as lr_scheduler
18
  from io import StringIO
19
  import sys
20
+ import spaces
21
 
22
  try:
23
  from torchsummary import summary
 
123
  logging.warning(f"Unsupported selector_method: {selector_method}, using all features")
124
  return features
125
 
126
+ @spaces.GPU
127
  def train_and_evaluate(
128
  df,
129
  features,
 
143
  selector_method="RandomForest",
144
  importance_threshold=0.0,
145
  scheduler_type="None",
146
+ device='cuda',
147
  verbose=True
148
  ):
149
  try:
 
 
 
150
  logging.info(f"Starting train_and_evaluate: model={model_cls.__name__}, features={len(features)}, window={window}, horizon={horizon}, scheduler={scheduler_type}, selector_method={selector_method}")
151
  from .data import preprocess_data
152