Skip to content

Commit c32495b

Browse files
authored
Merge pull request #92 from gleize/fix-memory-leak
Fix memory leak.
2 parents f8ad695 + d53b7a2 commit c32495b

File tree

7 files changed

+14
-7
lines changed

7 files changed

+14
-7
lines changed

InternVideo1/Downstream/Video-Text-Retrieval/modules/clip_evl/evl_utils/clip_vit_fusion.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ def forward(self, x, mode='video', return_all_feats=False):
249249
_, tmp_feats = tmp_x[:1], tmp_x[1:]
250250
tmp_feats = tmp_feats.permute(1, 3, 2, 0).reshape(N, C, T_down, H, W)
251251
tmp_feats = self.dpe[j](tmp_feats).view(N, C, T_down, L - 1).permute(3, 0, 2, 1)
252-
tmp_x[1:] = tmp_x[1:] + tmp_feats
252+
# tmp_x[1:] = tmp_x[1:] + tmp_feats # memory leak
253+
tmp_x = torch.cat([tmp_x[:1], tmp_x[1:] + tmp_feats], dim=0) # no memory leak
253254
# enhancer
254255
tmp_x = tmp_x.permute(2, 0, 1, 3).flatten(0, 1) # T * L, N, C
255256
cls_token = self.dec[j](cls_token, tmp_x)

InternVideo1/Downstream/Video-Text-Retrieval/modules/clip_evl/evl_utils/clip_vit_only_global.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ def forward(self, x, mode='video', return_all_feats=False):
224224
_, tmp_feats = tmp_x[:1], tmp_x[1:]
225225
tmp_feats = tmp_feats.permute(1, 3, 2, 0).reshape(N, C, T_down, H, W)
226226
tmp_feats = self.dpe[j](tmp_feats).view(N, C, T_down, L - 1).permute(3, 0, 2, 1)
227-
tmp_x[1:] = tmp_x[1:] + tmp_feats
227+
# tmp_x[1:] = tmp_x[1:] + tmp_feats # memory leak
228+
tmp_x = torch.cat([tmp_x[:1], tmp_x[1:] + tmp_feats], dim=0) # no memory leak
228229
# enhancer
229230
tmp_x = tmp_x.permute(2, 0, 1, 3).flatten(0, 1) # T * L, N, C
230231
cls_token = self.dec[j](cls_token, tmp_x)

InternVideo1/Downstream/Video-Text-Retrieval/modules/clip_kc_new/evl_utils/clip_vit_fusion.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ def forward(self, x, mode='video', return_all_feats=False):
249249
_, tmp_feats = tmp_x[:1], tmp_x[1:]
250250
tmp_feats = tmp_feats.permute(1, 3, 2, 0).reshape(N, C, T_down, H, W)
251251
tmp_feats = self.dpe[j](tmp_feats).view(N, C, T_down, L - 1).permute(3, 0, 2, 1)
252-
tmp_x[1:] = tmp_x[1:] + tmp_feats
252+
# tmp_x[1:] = tmp_x[1:] + tmp_feats # memory leak
253+
tmp_x = torch.cat([tmp_x[:1], tmp_x[1:] + tmp_feats], dim=0) # no memory leak
253254
# enhancer
254255
tmp_x = tmp_x.permute(2, 0, 1, 3).flatten(0, 1) # T * L, N, C
255256
cls_token = self.dec[j](cls_token, tmp_x)

InternVideo1/Downstream/Video-Text-Retrieval/modules/clip_kc_new/evl_utils/clip_vit_only_global.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ def forward(self, x, mode='video', return_all_feats=False):
224224
_, tmp_feats = tmp_x[:1], tmp_x[1:]
225225
tmp_feats = tmp_feats.permute(1, 3, 2, 0).reshape(N, C, T_down, H, W)
226226
tmp_feats = self.dpe[j](tmp_feats).view(N, C, T_down, L - 1).permute(3, 0, 2, 1)
227-
tmp_x[1:] = tmp_x[1:] + tmp_feats
227+
# tmp_x[1:] = tmp_x[1:] + tmp_feats # memory leak
228+
tmp_x = torch.cat([tmp_x[:1], tmp_x[1:] + tmp_feats], dim=0) # no memory leak
228229
# enhancer
229230
tmp_x = tmp_x.permute(2, 0, 1, 3).flatten(0, 1) # T * L, N, C
230231
cls_token = self.dec[j](cls_token, tmp_x)

InternVideo1/Downstream/multi-modalities-downstream/CoTrain/modules/InternVideo/clip_utils/utils/clip_vit_only_global.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ def forward(self, x, mode='video', return_all_feats=False):
224224
_, tmp_feats = tmp_x[:1], tmp_x[1:].clone()
225225
tmp_feats = tmp_feats.permute(1, 3, 2, 0).reshape(N, C, T_down, H, W)
226226
tmp_feats = self.dpe[j](tmp_feats).view(N, C, T_down, L - 1).permute(3, 0, 2, 1)
227-
tmp_x[1:] = tmp_x[1:] + tmp_feats
227+
# tmp_x[1:] = tmp_x[1:] + tmp_feats # memory leak
228+
tmp_x = torch.cat([tmp_x[:1], tmp_x[1:] + tmp_feats], dim=0) # no memory leak
228229
# enhancer
229230
tmp_x = tmp_x.permute(2, 0, 1, 3).flatten(0, 1) # T * L, N, C
230231
cls_token = self.dec[j](cls_token, tmp_x)

InternVideo1/Pretrain/Multi-Modalities-Pretraining/InternVideo/clip_utils/utils/clip_vit_only_global.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ def forward(self, x, mode='video', return_all_feats=False):
224224
_, tmp_feats = tmp_x[:1], tmp_x[1:]
225225
tmp_feats = tmp_feats.permute(1, 3, 2, 0).reshape(N, C, T_down, H, W)
226226
tmp_feats = self.dpe[j](tmp_feats).view(N, C, T_down, L - 1).permute(3, 0, 2, 1)
227-
tmp_x[1:] = tmp_x[1:] + tmp_feats
227+
# tmp_x[1:] = tmp_x[1:] + tmp_feats # memory leak
228+
tmp_x = torch.cat([tmp_x[:1], tmp_x[1:] + tmp_feats], dim=0) # no memory leak
228229
# enhancer
229230
tmp_x = tmp_x.permute(2, 0, 1, 3).flatten(0, 1) # T * L, N, C
230231
cls_token = self.dec[j](cls_token, tmp_x)

InternVideo1/Pretrain/UniFormerV2/slowfast/models/uniformerv2_model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ def forward(self, x):
261261
_, tmp_feats = tmp_x[:1], tmp_x[1:]
262262
tmp_feats = tmp_feats.permute(1, 3, 2, 0).reshape(N, C, T_down, H, W)
263263
tmp_feats = self.dpe[j](tmp_feats.clone()).view(N, C, T_down, L - 1).permute(3, 0, 2, 1).contiguous()
264-
tmp_x[1:] = tmp_x[1:] + tmp_feats
264+
# tmp_x[1:] = tmp_x[1:] + tmp_feats # memory leak
265+
tmp_x = torch.cat([tmp_x[:1], tmp_x[1:] + tmp_feats], dim=0) # no memory leak
265266
# global block
266267
tmp_x = tmp_x.permute(2, 0, 1, 3).flatten(0, 1) # T * L, N, C
267268
cls_token = self.dec[j](cls_token, tmp_x)

0 commit comments

Comments
 (0)