OCPCalculator ASE

Dear OCP team,

When I try to use one of the pretrained models from this list

(i.e. DimeNet+±Large S2EF)

I get the following error

KeyError Traceback (most recent call last)
Cell In [7], line 1
----> 1 calc = OCPCalculator(config_yml=config_yml_path, checkpoint=checkpoint_path)

File ~/Documents/ocp/ocpmodels/common/relaxation/ase_utils.py:137, in OCPCalculator.init(self, config_yml, checkpoint, trainer, cutoff, max_neighbors, device)
132 logging.warning(
133 “Unable to identify OCP trainer, defaulting to forces. Specify the trainer argument into OCPCalculator if otherwise.”
134 )
135 config[“trainer”] = “forces”
→ 137 config[“model_attributes”][“name”] = config.pop(“model”)
138 config[“model”] = config[“model_attributes”]
140 # Calculate the edge indices on the fly

KeyError: ‘model_attributes’

Because config that is presented there (on website) alongside checkpoint simply doesn’t have any “model_attributes” in itself.

Best,
Ivan

Hi Ivan,

Thanks for pointing this out. We should have a fix for this soon, it’s an issue caused with the config_yml definition. For the time being, if you’re using this for inference, you can use the calculator without config_yml and it should work fine. (calc = OCPCalculator(checkpoint=checkpoint_path))

I’ll update you once the original issue is also resolved.

Hello,

You tried this, and it worked? If so, could you please tell me with which model?

I am asking because I tried that too, but for different models it gives me different errors. (i.e. for the aforementioned Dimenet)


AssertionError Traceback (most recent call last)
Cell In [8], line 1
----> 1 calc = OCPCalculator(config_yml= None,checkpoint=checkpoint_path, trainer=‘forces’)

File ~/Documents/ocp/ocpmodels/common/relaxation/ase_utils.py:151, in OCPCalculator.init(self, config_yml, checkpoint, trainer, cutoff, max_neighbors, device)
148 del config[“dataset”][“src”]
149 config[“normalizer”] = config[“dataset”]
→ 151 self.trainer = registry.get_trainer_class(
152 config.get(“trainer”, “energy”)
153 )(
154 task=config[“task”],
155 model=config[“model”],
156 dataset=None,
157 normalizer=config[“normalizer”],
158 optimizer=config[“optim”],
159 identifier=“”,
160 slurm=config.get(“slurm”, {}),
161 local_rank=config.get(“local_rank”, device),
162 is_debug=config.get(“is_debug”, True),
163 cpu=True if device == “cpu” else False,
164 )
166 if checkpoint is not None:
167 self.load_checkpoint(checkpoint)

File ~/Documents/ocp/ocpmodels/trainers/forces_trainer.py:88, in ForcesTrainer.init(self, task, model, dataset, optimizer, identifier, normalizer, timestamp_id, run_dir, is_debug, is_hpo, print_every, seed, logger, local_rank, amp, cpu, slurm, noddp)
67 def init(
68 self,
69 task,
(…)
86 noddp=False,
87 ):
—> 88 super().init(
89 task=task,
90 model=model,
91 dataset=dataset,
92 optimizer=optimizer,
93 identifier=identifier,
94 normalizer=normalizer,
95 timestamp_id=timestamp_id,
96 run_dir=run_dir,
97 is_debug=is_debug,
98 is_hpo=is_hpo,
99 print_every=print_every,
100 seed=seed,
101 logger=logger,
102 local_rank=local_rank,
103 amp=amp,
104 cpu=cpu,
105 name=“s2ef”,
106 slurm=slurm,
107 noddp=noddp,
108 )

File ~/Documents/ocp/ocpmodels/trainers/base_trainer.py:205, in BaseTrainer.init(self, task, model, dataset, optimizer, identifier, normalizer, timestamp_id, run_dir, is_debug, is_hpo, print_every, seed, logger, local_rank, amp, cpu, name, slurm, noddp)
203 if distutils.is_master():
204 print(yaml.dump(self.config, default_flow_style=False))
→ 205 self.load()
207 self.evaluator = Evaluator(task=name)

File ~/Documents/ocp/ocpmodels/trainers/base_trainer.py:213, in BaseTrainer.load(self)
211 self.load_logger()
212 self.load_datasets()
→ 213 self.load_task()
214 self.load_model()
215 self.load_loss()

