multimodalart HF Staff commited on
Commit
1e700f6
·
verified ·
1 Parent(s): e1ead17

Fix Qwen3VL attribute path: self.vlm.visual/.language_model -> self.vlm.model.visual/.language_model (transformers 4.57.6+ nests these under .model)

Browse files
src/policies/LabVLA/modeling_labvla.py CHANGED
@@ -314,8 +314,8 @@ class LabVLAModel(nn.Module):
314
 
315
  def set_requires_grad(self):
316
  if self.config.freeze_vision_encoder:
317
- self.vlm.visual.eval()
318
- for p in self.vlm.visual.parameters():
319
  p.requires_grad = False
320
 
321
  if self.config.train_expert_only:
@@ -351,7 +351,7 @@ class LabVLAModel(nn.Module):
351
  def train(self, mode: bool = True):
352
  super().train(mode)
353
  if self.config.freeze_vision_encoder:
354
- self.vlm.visual.eval()
355
  if self.config.train_expert_only:
356
  self.vlm.eval()
357
  if self.config.train_vlm_only and self.dit_action_head is not None:
@@ -392,13 +392,13 @@ class LabVLAModel(nn.Module):
392
 
393
  # Disable checkpointing for vision encoder if not requested
394
  if not gc_visual_encoder:
395
- for module in self.vlm.visual.modules():
396
  if hasattr(module, 'gradient_checkpointing'):
397
  module.gradient_checkpointing = False
398
 
399
  # Disable checkpointing for Language Model if not requested
400
  if not gc_language_model:
401
- for module in self.vlm.language_model.modules():
402
  if hasattr(module, 'gradient_checkpointing'):
403
  module.gradient_checkpointing = False
404
 
@@ -420,8 +420,8 @@ class LabVLAModel(nn.Module):
420
  total = sum(1 for m in root.modules() if hasattr(m, "gradient_checkpointing"))
421
  active = sum(1 for m in root.modules() if getattr(m, "gradient_checkpointing", False))
422
  return name, active, total
423
- v = _count(self.vlm.visual, "visual")
424
- l = _count(self.vlm.language_model, "language_model")
425
  dit_on = int(getattr(self.dit_action_head, "gradient_checkpointing", False)) if self.dit_action_head is not None else 0
