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

[BUG] When using LLaVA with freeze-LM, training text only sample occurs error. #1314

Open
liveseongho opened this issue Dec 6, 2024 · 0 comments

Comments

@liveseongho
Copy link

Describe the bug
When using LLaVA with freeze-LM, training text only sample occurs error.

To Reproduce
Base code use VQASample for training LLaVA. But, if you use TextSample or samples with text only, it will occur following error.

Stack trace/logs

  File "/workspace/megatron/core/pipeline_parallel/schedules.py", line 365, in backward_step
    custom_backward(output_tensor[0], output_tensor_grad[0])
  File "/workspace/megatron/core/pipeline_parallel/schedules.py", line 149, in custom_backward
    Variable._execution_engine.run_backward(
RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn

Expected behavior
I think output_tensor[0] always has grad_fn, but it doesn't have grad_fn if any of sample uses parameters with grad.

Environment (please complete the following information):

Proposed fix
Fix following code

if config.deallocate_pipeline_outputs:
custom_backward(output_tensor[0], output_tensor_grad[0])
else:
torch.autograd.backward(output_tensor[0], grad_tensors=output_tensor_grad[0])

as follows

    if output_tensor[0].requires_grad:
        if config.deallocate_pipeline_outputs:
            custom_backward(output_tensor[0], output_tensor_grad[0])
        else:
            torch.autograd.backward(output_tensor[0], grad_tensors=output_tensor_grad[0])

Additional context
@trintamaki could you help to fix this issue?

@liveseongho liveseongho changed the title [BUG] When training LLaVA with freeze-LM, text only sample occurs error. [BUG] When using LLaVA with freeze-LM, training text only sample occurs error. Dec 6, 2024
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