nomic-ai / contrastors

Train Models Contrastively in Pytorch
Apache License 2.0
459 stars 35 forks source link

Error in the `_grad_cache_forward_step` function when running suggested contrastive pretraining command #9

Closed kuanhsieh closed 4 months ago

kuanhsieh commented 4 months ago

Hi, thank you very much for releasing the code and data for training text embedding models.

I followed the steps in README.md and ran the following suggested command for the contrastive pretraining step:

cd src/contrastors
torchrun --nproc-per-node=8 train.py --config=configs/train/contrastive_pretrain.yaml --dtype=bf16

However, I get the following error

File ".../contrastors/src/contrastors/trainers/clip.py", line 163, in _grad_cache_forward_step
    chunk_size=self.config.chunk_size,                                       
AttributeError: 'Config' object has no attribute 'chunk_size'   

the source of it is: https://github.com/nomic-ai/contrastors/blob/70f7baf0dff4e0019776e8c98257a3ad3fa4d687/src/contrastors/trainers/clip.py#L151-L167

My guess is that one should change chunk_size=self.config.chunk_size to chunk_size=self.config.train_args.chunk_size.

However, after changing that I get another error in the same _grad_cache_forward_step function:

File ".../contrastors/src/contrastors/trainers/clip.py", line 158, in _grad_cache_forward_step                             
    loss = grad_cache_loss(                                                                                                                                            
TypeError: grad_cache_loss() got an unexpected keyword argument 'step'   

which I'm guessing comes from running the forward_step function with step as an argument.

I see that the comment in the _grad_cache_forward_step function says that this function is not used? So is it that some code changes have not been pushed?

Many thanks, Kuan

zanussbaum commented 4 months ago

Sorry! I pushed some bad code. It should work now after being fixed in #10 Let me know if it doesn't still fix your issue