LLaVA-VL / LLaVA-NeXT

Apache License 2.0
2.96k stars 253 forks source link

self.image_newline inside the forward pass question #321

Open YerongLi opened 1 month ago

YerongLi commented 1 month ago

I'm currently working with the code and I'm having some trouble OVERRIDE forward where the self.module.image_newline attribute is set or initialized in the model.

I've traced the model through the forward pass, but I'm unable to find any explicit assignment to self.module.image_newline. Could you clarify where this attribute is being initialized or set?

Before the forward pass self.module.image_newline is empty

Parameter containing:
tensor([], device='cuda:0', dtype=torch.bfloat16)

Inside the forward pass it is a constant which is not empty

Parameter containing:
tensor([ 0.0123,  0.0142, -0.0299,  ..., -0.0332, -0.0041,  0.0240],
       device='cuda:0', dtype=torch.bfloat16)

Could anyone get me hint where self.image_newline is set?

Specifically, I am referring to this section of the code:https://github.com/huggingface/transformers/blob/f0e640adfa3cedea53912b95e3093f05cc2b66b5/src/transformers/models/llava_onevision/modeling_llava_onevision.py#L677

  image_features, feature_lens = self.pack_image_features(
      image_features,
      image_sizes,
      image_newline=self.image_newline,
      vision_aspect_ratio=vision_aspect_ratio,
  )
YerongLi commented 1 month ago

In torch module, image_newline is editted with a pre_forward_hook

torch/nn/modules/module.py