Spaces:
Running
Running
Sadjad Alikhani
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -14,29 +14,6 @@ import pandas as pd
|
|
14 |
from sklearn.metrics import f1_score
|
15 |
import seaborn as sns
|
16 |
|
17 |
-
# Set a fixed random seed for reproducibility
|
18 |
-
seed = 42
|
19 |
-
np.random.seed(seed)
|
20 |
-
torch.manual_seed(seed) # Ensure PyTorch random seed for CPU
|
21 |
-
|
22 |
-
# If running on GPU, set the seed for CUDA as well
|
23 |
-
if torch.cuda.is_available():
|
24 |
-
torch.cuda.manual_seed(seed)
|
25 |
-
torch.cuda.manual_seed_all(seed)
|
26 |
-
torch.backends.cudnn.deterministic = True
|
27 |
-
torch.backends.cudnn.benchmark = False
|
28 |
-
|
29 |
-
# Enable deterministic algorithms in PyTorch (slower, but ensures consistency)
|
30 |
-
torch.use_deterministic_algorithms(True)
|
31 |
-
|
32 |
-
# Limit the number of threads to prevent non-deterministic results from multithreading
|
33 |
-
torch.set_num_threads(1)
|
34 |
-
os.environ['MKL_NUM_THREADS'] = '1'
|
35 |
-
os.environ['OMP_NUM_THREADS'] = '1'
|
36 |
-
|
37 |
-
# Optional: Use for debugging to ensure intermediate values match across devices
|
38 |
-
torch.set_printoptions(precision=10)
|
39 |
-
|
40 |
#################### BEAM PREDICTION #########################}
|
41 |
def beam_prediction_task(data_percentage, task_complexity):
|
42 |
# Folder naming convention based on input_type, data_percentage, and task_complexity
|
@@ -438,8 +415,7 @@ def process_hdf5_file(uploaded_file, percentage):
|
|
438 |
# Step 4: Load the model from lwm_model module
|
439 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
440 |
print(f"Loading the LWM model on {device}...")
|
441 |
-
model = lwm_model.LWM.from_pretrained(device=device)
|
442 |
-
model = model.float()
|
443 |
#for name, param in model.state_dict().items():
|
444 |
# print(f"Layer: {name} | Weights: {param}")
|
445 |
|
@@ -454,7 +430,7 @@ def process_hdf5_file(uploaded_file, percentage):
|
|
454 |
#print(preprocessed_chs[0][0][-1]) #CORRECT
|
455 |
|
456 |
# Step 7: Perform inference using the functions from inference.py
|
457 |
-
output_emb = inference.lwm_inference(preprocessed_chs, 'cls_emb', model)
|
458 |
output_raw = inference.create_raw_dataset(preprocessed_chs, device)
|
459 |
|
460 |
print(f"Output Embeddings Shape: {output_emb.shape}")
|
|
|
14 |
from sklearn.metrics import f1_score
|
15 |
import seaborn as sns
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
#################### BEAM PREDICTION #########################}
|
18 |
def beam_prediction_task(data_percentage, task_complexity):
|
19 |
# Folder naming convention based on input_type, data_percentage, and task_complexity
|
|
|
415 |
# Step 4: Load the model from lwm_model module
|
416 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
417 |
print(f"Loading the LWM model on {device}...")
|
418 |
+
model = lwm_model.LWM.from_pretrained(device=device).float()
|
|
|
419 |
#for name, param in model.state_dict().items():
|
420 |
# print(f"Layer: {name} | Weights: {param}")
|
421 |
|
|
|
430 |
#print(preprocessed_chs[0][0][-1]) #CORRECT
|
431 |
|
432 |
# Step 7: Perform inference using the functions from inference.py
|
433 |
+
output_emb = inference.lwm_inference(preprocessed_chs, 'cls_emb', model, device)
|
434 |
output_raw = inference.create_raw_dataset(preprocessed_chs, device)
|
435 |
|
436 |
print(f"Output Embeddings Shape: {output_emb.shape}")
|