426
  logger.info(
427
  f"GC layers active: visual={v[1]}/{v[2]} language_model={l[1]}/{l[2]} dit={dit_on}"
@@ -472,7 +472,7 @@ class LabVLAModel(nn.Module):
472
  D1 = pixel_values.shape[-1]
473
  pixel_values_flat = pixel_values.view(-1, D1)
474
  image_grid_thw_flat = image_grid_thw.view(-1, 3)
475
- image_embs, _ = self.vlm.visual(pixel_values_flat, image_grid_thw_flat)
476
 
477
  embs = self.vlm.get_input_embeddings()(lang_tokens)
478
  B, L, D2 = embs.shape
@@ -518,7 +518,7 @@ class LabVLAModel(nn.Module):
518
 
519
  HF's ``create_causal_mask`` early-exits when given a 4D mask and
520
  uses it as-is (transformers/masking_utils.py). So routing this
521
- mask through ``self.vlm.language_model(attention_mask=...)`` bypasses
522
  the auto-causal logic entirely.
523
 
524
  Returns:
@@ -633,7 +633,7 @@ class LabVLAModel(nn.Module):
633
 
634
  # Run VLM language model (use_cache=False must be passed explicitly; otherwise gradient checkpointing cannot save memory properly)
635
  layerwise = bool(getattr(self.config, "dit_layerwise_vlm_features", False))
636
- vlm_output = self.vlm.language_model(
637
  inputs_embeds=embs,
638
  attention_mask=lm_attention_mask,
639
  position_ids=position_ids,
@@ -761,7 +761,7 @@ class LabVLAModel(nn.Module):
761
  else:
762
  lm_attention_mask = full_attn
763
 
764
- lm_out = self.vlm.language_model(
765
  inputs_embeds=full_embeds,
766
  attention_mask=lm_attention_mask,
767
  position_ids=full_pos_ids,
@@ -1209,14 +1209,14 @@ class LabVLAModel(nn.Module):
1209
  # semantically equivalent for both branches.
1210
  if self.config.train_expert_only:
1211
  with torch.no_grad():
1212
- lm_out = self.vlm.language_model(
1213
  inputs_embeds=full_embeds,
1214
  attention_mask=lm_attention_mask,
1215
  position_ids=full_pos_ids,
1216
  use_cache=False,
1217
  )
1218
  else:
1219
- lm_out = self.vlm.language_model(
1220
  inputs_embeds=full_embeds,
1221
  attention_mask=lm_attention_mask,
1222
  position_ids=full_pos_ids,
@@ -1385,7 +1385,7 @@ class LabVLAModel(nn.Module):
1385
  else:
1386
  lm_attention_mask = full_attn
1387
 
1388
- lm_out = self.vlm.language_model(
1389
  inputs_embeds=full_embeds,
1390
  attention_mask=lm_attention_mask,
1391
  position_ids=full_pos_ids,
@@ -1614,7 +1614,7 @@ class LabVLAModel(nn.Module):
1614
  lm_attention_mask = full_attn
1615
 
1616
  # (6) SINGLE LM forward
1617
- lm_out = self.vlm.language_model(
1618
  inputs_embeds=full_embeds,
1619
  attention_mask=lm_attention_mask,
1620
  position_ids=full_pos_ids,
 
314
 
315
  def set_requires_grad(self):
316
  if self.config.freeze_vision_encoder:
317
+ self.vlm.model.visual.eval()
318
+ for p in self.vlm.model.visual.parameters():
319
  p.requires_grad = False
320
 
321
  if self.config.train_expert_only:
 
351
  def train(self, mode: bool = True):
352
  super().train(mode)
353
  if self.config.freeze_vision_encoder:
354
+ self.vlm.model.visual.eval()
355
  if self.config.train_expert_only:
356
  self.vlm.eval()
357
  if self.config.train_vlm_only and self.dit_action_head is not None:
 
392
 
393
  # Disable checkpointing for vision encoder if not requested
394
  if not gc_visual_encoder:
395
+ for module in self.vlm.model.visual.modules():
396
  if hasattr(module, 'gradient_checkpointing'):
397
  module.gradient_checkpointing = False
398
 
399
  # Disable checkpointing for Language Model if not requested
400
  if not gc_language_model:
401
+ for module in self.vlm.model.language_model.modules():
402
  if hasattr(module, 'gradient_checkpointing'):
403
  module.gradient_checkpointing = False
404
 
 
420
  total = sum(1 for m in root.modules() if hasattr(m, "gradient_checkpointing"))
421
  active = sum(1 for m in root.modules() if getattr(m, "gradient_checkpointing", False))
422
  return name, active, total
423
+ v = _count(self.vlm.model.visual, "visual")
424
+ l = _count(self.vlm.model.language_model, "language_model")
425
  dit_on = int(getattr(self.dit_action_head, "gradient_checkpointing", False)) if self.dit_action_head is not None else 0
426
  logger.info(
427
  f"GC layers active: visual={v[1]}/{v[2]} language_model={l[1]}/{l[2]} dit={dit_on}"
 
472
  D1 = pixel_values.shape[-1]
473
  pixel_values_flat = pixel_values.view(-1, D1)
474
  image_grid_thw_flat = image_grid_thw.view(-1, 3)
475
+ image_embs, _ = self.vlm.model.visual(pixel_values_flat, image_grid_thw_flat)
476
 
477
  embs = self.vlm.get_input_embeddings()(lang_tokens)
478
  B, L, D2 = embs.shape
 
518
 
519
  HF's ``create_causal_mask`` early-exits when given a 4D mask and
520
  uses it as-is (transformers/masking_utils.py). So routing this
521
+ mask through ``self.vlm.model.language_model(attention_mask=...)`` bypasses
522
  the auto-causal logic entirely.
523
 
524
  Returns:
 
633
 
634
  # Run VLM language model (use_cache=False must be passed explicitly; otherwise gradient checkpointing cannot save memory properly)
635
  layerwise = bool(getattr(self.config, "dit_layerwise_vlm_features", False))
636
+ vlm_output = self.vlm.model.language_model(
637
  inputs_embeds=embs,
638
  attention_mask=lm_attention_mask,
639
  position_ids=position_ids,
 
761
  else:
762
  lm_attention_mask = full_attn
763
 
764
+ lm_out = self.vlm.model.language_model(
765
  inputs_embeds=full_embeds,
766
  attention_mask=lm_attention_mask,
767
  position_ids=full_pos_ids,
 
1209
  # semantically equivalent for both branches.
1210
  if self.config.train_expert_only:
1211
  with torch.no_grad():
1212
+ lm_out = self.vlm.model.language_model(
1213
  inputs_embeds=full_embeds,
1214
  attention_mask=lm_attention_mask,
1215
  position_ids=full_pos_ids,
1216
  use_cache=False,
1217
  )
1218
  else:
1219
+ lm_out = self.vlm.model.language_model(
1220
  inputs_embeds=full_embeds,
1221
  attention_mask=lm_attention_mask,
1222
  position_ids=full_pos_ids,
 
1385
  else:
1386
  lm_attention_mask = full_attn
1387
 
1388
+ lm_out = self.vlm.model.language_model(
1389
  inputs_embeds=full_embeds,
1390
  attention_mask=lm_attention_mask,
1391
  position_ids=full_pos_ids,
 
1614
  lm_attention_mask = full_attn
1615
 
1616
  # (6) SINGLE LM forward
1617
+ lm_out = self.vlm.model.language_model(
1618
  inputs_embeds=full_embeds,
1619
  attention_mask=lm_attention_mask,
1620
  position_ids=full_pos_ids,