Views
No views yet
[!NOTE] This README has been auto-generated by the HF Job run linked below and the whole repository is a reproducible artifact of this Job
torch.compile needed)1
2import gc
3from contextlib import contextmanager
4
5import spaces
6import torch
7import torch.utils._pytree as pytree
8from huggingface_hub import hf_hub_download, snapshot_download
9
10from ltx_pipelines.distilled import DistilledPipeline
11from ltx_pipelines.utils.denoisers import SimpleDenoiser
12from ltx_pipelines.utils.types import ModalitySpec
13from ltx_pipelines.utils.constants import DISTILLED_SIGMAS, STAGE_2_DISTILLED_SIGMAS
14from ltx_pipelines.utils.helpers import combined_image_conditionings
15from ltx_pipelines.utils.media_io import encode_video
16from ltx_core.model.video_vae import TilingConfig, get_video_chunks_number
17from ltx_core.model.transformer.transformer_args import TransformerArgs
18from ltx_core.components.noisers import GaussianNoiser
19
20
21import os as _os
22# Reduce CUDA-allocator fragmentation; the LTX-2 distilled pipeline exhausts a
23# 96GB GPU otherwise.
24_os.environ.setdefault("PYTORCH_CUDA_ALLOC_CONF", "expandable_segments:True")
25
26# cuDNN 9.20 + cuBLAS 13.x mismatch causes a `cublasLtGetVersion` segfault at
27# teardown on cu130. The transformer block has no convs anyway.
28torch.backends.cudnn.enabled = False
29
30
31# Register TransformerArgs as a pytree node so torch.export can flatten the
32# dataclass at the export boundary. We exclude `enabled` (bool) so AOTI's
33# boxed_run gets only tensor leaves — otherwise the unflattening at runtime
34# produces 2 extra non-tensor leaves that the compiled artifact doesn't expect.
35_TA_TENSOR_FIELDS = [
36 "x", "context", "context_mask",
37 "timesteps", "embedded_timestep",
38 "positional_embeddings", "cross_positional_embeddings",
39 "cross_scale_shift_timestep", "cross_gate_timestep",
40 "prompt_timestep", "self_attention_mask",
41]
42
43
44def _ta_flatten(obj):
45 values, nones = [], []
46 for name in _TA_TENSOR_FIELDS:
47 v = getattr(obj, name)
48 (nones if v is None else values).append((name, v))
49 flat_names = [n for n, _ in values]
50 none_names = [n for n, _ in nones]
51 return [v for _, v in values], (flat_names, none_names)
52
53
54def _ta_unflatten(values, context):
55 flat_names, none_names = context
56 kwargs = dict(zip(flat_names, values, strict=True))
57 for n in none_names:
58 kwargs[n] = None
59 kwargs["enabled"] = True
60 return TransformerArgs(**kwargs)
61
62
63def _ta_flatten_with_keys(obj):
64 flat, ctx = _ta_flatten(obj)
65 flat_names, _ = ctx
66 return [(pytree.GetAttrKey(n), v) for n, v in zip(flat_names, flat, strict=True)], ctx
67
68
69pytree.register_pytree_node(
70 TransformerArgs,
71 _ta_flatten,
72 _ta_unflatten,
73 serialized_type_name="ltx_core.model.transformer.transformer_args.TransformerArgs",
74 flatten_with_keys_fn=_ta_flatten_with_keys,
75)
76
77
78distilled_path = hf_hub_download("Lightricks/LTX-2", "ltx-2-19b-distilled.safetensors")
79upsampler_path = hf_hub_download("Lightricks/LTX-2", "ltx-2-spatial-upscaler-x2-1.0.safetensors")
80gemma_root = snapshot_download("google/gemma-3-12b-it-qat-q4_0-unquantized")
81
82
83pipeline = DistilledPipeline(
84 distilled_checkpoint_path=distilled_path,
85 gemma_root=gemma_root,
86 spatial_upsampler_path=upsampler_path,
87 loras=[],
88 device=torch.device("cuda"),
89)
90# DiffusionStage rebuilds the transformer on every __call__; we want a single
91# persistent instance so the AOTI artifact survives between samples.
92pipeline._transformer = pipeline.stage._build_transformer()
93
94
95@contextmanager
96def _persistent_transformer_ctx(**_kwargs):
97 yield pipeline._transformer
98
99
100pipeline.stage._transformer_ctx = _persistent_transformer_ctx
101
102spaces.aoti_load(
103 module=pipeline._transformer,
104 repo_id='cbensimon/X0Model-sm120-cu130-rd1',
105)1# Install hf CLI
2curl -LsSf https://hf.co/cli/install.sh | bash
3
4# Login
5hf auth login
6
7# Get the job file and edit (user section) if needed
8hf download cbensimon/X0Model-sm120-cu130-rd1 job.py --local-dir .
9
10# Run the job and change flavor or image if needed
11hf jobs uv run job.py \
12 --flavor rtx-pro-6000 \
13 --image pytorch/pytorch:2.9.1-cuda13.0-cudnn9-devel \
14 --secrets HF_TOKEN
15
16# Or run locally with Docker
17docker run --rm --gpus all \
18 -v $PWD/job.py:/workspace/job.py \
19 -e HF_TOKEN=$(hf auth token) \
20 -e JOB_IMAGE=pytorch/pytorch:2.9.1-cuda13.0-cudnn9-devel \
21 -e JOB_FLAVOR=rtx-pro-6000 \
22 pytorch/pytorch:2.9.1-cuda13.0-cudnn9-devel \
23 uv run /workspace/job.pyOUTPUT_REPO_NAMESPACE: taken from HF_TOKEN otherwiseOUTPUT_REPO_BASE_NAME: defaults to module class nameOUTPUT_REPO_ID: fully overtakes name generation| Before compilation (3.27s) | After compilation (3.20s) |
|---|---|
| Speedup: 1.02x | |
| (note that this might not always reflect actual performance gain) |
PyTorch version: 2.12.0+cu130
Is debug build: False
CUDA used to build PyTorch: 13.0
ROCM used to build PyTorch: N/A
OS: Ubuntu 22.04.5 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: version 4.1.2
Libc version: glibc-2.35
Python version: 3.10.19 (main, Oct 31 2025, 23:02:46) [Clang 21.1.4 ] (64-bit runtime)
Python platform: Linux-6.17.0-1013-aws-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 13.0.48
CUDA_MODULE_LOADING set to:
GPU models and configuration: GPU 0: NVIDIA RTX PRO 6000 Blackwell Server Edition
Nvidia driver version: 595.58.03
cuDNN version: Could not collect
Is XPU available: False
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
Caching allocator config: {'PYTORCH_CUDA_ALLOC_CONF': 'expandable_segments:True'}
CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 46 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Vendor ID: GenuineIntel
Model name: Intel(R) Xeon(R) Platinum 8559C
CPU family: 6
Model: 207
Thread(s) per core: 2
Core(s) per socket: 8
Socket(s): 1
Stepping: 2
BogoMIPS: 4800.00
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq monitor ssse3 fma cx16 pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves avx_vnni avx512_bf16 wbnoinvd ida arat avx512vbmi umip pku ospke waitpkg avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq rdpid cldemote movdiri movdir64b md_clear serialize amx_bf16 avx512_fp16 amx_tile amx_int8 flush_l1d arch_capabilities
Hypervisor vendor: KVM
Virtualization type: full
L1d cache: 384 KiB (8 instances)
L1i cache: 256 KiB (8 instances)
L2 cache: 16 MiB (8 instances)
L3 cache: 320 MiB (1 instance)
NUMA node(s): 1
NUMA node0 CPU(s): 0-15
Vulnerability Gather data sampling: Not affected
Vulnerability Ghostwrite: Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Old microcode: Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; PBRSB-eIBRS SW sequence; BHI BHI_DIS_S
Vulnerability Srbds: Not affected
Vulnerability Tsa: Not affected
Vulnerability Tsx async abort: Not affected
Vulnerability Vmscape: Not affected
Versions of relevant libraries:
[pip3] Could not collect
[conda] numpy 2.3.4 py311h2e04523_0 conda-forge
[conda] nvidia-cublas 13.0.0.19 pypi_0 pypi
[conda] nvidia-cuda-cupti 13.0.48 pypi_0 pypi
[conda] nvidia-cuda-nvrtc 13.0.48 pypi_0 pypi
[conda] nvidia-cuda-runtime 13.0.48 pypi_0 pypi
[conda] nvidia-cudnn-cu13 9.13.0.50 pypi_0 pypi
[conda] nvidia-cufft 12.0.0.15 pypi_0 pypi
[conda] nvidia-curand 10.4.0.35 pypi_0 pypi
[conda] nvidia-cusolver 12.0.3.29 pypi_0 pypi
[conda] nvidia-cusparse 12.6.2.49 pypi_0 pypi
[conda] nvidia-cusparselt-cu13 0.8.0 pypi_0 pypi
[conda] nvidia-nccl-cu13 2.27.7 pypi_0 pypi
[conda] nvidia-nvjitlink 13.0.39 pypi_0 pypi
[conda] nvidia-nvtx 13.0.39 pypi_0 pypi
[conda] optree 0.17.0 pypi_0 pypi
[conda] torch 2.9.1+cu130 pypi_0 pypi
[conda] torchaudio 2.9.1+cu130 pypi_0 pypi
[conda] torchelastic 0.2.2 pypi_0 pypi
[conda] torchvision 0.24.1+cu130 pypi_0 pypi
[conda] triton 3.5.1 pypi_0 pypi