Skip to content

Commit

Permalink
fix indeterministic results in inference
Browse files Browse the repository at this point in the history
  • Loading branch information
Blazej Banaszewski committed Aug 22, 2024
1 parent 7ac5ba7 commit efca30f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions minimol/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

from torch_geometric.data import Batch

import random
import numpy as np


class Minimol:

Expand Down Expand Up @@ -55,10 +58,22 @@ def __init__(self, batch_size: int = 100):
gradient_acc=1,
global_bs=self.datamodule.batch_size_training,
)
self.set_training_mode_false(predictor)
predictor.load_state_dict(torch.load(state_dict_path), strict=False)
self.predictor = Fingerprinter(predictor, 'gnn:15')
self.predictor.setup()

def set_training_mode_false(self, module):
if isinstance(module, torch.nn.Module):
module.training = False
for submodule in module.children():
self.set_training_mode_false(submodule)
elif isinstance(module, list):
for value in module:
self.set_training_mode_false(value)
elif isinstance(module, dict):
for _, value in module.items():
self.set_training_mode_false(value)

def load_config(self, config_name):
hydra.initialize('ckpts/minimol_v1/', version_base=None)
Expand Down

0 comments on commit efca30f

Please sign in to comment.