dreamx_world_ar ¶
DreamX-World autoregressive causal DiT.
Adapted from DreamX-World's Apache-2.0 wan/modules/causal_camera_model_2_2_prope_infinity.py. The implementation is kept native to FastVideo: no production import from DreamX, Diffusers, or Transformers is required.
Classes¶
fastvideo.models.dits.dreamx_world_ar.CausalPropeSelfAttention ¶
CausalPropeSelfAttention(dim, attn_dim, num_heads, window_size=(-1, -1), local_attn_size=-1, sink_size=0, qk_norm=True, eps=1e-06)
Bases: Module
PRoPE self-attention with optional KV cache for camera-controlled inference.
Source code in fastvideo/models/dits/dreamx_world_ar.py
Methods:¶
fastvideo.models.dits.dreamx_world_ar.CausalPropeSelfAttention.forward ¶
forward(x, cam_viewmats, cam_K, seq_lens, grid_sizes, freqs, kv_cache=None, current_start=0, cache_start=None, sink_recache_after_switch=False, cache_update_policy='commit_detached')
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x | Shape [B, L, C] | required | |
cam_viewmats | Camera view matrices | required | |
cam_K | Camera intrinsics | required | |
kv_cache | Optional KV cache dict. When None, runs full attention over current chunk. | None |
Source code in fastvideo/models/dits/dreamx_world_ar.py
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 | |
fastvideo.models.dits.dreamx_world_ar.CausalWanSelfAttention ¶
Bases: Module
Self-attention with KV cache and Block-Relativistic RoPE for causal inference.
Source code in fastvideo/models/dits/dreamx_world_ar.py
Methods:¶
fastvideo.models.dits.dreamx_world_ar.CausalWanSelfAttention.forward ¶
forward(x, seq_lens, grid_sizes, freqs, kv_cache, current_start=0, cache_start=None, sink_recache_after_switch=False)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x | Shape [B, L, C] | required | |
seq_lens | Shape [B] | required | |
grid_sizes | Shape [B, 3] containing (F, H, W) | required | |
freqs | RoPE frequencies [1024, head_dim / 2] | required | |
kv_cache | Dict with 'k', 'v', 'global_end_index', 'local_end_index' | required | |
current_start | Current position in the global token sequence | 0 |
Source code in fastvideo/models/dits/dreamx_world_ar.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | |
fastvideo.models.dits.dreamx_world_ar.DreamXWorldARTransformer3DModel ¶
Bases: BaseDiT
DreamX-World-5B autoregressive causal transformer.
Source code in fastvideo/models/dits/dreamx_world_ar.py
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 | |
Methods:¶
fastvideo.models.dits.dreamx_world_ar.DreamXWorldARTransformer3DModel.forward ¶
forward(x=None, t=None, context=None, seq_len=None, y=None, y_camera=None, kv_cache=None, crossattn_cache=None, current_start=0, cache_start=0, cache_update_policy='commit_detached', hidden_states=None, encoder_hidden_states=None, timestep=None, **kwargs)
Causal inference with KV caching. See Algorithm 2 of CausVid (https://arxiv.org/abs/2412.07772).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x | List of input video tensors [C_in, F, H, W] | None | |
t | Timestep tensor [B, L] | None | |
context | List of text embeddings [L, C] | None | |
seq_len | Maximum sequence length for positional encoding | None | |
y | Optional conditional video inputs (I2V mode) | None | |
y_camera | Camera parameters dict {'viewmats': ..., 'K': ...} | None | |
kv_cache | List of KV cache dicts per transformer block | None | |
crossattn_cache | List of cross-attention cache dicts | None | |
current_start | Current position in global token sequence | 0 | |
cache_start | Cache start position | 0 | |
cache_update_policy | Cache update strategy ('commit_detached' or 'none') | 'commit_detached' |
Returns:
| Type | Description |
|---|---|
| Stacked output tensors [B, C_out, F, H/8, W/8] |
Source code in fastvideo/models/dits/dreamx_world_ar.py
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 | |
fastvideo.models.dits.dreamx_world_ar.DreamXWorldARTransformer3DModel.init_weights ¶
Initialize model parameters using Xavier initialization.
Source code in fastvideo/models/dits/dreamx_world_ar.py
fastvideo.models.dits.dreamx_world_ar.DreamXWorldARTransformer3DModel.unpatchify ¶
Reconstruct video tensors from patch embeddings.
Source code in fastvideo/models/dits/dreamx_world_ar.py
fastvideo.models.dits.dreamx_world_ar.WanLayerNorm ¶
Bases: LayerNorm
Kept private instead of fastvideo.layers.layernorm.FP32LayerNorm.
The official DreamX-World model_2_2.py normalizes in the input dtype (no x.float() upcast, unlike Wan2.1). FP32LayerNorm casts input and affine params to fp32, which is not bit-identical under bf16, so the verbatim implementation stays.
Source code in fastvideo/models/dits/dreamx_world_ar.py
fastvideo.models.dits.dreamx_world_ar.WanRMSNorm ¶
Bases: Module
Kept private instead of fastvideo.layers.layernorm.RMSNorm.
The official DreamX-World model_2_2.py computes the RMS statistics in the input dtype — the upstream code has the fp32 upcast explicitly commented out (# return self._norm(x.float())...). FastVideo's RMSNorm always normalizes in fp32, which is not bit-identical under bf16, so the verbatim implementation stays.
Source code in fastvideo/models/dits/dreamx_world_ar.py
Functions:¶
fastvideo.models.dits.dreamx_world_ar.block_relativistic_rope ¶
Apply Block-Relativistic RoPE to input tensor. Adapted from Infinity-RoPE (https://arxiv.org/abs/2511.20649).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x | Input tensor [B, L, num_heads, head_dim] | required | |
grid_sizes | Tensor [B, 3] containing (F, H, W) | required | |
freqs | RoPE frequencies | required | |
start_frame | Starting frame index for sequential RoPE | 0 | |
relative_frame_indices | Optional tensor [F] specifying explicit frame indices for Block-Relativistic RoPE. Overrides start_frame if provided. | None |