-
Notifications
You must be signed in to change notification settings - Fork 87
POC: enable to train at the double precision #207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,15 +15,17 @@ def __init__( | |
pre_transform=None, | ||
pre_filter=None, | ||
paths=None, | ||
atomic_numbers=None, | ||
max_gradient=None, | ||
subsample_molecules=1, | ||
): | ||
assert isinstance(paths, (str, list)) | ||
|
||
arg_hash = f"{paths}{max_gradient}{subsample_molecules}" | ||
arg_hash = f"{paths}{atomic_numbers}{max_gradient}{subsample_molecules}" | ||
arg_hash = hashlib.md5(arg_hash.encode()).hexdigest() | ||
self.name = f"{self.__class__.__name__}-{arg_hash}" | ||
self.paths = paths | ||
self.atomic_numbers = atomic_numbers | ||
self.max_gradient = max_gradient | ||
self.subsample_molecules = int(subsample_molecules) | ||
super().__init__(root, transform, pre_transform, pre_filter) | ||
|
@@ -180,6 +182,11 @@ def sample_iter(self, mol_ids=False): | |
fq = pt.tensor(mol["formal_charges"], dtype=pt.long) | ||
q = fq.sum() | ||
|
||
# Keep molecules with specific elements | ||
if self.atomic_numbers: | ||
if not set(z.numpy()).issubset(self.atomic_numbers): | ||
continue | ||
|
||
for i_conf, (pos, y, neg_dy, pq, dp) in enumerate(load_confs(mol, n_atoms=len(z))): | ||
|
||
# Skip samples with large forces | ||
|
@@ -220,6 +227,7 @@ def processed_file_names(self): | |
def process(self): | ||
|
||
print("Arguments") | ||
print(f" atomic_numbers: {self.atomic_numbers}") | ||
print(f" max_gradient: {self.max_gradient} eV/A") | ||
print(f" subsample_molecules: {self.subsample_molecules}\n") | ||
|
||
|
@@ -309,9 +317,7 @@ def get(self, idx): | |
atoms = slice(self.idx_mm[idx], self.idx_mm[idx + 1]) | ||
z = pt.tensor(self.z_mm[atoms], dtype=pt.long) | ||
pos = pt.tensor(self.pos_mm[atoms], dtype=pt.float32) | ||
y = pt.tensor(self.y_mm[idx], dtype=pt.float32).view( | ||
1, 1 | ||
) # It would be better to use float64, but the trainer complaints | ||
y = pt.tensor(self.y_mm[idx], dtype=pt.float64).view(1, 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would pass dtype as an argument to Ace here and store everything in the correct type. I do not see why store pos in float32 and y in float64. |
||
neg_dy = pt.tensor(self.neg_dy_mm[atoms], dtype=pt.float32) | ||
q = pt.tensor(self.q_mm[idx], dtype=pt.long) | ||
pq = pt.tensor(self.pq_mm[atoms], dtype=pt.float32) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,8 +127,9 @@ def step(self, batch, loss_fn, stage): | |
if batch.y.ndim == 1: | ||
batch.y = batch.y.unsqueeze(1) | ||
|
||
# y loss | ||
loss_y = loss_fn(y, batch.y) | ||
# y | ||
y_dtype = {16: torch.float16, 32: torch.float32, 64: torch.float64}[self.hparams.precision] | ||
loss_y = loss_fn(y, batch.y.to(y_dtype)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How come you need this here but not a few lines above for neg_dy? |
||
|
||
if stage in ["train", "val"] and self.hparams.ema_alpha_y < 1: | ||
if self.ema[stage + "_y"] is None: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ def get_args(): | |
parser.add_argument('--ema-alpha-neg-dy', type=float, default=1.0, help='The amount of influence of new losses on the exponential moving average of dy') | ||
parser.add_argument('--ngpus', type=int, default=-1, help='Number of GPUs, -1 use all available. Use CUDA_VISIBLE_DEVICES=1, to decide gpus') | ||
parser.add_argument('--num-nodes', type=int, default=1, help='Number of nodes') | ||
parser.add_argument('--precision', type=int, default=32, choices=[16, 32], help='Floating point precision') | ||
parser.add_argument('--precision', type=int, default=32, choices=[16, 32, 64], help='Floating point precision') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh wow I totally missed this argument when I implemented #182 |
||
parser.add_argument('--log-dir', '-l', default='/tmp/logs', help='log file') | ||
parser.add_argument('--splits', default=None, help='Npz with splits idx_train, idx_val, idx_test') | ||
parser.add_argument('--train-size', type=number, default=None, help='Percentage/number of samples in training set (None to use all remaining samples)') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This got mixed from #206, right?