Skip to content
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

Dtype Issues on Inference #22

Open
nrocketmann opened this issue Sep 18, 2023 · 0 comments
Open

Dtype Issues on Inference #22

nrocketmann opened this issue Sep 18, 2023 · 0 comments

Comments

@nrocketmann
Copy link

Hello,
First off, thanks for making this repo as well as all the other awesome work you do making high quality, open source implementations of SOTA ML papers!

I've been having issues getting ConditionalFlowMatcherWrapper.sample to work. For training, I wrapped the ConditionalFlowMatcherWrapper in a simple torch lightning module, and train the model in mixed precision FP16 like so:

trainer = pl.Trainer(accelerator="gpu", devices=[0], max_steps=100, precision=16, enable_progress_bar=True)

trainer.fit(model=model, train_dataloaders=dataloader)

I'm using torch 2.0 and A100 GPUs, so attend.py defaults to Flash Attention, which only works with FP16 AFAIK. Training works fine as long as I include the precision=16 part, so no issues here.

However, when I try to load the model, I call .to('cuda:0').half() on both it and the input batch, I get the error:
expected scalar type Half but found Float
It seems to be originating from here. Going down the stack trace, it seems like in the Vector Quantizer, here, the inputs to the cdist call are fp32, even though everything further up the stack trace is fp16. Does this have to do with the @autocast here maybe? I'm not sure what I can do to get around this, since all of my inputs and the model are in fp16.

I also tried not calling half() on the model or data, but then attention.py throws a No kernel available error because it can't do flash attention with FP32. I tried making a slight modification at line 105 to avoid using flash:

        if self.flash and q.dtype==torch.float16:
            return self.flash_attn(q, k, v, mask = mask)

but then I get a cryptic error cuFFT error: CUFFT_INTERNAL_ERROR.

Any help would be greatly appreciated. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant