patch_vllm_diffusion_tensor_causal.py 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env python3
  2. """Allow DiffusionGemma Tensor causal masks after vLLM PR #47914."""
  3. import sys
  4. from pathlib import Path
  5. source_root = Path(sys.argv[1]) if len(sys.argv) > 1 else Path.cwd()
  6. target = source_root / "vllm/v1/worker/gpu/attn_utils.py"
  7. bad_signature = "causal: bool | Mapping[int, bool] = True,"
  8. fixed_signature = "causal: bool | Mapping[int, bool] | torch.Tensor = True,"
  9. bad_group_causal = (
  10. " group_causal = causal if isinstance(causal, bool) else "
  11. "causal.get(i, True)"
  12. )
  13. fixed_group_causal = """ if isinstance(causal, (bool, torch.Tensor)):
  14. group_causal = causal
  15. else:
  16. group_causal = causal.get(i, True)"""
  17. if not target.exists():
  18. raise SystemExit(f"{target} not found; cannot apply DiffusionGemma causal patch")
  19. text = target.read_text()
  20. if fixed_signature in text and fixed_group_causal in text:
  21. print("DiffusionGemma Tensor causal workaround already present; skipping")
  22. elif bad_signature in text and bad_group_causal in text:
  23. text = text.replace(bad_signature, fixed_signature, 1)
  24. text = text.replace(bad_group_causal, fixed_group_causal, 1)
  25. target.write_text(text)
  26. print("Applied DiffusionGemma Tensor causal workaround for vLLM PR #47914")
  27. else:
  28. print("Known vLLM PR #47914 causal regression pattern not found; skipping")