deepmodeling / deepmodeling/Uni-Mol
[BUG] AttributeError: 'Trainer' object has no attribute 'scaler'
- Dominant language
- Python
- Stars
- 1.2k
- Forks
- 181
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the bug
When I run the code below, I get an exception`AttributeError: 'Trainer' object has no attribute 'scaler'`. The stack trace is shown below the code.
```python
from unimol_tools import MolTrain
import pandas as pd
from sklearn.model_selection import train_test_split
def main():
df = pd.read_csv("https://raw.githubusercontent.com/PatWalters/practical_cheminformatics_posts/refs/heads/main/splitting/biogen_logS.csv")
epochs = 100
kfold = 5
learning_rate=1e-4
batch_size=8
save_dir_each_fold = "."
clf = MolTrain(
task='regression',
data_type='molecule',
device='cpu',
epochs=epochs, #100,
learning_rate=learning_rate, #1e-4,
kfold=kfold, # inner CV
early_stopping=5,
batch_size=batch_size,
metrics='mse',
#freeze_layers=['encoder', 'gbf'],
remove_hs=True,
use_cuda=False,
save_path=save_dir_each_fold)
df.rename(columns={"logS" : "target"},inplace=True)
train_df, test_df = train_test_split(df)
train_dict = train_df.to_dict(orient="list")
clf.fit(data=train_dict)
if __name__ == "__main__":
main()
```
```shell
Traceback (most recent call last):
File "/home/ubuntu/DATA/UNIMOL/./test_unimol.py", line 41, in
main()
File "/home/ubuntu/DATA/UNIMOL/./test_unimol.py", line 37, in main
clf.fit(data=train_dict)
File "/home/ubuntu/DATA/UNIMOL/unimol/lib/python3.11/site-packages/unimol_tools/train.py", line 184, in fit
self.model.run()
File "/home/ubuntu/DATA/UNIMOL/unimol/lib/python3.11/site-packages/unimol_tools/models/nnmodel.py", line 224, in run
_y_pred = self.trainer.fit_predict(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ubuntu/DATA/UNIMOL/unimol/lib/python3.11/site-packages/unimol_tools/tasks/trainer.py", line 210, in fit_predict
return self.fit_predict_wo_ddp(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ubuntu/DATA/UNIMOL/unimol/lib/python3.11/site-packages/unimol_tools/tasks/trainer.py", line 267, in fit_predict_wo_ddp
total_trn_loss = self._train_one_epoch(
^^^^^^^^^^^^^^^^^^^^^^
File "/home/ubuntu/DATA/UNIMOL/unimol/lib/python3.11/site-packages/unimol_tools/tasks/trainer.py", line 457, in _train_one_epoch
loss = self._compute_loss(model, net_input, net_target, loss_func)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ubuntu/DATA/UNIMOL/unimol/lib/python3.11/site-packages/unimol_tools/tasks/trainer.py", line 471, in _compute_loss
if self.scaler and self.device.type == 'cuda':
^^^^^^^^^^^
AttributeError: 'Trainer' object has no attribute 'scaler'
```
### Uni-Mol Version
unimol-tools==0.1.3.post1
### Expected behavior
Run successfully without throwing an exception
### To Reproduce
See code above
### Environment
Ubuntu 22.04
### Additional Context
_No response_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.