atomistic-machine-learning / schnetpack

SchNetPack - Deep Neural Networks for Atomistic Systems
Other
791 stars 215 forks source link

Question on config file #591

Closed nitbha007 closed 11 months ago

nitbha007 commented 11 months ago

Hello,

I would like to use the "qm9_dipole.yaml" config file for just predicting the dipole moment for my dataset. Could you please tell me, what modifications do I need to make in the config file?

I modified the config file as shown and specify the path to dataset, but it throws an error.

# @package _global_

defaults:
  - override /model: nnp
  - override /data: custom

run:
  experiment: ${globals.property}

globals:
  cutoff: 5.
  lr: 5e-4
  property: dipole_moment
jnsLs commented 11 months ago

Hello @nitbha007 ,

could you please provide your error message?

Best regards, Jonas

nitbha007 commented 11 months ago

Hello, Here's the error message:

Traceback (most recent call last):
  File "/scratch/phys/t30424-euspeclab/SchnetPack/conda_env_spk/schnetpack/src/schnetpack/cli.py", line 158, in train
    trainer.fit(model=task, datamodule=datamodule, ckpt_path=config.run.ckpt_path)
  File "/home/bhatian1/.local/lib/python3.9/site-packages/pytorch_lightning/trainer/trainer.py", line 529, in fit
    call._call_and_handle_interrupt(
  File "/home/bhatian1/.local/lib/python3.9/site-packages/pytorch_lightning/trainer/call.py", line 42, in _call_and_handle_interrupt
    return trainer_fn(*args, **kwargs)
  File "/home/bhatian1/.local/lib/python3.9/site-packages/pytorch_lightning/trainer/trainer.py", line 568, in _fit_impl
    self._run(model, ckpt_path=ckpt_path)
  File "/home/bhatian1/.local/lib/python3.9/site-packages/pytorch_lightning/trainer/trainer.py", line 973, in _run
    results = self._run_stage()
  File "/home/bhatian1/.local/lib/python3.9/site-packages/pytorch_lightning/trainer/trainer.py", line 1016, in _run_stage
    self.fit_loop.run()
  File "/home/bhatian1/.local/lib/python3.9/site-packages/pytorch_lightning/loops/fit_loop.py", line 201, in run
    self.advance()
  File "/home/bhatian1/.local/lib/python3.9/site-packages/pytorch_lightning/loops/fit_loop.py", line 354, in advance
    self.epoch_loop.run(self._data_fetcher)
  File "/home/bhatian1/.local/lib/python3.9/site-packages/pytorch_lightning/loops/training_epoch_loop.py", line 133, in run
    self.advance(data_fetcher)
  File "/home/bhatian1/.local/lib/python3.9/site-packages/pytorch_lightning/loops/training_epoch_loop.py", line 218, in advance
    batch_output = self.automatic_optimization.run(trainer.optimizers[0], kwargs)
  File "/home/bhatian1/.local/lib/python3.9/site-packages/pytorch_lightning/loops/optimization/automatic.py", line 185, in run
    self._optimizer_step(kwargs.get("batch_idx", 0), closure)
  File "/home/bhatian1/.local/lib/python3.9/site-packages/pytorch_lightning/loops/optimization/automatic.py", line 260, in _optimizer_step
    call._call_lightning_module_hook(
  File "/home/bhatian1/.local/lib/python3.9/site-packages/pytorch_lightning/trainer/call.py", line 144, in _call_lightning_module_hook
    output = fn(*args, **kwargs)
  File "/scratch/phys/t30424-euspeclab/SchnetPack/conda_env_spk/schnetpack/src/schnetpack/task.py", line 279, in optimizer_step
    optimizer.step(closure=optimizer_closure)
  File "/home/bhatian1/.local/lib/python3.9/site-packages/pytorch_lightning/core/optimizer.py", line 155, in step
    step_output = self._strategy.optimizer_step(self._optimizer, closure, **kwargs)
  File "/home/bhatian1/.local/lib/python3.9/site-packages/pytorch_lightning/strategies/strategy.py", line 225, in optimizer_step
    return self.precision_plugin.optimizer_step(optimizer, model=model, closure=closure, **kwargs)
  File "/home/bhatian1/.local/lib/python3.9/site-packages/pytorch_lightning/plugins/precision/precision_plugin.py", line 114, in optimizer_step
    return optimizer.step(closure=closure, **kwargs)
  File "/scratch/phys/t30424-euspeclab/SchnetPack/conda_env_spk/spk/lib/python3.9/site-packages/torch/optim/optimizer.py", line 280, in wrapper
    out = func(*args, **kwargs)
  File "/scratch/phys/t30424-euspeclab/SchnetPack/conda_env_spk/spk/lib/python3.9/site-packages/torch/optim/optimizer.py", line 33, in _use_grad
    ret = func(self, *args, **kwargs)
  File "/scratch/phys/t30424-euspeclab/SchnetPack/conda_env_spk/spk/lib/python3.9/site-packages/torch/optim/adamw.py", line 148, in step
    loss = closure()
  File "/home/bhatian1/.local/lib/python3.9/site-packages/pytorch_lightning/plugins/precision/precision_plugin.py", line 101, in _wrap_closure
    closure_result = closure()
  File "/home/bhatian1/.local/lib/python3.9/site-packages/pytorch_lightning/loops/optimization/automatic.py", line 140, in __call__
    self._result = self.closure(*args, **kwargs)
  File "/home/bhatian1/.local/lib/python3.9/site-packages/pytorch_lightning/loops/optimization/automatic.py", line 126, in closure
    step_output = self._step_fn()
  File "/home/bhatian1/.local/lib/python3.9/site-packages/pytorch_lightning/loops/optimization/automatic.py", line 307, in _training_step
    training_step_output = call._call_strategy_hook(trainer, "training_step", *kwargs.values())
  File "/home/bhatian1/.local/lib/python3.9/site-packages/pytorch_lightning/trainer/call.py", line 291, in _call_strategy_hook
    output = fn(*args, **kwargs)
  File "/home/bhatian1/.local/lib/python3.9/site-packages/pytorch_lightning/strategies/strategy.py", line 367, in training_step
    return self.model.training_step(*args, **kwargs)
  File "/scratch/phys/t30424-euspeclab/SchnetPack/conda_env_spk/schnetpack/src/schnetpack/task.py", line 181, in training_step
    loss = self.loss_fn(pred, targets)
  File "/scratch/phys/t30424-euspeclab/SchnetPack/conda_env_spk/schnetpack/src/schnetpack/task.py", line 145, in loss_fn
    loss += output.calculate_loss(pred, batch)
  File "/scratch/phys/t30424-euspeclab/SchnetPack/conda_env_spk/schnetpack/src/schnetpack/task.py", line 63, in calculate_loss
    loss = self.loss_weight * self.loss_fn(
  File "/scratch/phys/t30424-euspeclab/SchnetPack/conda_env_spk/spk/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/scratch/phys/t30424-euspeclab/SchnetPack/conda_env_spk/spk/lib/python3.9/site-packages/torch/nn/modules/loss.py", line 536, in forward
    return F.mse_loss(input, target, reduction=self.reduction)
  File "/scratch/phys/t30424-euspeclab/SchnetPack/conda_env_spk/spk/lib/python3.9/site-packages/torch/nn/functional.py", line 3294, in mse_loss
    expanded_input, expanded_target = torch.broadcast_tensors(input, target)
  File "/scratch/phys/t30424-euspeclab/SchnetPack/conda_env_spk/spk/lib/python3.9/site-packages/torch/functional.py", line 74, in broadcast_tensors
    return _VF.broadcast_tensors(tensors)  # type: ignore[attr-defined]
RuntimeError: The size of tensor a (10) must match the size of tensor b (3) at non-singleton dimension 1

Note: "dipole_moment":{"ndarray":[[1,3],"float64",232]}}. The response config works well with the same data.

stefaanhessmann commented 11 months ago

Hi @nitbha007 ,

I am not sure what you are exactly trying to do. From my understanding you want to train a dipole moment model on your own dataset. Is the config file you provided the full config file, or just the first part? If this is your full config file, you should also include the sections about model, data and task. However if you also add these section to you config file, you will need to set predict_magnitude=False, because you have dipole moment vectors. The example script only predicts the magnitude of the dipole moments, since this is what QM9 has provided.

Let me know if this works!

Best, Stefaan

nitbha007 commented 11 months ago

Hello, I had the full config file. Adding the predict_magnitude=False has worked for me.

Thank you.