File ~/Documents/ocp/ocpmodels/trainers/forces_trainer.py:114, in ForcesTrainer.load_task(self)
111 logging.info(f"Loading dataset: {self.config[‘task’][‘dataset’]}")
113 if “relax_dataset” in self.config[“task”]:
→ 114 self.relax_dataset = registry.get_dataset_class(“lmdb”)(
115 self.config[“task”][“relax_dataset”]
116 )
117 self.relax_sampler = self.get_sampler(
118 self.relax_dataset,
119 self.config[“optim”].get(
(…)
122 shuffle=False,
123 )
124 self.relax_loader = self.get_dataloader(
125 self.relax_dataset,
126 self.relax_sampler,
127 )

File ~/Documents/ocp/ocpmodels/datasets/lmdb_dataset.py:50, in LmdbDataset.init(self, config, transform)
48 if not self.path.is_file():
49 db_paths = sorted(self.path.glob(“*.lmdb”))
—> 50 assert len(db_paths) > 0, f"No LMDBs found in ‘{self.path}’"
52 self.metadata_path = self.path / “metadata.npz”
54 self._keys, self.envs = ,

AssertionError: No LMDBs found in ‘/checkpoint/electrocatalysis/relaxations/features/init_to_relaxed/all/val_is/data.lmdb’

and for SchNet ( S2EF models: optimized for force only again)


Exception Traceback (most recent call last)
Cell In [5], line 1
----> 1 calc_sch = OCPCalculator(checkpoint=path_sch)

File ~/Documents/ocp/ocpmodels/common/relaxation/ase_utils.py:151, in OCPCalculator.init(self, config_yml, checkpoint, trainer, cutoff, max_neighbors, device)
148 del config[“dataset”][“src”]
149 config[“normalizer”] = config[“dataset”]
→ 151 self.trainer = registry.get_trainer_class(
152 config.get(“trainer”, “energy”)
153 )(
154 task=config[“task”],
155 model=config[“model”],
156 dataset=None,
157 normalizer=config[“normalizer”],
158 optimizer=config[“optim”],
159 identifier=“”,
160 slurm=config.get(“slurm”, {}),
161 local_rank=config.get(“local_rank”, device),
162 is_debug=config.get(“is_debug”, True),
163 cpu=True if device == “cpu” else False,
164 )
166 if checkpoint is not None:
167 self.load_checkpoint(checkpoint)

File ~/Documents/ocp/ocpmodels/trainers/forces_trainer.py:88, in ForcesTrainer.init(self, task, model, dataset, optimizer, identifier, normalizer, timestamp_id, run_dir, is_debug, is_hpo, print_every, seed, logger, local_rank, amp, cpu, slurm, noddp)
67 def init(
68 self,
69 task,
(…)
86 noddp=False,
87 ):
—> 88 super().init(
89 task=task,
90 model=model,
91 dataset=dataset,
92 optimizer=optimizer,
93 identifier=identifier,
94 normalizer=normalizer,
95 timestamp_id=timestamp_id,
96 run_dir=run_dir,
97 is_debug=is_debug,
98 is_hpo=is_hpo,
99 print_every=print_every,
100 seed=seed,
101 logger=logger,
102 local_rank=local_rank,
103 amp=amp,
104 cpu=cpu,
105 name=“s2ef”,
106 slurm=slurm,
107 noddp=noddp,
108 )

File ~/Documents/ocp/ocpmodels/trainers/base_trainer.py:205, in BaseTrainer.init(self, task, model, dataset, optimizer, identifier, normalizer, timestamp_id, run_dir, is_debug, is_hpo, print_every, seed, logger, local_rank, amp, cpu, name, slurm, noddp)
203 if distutils.is_master():
204 print(yaml.dump(self.config, default_flow_style=False))
→ 205 self.load()
207 self.evaluator = Evaluator(task=name)

File ~/Documents/ocp/ocpmodels/trainers/base_trainer.py:217, in BaseTrainer.load(self)
215 self.load_loss()
216 self.load_optimizer()
→ 217 self.load_extras()

File ~/Documents/ocp/ocpmodels/trainers/base_trainer.py:521, in BaseTrainer.load_extras(self)
520 def load_extras(self):
→ 521 self.scheduler = LRScheduler(self.optimizer, self.config[“optim”])
522 self.clip_grad_norm = self.config[“optim”].get(“clip_grad_norm”)
523 self.ema_decay = self.config[“optim”].get(“ema_decay”)

File ~/Documents/ocp/ocpmodels/modules/scheduler.py:36, in LRScheduler.init(self, optimizer, config)
34 self.scheduler = getattr(lr_scheduler, self.scheduler_type)
35 scheduler_args = self.filter_kwargs(config)
—> 36 self.scheduler = self.scheduler(optimizer, **scheduler_args)

File ~/anaconda3/envs/ocp-models_official/lib/python3.9/site-packages/torch/optim/lr_scheduler.py:203, in LambdaLR.init(self, optimizer, lr_lambda, last_epoch, verbose)
200 raise ValueError(“Expected {} lr_lambdas, but got {}”.format(
201 len(optimizer.param_groups), len(lr_lambda)))
202 self.lr_lambdas = list(lr_lambda)
→ 203 super(LambdaLR, self).init(optimizer, last_epoch, verbose)

File ~/anaconda3/envs/ocp-models_official/lib/python3.9/site-packages/torch/optim/lr_scheduler.py:77, in _LRScheduler.init(self, optimizer, last_epoch, verbose)
74 self._step_count = 0
75 self.verbose = verbose
—> 77 self.step()

File ~/anaconda3/envs/ocp-models_official/lib/python3.9/site-packages/torch/optim/lr_scheduler.py:152, in _LRScheduler.step(self, epoch)
150 if epoch is None:
151 self.last_epoch += 1
→ 152 values = self.get_lr()
153 else:
154 warnings.warn(EPOCH_DEPRECATION_WARNING, UserWarning)

File ~/anaconda3/envs/ocp-models_official/lib/python3.9/site-packages/torch/optim/lr_scheduler.py:250, in LambdaLR.get_lr(self)
246 if not self._get_lr_called_within_step:
247 warnings.warn("To get the last learning rate computed by the scheduler, "
248 “please use get_last_lr().”)
→ 250 return [base_lr * lmbda(self.last_epoch)
251 for lmbda, base_lr in zip(self.lr_lambdas, self.base_lrs)]

File ~/anaconda3/envs/ocp-models_official/lib/python3.9/site-packages/torch/optim/lr_scheduler.py:250, in (.0)
246 if not self._get_lr_called_within_step:
247 warnings.warn("To get the last learning rate computed by the scheduler, "
248 “please use get_last_lr().”)
→ 250 return [base_lr * lmbda(self.last_epoch)
251 for lmbda, base_lr in zip(self.lr_lambdas, self.base_lrs)]

File ~/Documents/ocp/ocpmodels/modules/scheduler.py:30, in LRScheduler.init..(x)
28 else:
29 self.scheduler_type = “LambdaLR”
—> 30 scheduler_lambda_fn = lambda x: warmup_lr_lambda(x, self.config)
31 self.config[“lr_lambda”] = scheduler_lambda_fn
33 if self.scheduler_type != “Null”:

File ~/Documents/ocp/ocpmodels/common/utils.py:101, in warmup_lr_lambda(current_step, optim_config)
95 # keep this block for older configs that have warmup_epochs instead of warmup_steps
96 # and lr_milestones are defined in epochs
97 if (
98 any(x < 100 for x in optim_config[“lr_milestones”])
99 or “warmup_epochs” in optim_config
100 ):
→ 101 raise Exception(
102 “ConfigError: please define lr_milestones in steps not epochs and define warmup_steps instead of warmup_epochs”
103 )
105 if current_step <= optim_config[“warmup_steps”]:
106 alpha = current_step / float(optim_config[“warmup_steps”])

Exception: ConfigError: please define lr_milestones in steps not epochs and define warmup_steps instead of warmup_epochs

Also, just wanted to say I really appreciate quickness of the response :slight_smile:

Best,
Ivan

Ah I see. So for some of the older models (Exception: ConfigError: please define lr_milestones in steps not epochs and define warmup_steps instead of warmup_epochs) it will be necessary to specify the config_yml (working on that fix shortly).

I’ve tried it for the newer/best performing models - GemNet-OC: checkpoint. If you want to try that while I look into the older models.

As an update - OCPCalc edge cases by mshuaibii · Pull Request #417 · Open-Catalyst-Project/ocp · GitHub.

We have resolved these edge cases. Please let me know if you run into any other issues. Sorry about that!