Spaces:
Running
Running
Sadjad Alikhani
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,6 +14,38 @@ import pandas as pd
|
|
| 14 |
from sklearn.metrics import f1_score
|
| 15 |
import seaborn as sns
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
#################### BEAM PREDICTION #########################}
|
| 19 |
def beam_prediction_task(data_percentage, task_complexity):
|
|
|
|
| 14 |
from sklearn.metrics import f1_score
|
| 15 |
import seaborn as sns
|
| 16 |
|
| 17 |
+
import torch
|
| 18 |
+
import numpy as np
|
| 19 |
+
import random
|
| 20 |
+
import os
|
| 21 |
+
|
| 22 |
+
# Set a fixed random seed for reproducibility
|
| 23 |
+
seed = 42
|
| 24 |
+
random.seed(seed)
|
| 25 |
+
np.random.seed(seed)
|
| 26 |
+
torch.manual_seed(seed) # Ensure PyTorch random seed for CPU
|
| 27 |
+
|
| 28 |
+
# If running on GPU, set the seed for CUDA as well
|
| 29 |
+
if torch.cuda.is_available():
|
| 30 |
+
torch.cuda.manual_seed(seed)
|
| 31 |
+
torch.cuda.manual_seed_all(seed)
|
| 32 |
+
torch.backends.cudnn.deterministic = True
|
| 33 |
+
torch.backends.cudnn.benchmark = False
|
| 34 |
+
|
| 35 |
+
# Ensure that the model uses float32 precision (same as on GPU)
|
| 36 |
+
# Assuming you load your model later, ensure it's float precision.
|
| 37 |
+
# model = model.float() # Uncomment this when loading the model
|
| 38 |
+
|
| 39 |
+
# Enable deterministic algorithms in PyTorch (slower, but ensures consistency)
|
| 40 |
+
torch.use_deterministic_algorithms(True)
|
| 41 |
+
|
| 42 |
+
# Limit the number of threads to prevent non-deterministic results from multithreading
|
| 43 |
+
torch.set_num_threads(1)
|
| 44 |
+
os.environ['MKL_NUM_THREADS'] = '1'
|
| 45 |
+
os.environ['OMP_NUM_THREADS'] = '1'
|
| 46 |
+
|
| 47 |
+
# Optional: Use for debugging to ensure intermediate values match across devices
|
| 48 |
+
torch.set_printoptions(precision=10)
|
| 49 |
|
| 50 |
#################### BEAM PREDICTION #########################}
|
| 51 |
def beam_prediction_task(data_percentage, task_complexity):
|