[GH-ISSUE #65] self.hd_alpha_downsamples = nn.Parameter(torch.zeros(1)) #50

Open
opened 2026-10-26 21:09:08 +00:00 by bsakaguchi · 1 comment
Owner

Originally created by @MicroPhion on GitHub (Jan 31, 2025).
Original GitHub issue: https://github.com/deepseek-ai/DeepSeek-VL/issues/65

def forward(self, x: torch.Tensor) -> torch.Tensor:
    x = self.patch_embed(x) # [2, 3, 1024, 1024] -> [2, 64, 64, 768]
    if self.pos_embed is not None:
        x = x + self.pos_embed

    global_features = []
    for i, blk in enumerate(self.blocks):
        x = blk(x) # [2, 64, 64, 768] -> [2, 64, 64, 768]
        if self.sam_hd and blk.window_size == 0: # "global_attn_indexes": [2, 5, 8, 11]
            global_features.append(x)

    x = self.neck(x.permute(0, 3, 1, 2)) # [2, 64, 64, 768]->[2, 256, 64, 64]
    x_dtype = x.dtype
    x = F.interpolate(
        x.float(), size=(96, 96), mode="bilinear", align_corners=False
    ).to(x_dtype) # [2, 64, 64, 768]->[2, 256, 96, 96]
    x = self.downsamples(x) # [2, 256, 96, 96]->[2, 1024, 24, 24]

    if self.sam_hd:
        first_global_feature = self.neck_hd(global_features[0].permute(0, 3, 1, 2)) # [2, 64, 64, 768]->[2, 256, 64, 64]
        x_dtype = first_global_feature.dtype
        first_global_feature = F.interpolate(
            first_global_feature.float(),
            size=(96, 96),
            mode="bilinear",
            align_corners=False,
        ) # [2, 256, 64, 64] -> [2, 256, 96, 96]
        first_global_feature = self.downsamples(first_global_feature.to(x_dtype)) # [2, 256, 96, 96] -> [2, 1024, 24, 24]
        x = x + first_global_feature * self.hd_alpha_downsamples #这里self.hd_alpha_downsamples = 0,也就是first_global_feature的计算没有意义

上面的代码是sam.py文件中的一段,看上面的代码,这里设置self.hd_alpha_downsamples一直为0,计算first_global_feature的作用是什么,这里其实不是一直都是0,在外部会对这个变量进行修改。

Originally created by @MicroPhion on GitHub (Jan 31, 2025). Original GitHub issue: https://github.com/deepseek-ai/DeepSeek-VL/issues/65 def forward(self, x: torch.Tensor) -> torch.Tensor: x = self.patch_embed(x) # [2, 3, 1024, 1024] -> [2, 64, 64, 768] if self.pos_embed is not None: x = x + self.pos_embed global_features = [] for i, blk in enumerate(self.blocks): x = blk(x) # [2, 64, 64, 768] -> [2, 64, 64, 768] if self.sam_hd and blk.window_size == 0: # "global_attn_indexes": [2, 5, 8, 11] global_features.append(x) x = self.neck(x.permute(0, 3, 1, 2)) # [2, 64, 64, 768]->[2, 256, 64, 64] x_dtype = x.dtype x = F.interpolate( x.float(), size=(96, 96), mode="bilinear", align_corners=False ).to(x_dtype) # [2, 64, 64, 768]->[2, 256, 96, 96] x = self.downsamples(x) # [2, 256, 96, 96]->[2, 1024, 24, 24] if self.sam_hd: first_global_feature = self.neck_hd(global_features[0].permute(0, 3, 1, 2)) # [2, 64, 64, 768]->[2, 256, 64, 64] x_dtype = first_global_feature.dtype first_global_feature = F.interpolate( first_global_feature.float(), size=(96, 96), mode="bilinear", align_corners=False, ) # [2, 256, 64, 64] -> [2, 256, 96, 96] first_global_feature = self.downsamples(first_global_feature.to(x_dtype)) # [2, 256, 96, 96] -> [2, 1024, 24, 24] x = x + first_global_feature * self.hd_alpha_downsamples #这里self.hd_alpha_downsamples = 0,也就是first_global_feature的计算没有意义 上面的代码是sam.py文件中的一段,看上面的代码,这里设置self.hd_alpha_downsamples一直为0,计算first_global_feature的作用是什么,这里其实不是一直都是0,在外部会对这个变量进行修改。
Author
Owner

@MicroPhion commented on GitHub (Jan 31, 2025):

具体外面在什么情况下会修改这个变量。

<!-- gh-comment-id:2626515550 --> @MicroPhion commented on GitHub (Jan 31, 2025): 具体外面在什么情况下会修改这个变量。
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
deepseek-ai/DeepSeek-VL#50
No description provided.