Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
class Qwen3VLTransformerLayerInfer(Qwen2VLTransformerLayerInfer):
def __init__(self, layer_num, network_config, mode=[]):
super().__init__(layer_num, network_config, mode)
self.head_dim_ = network_config["head_dim"]
self.mrope_section = torch.tensor(
network_config["rope_scaling"]["mrope_section"], dtype=torch.int32, device="cuda"
)
Comment on lines 28 to 30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The initialization of self.mrope_section is redundant as it's already handled by the superclass Qwen2VLTransformerLayerInfer's __init__ method, which is invoked via super().__init__() on line 26. Removing these lines will eliminate code duplication and improve maintainability.

Expand Down
4 changes: 2 additions & 2 deletions lightllm/models/vit/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def encode(self, images: List[ImageItem]):
else:
raise Exception("Unsupport input types: {} for {}".format(type(img), img))

cur_num = img_tensors[-1].shape[0]
cur_num = img.token_num
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve robustness, consider adding an assertion to verify that img.token_num is not None before it's used. This will help catch potential issues early if the value is not set as expected, preventing a TypeError during the summation and making the code's contract clearer.

Suggested change
cur_num = img.token_num
assert img.token_num is not None, "Image token number must be set before calling encode."
cur_num = img.token_num

valid_ids.append([valid_id, valid_id + cur_num])
valid_id += cur_num

Expand All @@ -195,7 +195,7 @@ def encode(self, images: List[ImageItem]):
imgs = torch.cat(img_tensors, dim=0)
pixel_values = imgs.cuda().to(dtype=self.data_type)
all_img_embeds = self.forward(pixel_values)
return all_img_embeds, uuids, valid_ids
return all_img_embeds.view(-1, all_img_embeds.shape[-1]), uuids, valid_ids

def cuda(self):
return self
Expand Down