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

fix llava model device bugs #359

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions internlm/model/modeling_llava.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from internlm.model.modules.linear import new_linear
from internlm.model.modules.norm import new_layer_norm
from internlm.utils.logger import get_logger
from internlm.utils.common import get_current_device

logger = get_logger(__file__)

Expand Down Expand Up @@ -192,7 +193,7 @@ def forward(self, hidden_states=None, images=None, input_ids=None, **kwargs):
if hasattr(self, "vit") and hasattr(self, "vision_proj") and hasattr(self, "tok_embeddings"):
# vit
if len(images) == 1 and len(images[0]) == 0: # make sure grad in Qformer for update
images = [torch.rand(1, 3, self.vit.image_size, self.vit.image_size).cuda().to(self.dtype)]
images = [torch.rand(1, 3, self.vit.image_size, self.vit.image_size).to(self.device).to(self.dtype)]
pure_text = True

for image in images:
Expand All @@ -201,7 +202,7 @@ def forward(self, hidden_states=None, images=None, input_ids=None, **kwargs):
x = []
else:
assert not isinstance(image, list), image
x = image.to(torch.cuda.current_device()).to(self.dtype)
x = image.to(get_current_device()).to(self.dtype)
x = self.vit(x)
x = self.vision_proj(x)
xs.append(x)
Expand Down
Loading