Spaces:
Running on Zero
Running on Zero
Load the AoTI packages from the public multimodalart/minimax-h3-aoti, move the upsample toggle under the prompt
Browse filesFiles changed (3)
- README.md+6-5
- app.py+10-17
- h3_aoti.py+9-7
106 unmodified lines10710810911011111211369 unmodified lines183184185186187188189190191192106 unmodified lines## AoTI-compiled blocksWith `H3_AOTI=1` the 50 repeated transformer blocks run from a compiled package,`diffusers-internal-dev/minimax-h3-aoti:bf16/torch2.11/sm120/dynamic` — a single dynamic-sequence artifact that servesevery canvas, duration, reference set and prompt length.It is the **same package the `transformer/` partition runs**, and nothing about it is partition-specific. The two69 unmodified lines## SecretsThe weights are the public [`MiniMaxAI/MiniMax-H3`](https://huggingface.co/MiniMaxAI/MiniMax-H3) diffuserscheckpoint and the conditioner is a public Space called without a token, so that round trip runs on the caller's ownquota rather than this org's. `HF_TOKEN` is still read by `h3_aoti`, whose compiled-package repository is private —without it, set `H3_AOTI=0`.## Where diffusers comes from106 unmodified lines10710810911011111211369 unmodified lines183184185186187188189190191192193106 unmodified lines## AoTI-compiled blocksWith `H3_AOTI=1` the 50 repeated transformer blocks run from a compiled package,[`multimodalart/minimax-h3-aoti`](https://huggingface.co/multimodalart/minimax-h3-aoti)`:bf16/torch2.11/sm120/dynamic` — a single dynamic-sequence artifact that servesevery canvas, duration, reference set and prompt length.It is the **same package the `transformer/` partition runs**, and nothing about it is partition-specific. The two69 unmodified lines## SecretsNothing this Space loads is private any more: the weights are the public[`MiniMaxAI/MiniMax-H3`](https://huggingface.co/MiniMaxAI/MiniMax-H3) checkpoint, the compiled AoTI packages are thepublic [`multimodalart/minimax-h3-aoti`](https://huggingface.co/multimodalart/minimax-h3-aoti) model repo, and theconditioner is a public Space called without a token — so that round trip runs on the caller's own quota rather thanthis org's. No `HF_TOKEN` is required.## Where diffusers comes from
236 unmodified lines237238239240241242243244307 unmodified lines55255355455555655755826 unmodified lines58558658758858959027 unmodified lines61861962062162262362462562662762862963063163263363463563663763842 unmodified lines681682683684685686687688689690691692693694236 unmodified linesblocks = MiniMaxH3Ref2VAGeneratorBlocks()print(f"[ref2va] loading {[c.name for c in blocks.expected_components]} from {MODEL_REPO} ...", flush=True)pipe = blocks.init_pipeline(MODEL_REPO, components_manager=manager, collection="h3")# `MiniMaxAI/MiniMax-H3` is public, so the weights are fetched without a token. `HF_TOKEN` is still read by# `h3_aoti`, whose compiled-package repository is not.pipe.load_components(dtype=torch.bfloat16)# Pin the two autoencoders to torch SDPA *before* the transformer takes cuDNN, and in that order.307 unmodified linesf"({generate_seconds / int(steps):.1f} s/step) · seed {int(seed)}",flush=True,)return path, refinedload_models()26 unmodified lineslines=3,value="The character walks through a neon-lit street in the rain, humming to themselves",)# One tab per modality, in the order the model reads them. A reference left in a tab that is not the# open one is still part of the request — the tabs lay the slots out, they do not choose between them.with gr.Tabs():27 unmodified lines)steps = gr.Slider(label="Steps", minimum=10, maximum=40, step=1, value=28)seed = gr.Number(label="Seed", value=42, precision=0)upsample = gr.Checkbox(label="Upsample prompt",value=False,info="Rewrites the prompt into the model's trained format with the conditioner's Qwen3-VL before encoding.",)with gr.Column():result = gr.Video(label="Video + soundtrack")with gr.Accordion("Upsampled prompt", open=False):upsampled = gr.Textbox(show_label=False,lines=8,interactive=False,placeholder="Turn on “Upsample prompt” to see the rewrite that was encoded.",)open_slots = gr.State(OPEN_IMAGE_SLOTS)42 unmodified lines],],inputs=[prompt, images[0], audio, video, canvas],outputs=[result, upsampled],fn=generate,cache_examples=True,cache_mode="lazy",)# The video stays the first output and the upsampled prompt is appended last, so existing consumers are untouched.run.click(generate, request, [result, upsampled], api_name="generate")if __name__ == "__main__":236 unmodified lines237238239240241242243244307 unmodified lines55255355455555655755826 unmodified lines58558658758858959059127 unmodified lines61962062162262362462562662762862963063142 unmodified lines674675676677678679680681682683684685686687236 unmodified linesblocks = MiniMaxH3Ref2VAGeneratorBlocks()print(f"[ref2va] loading {[c.name for c in blocks.expected_components]} from {MODEL_REPO} ...", flush=True)pipe = blocks.init_pipeline(MODEL_REPO, components_manager=manager, collection="h3")# Every repository this Space reads is public — the checkpoint, the AoTI packages and the conditioner# Space — so no token is passed anywhere.pipe.load_components(dtype=torch.bfloat16)# Pin the two autoencoders to torch SDPA *before* the transformer takes cuDNN, and in that order.307 unmodified linesf"({generate_seconds / int(steps):.1f} s/step) · seed {int(seed)}",flush=True,)return path, refined, gr.update(visible=bool(refined))load_models()26 unmodified lineslines=3,value="The character walks through a neon-lit street in the rain, humming to themselves",)upsample = gr.Checkbox(label="Upsample prompt", value=False)# One tab per modality, in the order the model reads them. A reference left in a tab that is not the# open one is still part of the request — the tabs lay the slots out, they do not choose between them.with gr.Tabs():27 unmodified lines)steps = gr.Slider(label="Steps", minimum=10, maximum=40, step=1, value=28)seed = gr.Number(label="Seed", value=42, precision=0)with gr.Column():result = gr.Video(label="Video + soundtrack")# Only shown for a request that actually asked for a rewrite, so a plain request is not left with an# empty panel. The accordion is an output for that reason: its visibility is part of the answer.with gr.Accordion("Upsampled prompt", open=False, visible=False) as upsampled_panel:upsampled = gr.Textbox(show_label=False, lines=8, interactive=False)open_slots = gr.State(OPEN_IMAGE_SLOTS)42 unmodified lines],],inputs=[prompt, images[0], audio, video, canvas],outputs=[result, upsampled, upsampled_panel],fn=generate,cache_examples=True,cache_mode="lazy",)# The video stays the first output and the upsampled prompt is appended last, so existing consumers are untouched.run.click(generate, request, [result, upsampled, upsampled_panel], api_name="generate")if __name__ == "__main__":
1 unmodified line234567853 unmodified lines6263646566676869141 unmodified lines2112122132142152162172187 unmodified lines226227228229230231232187 unmodified lines4204214224234244254261 unmodified lineShared byte-identically by every MiniMax-H3 Space. A Space only ever calls `maybe_load()`; the compile path runs fromthe debug Space's "Compile (AoTI)" tab, or off-Space from `job_bf16_aoti.py` on an `rtx-pro-6000` Job, and pushes itsartifacts to `diffusers-internal-dev/minimax-h3-aoti` under `<width>/torch<X.Y>/sm<cc>/<shape>`.What is measured, so nobody has to guess whether this is worth turning on. Unquantized bfloat16, 124 frames,everything resident, one dynamic-sequence package serving every row — on an RTX PRO 6000 Blackwell, torch 2.11,53 unmodified linesfrom pathlib import PathAOTI = os.environ.get("H3_AOTI", "0") == "1"AOTI_REPO = os.environ.get("H3_AOTI_REPO", "diffusers-internal-dev/minimax-h3-aoti")AOTI_REPO_TYPE = os.environ.get("H3_AOTI_REPO_TYPE", "dataset")# `dynamic` is the one package that serves every canvas, duration *and prompt*, and for bfloat16 it is what gets built:# a dynamic sequence dimension exports and compiles cleanly (measured on an rtx-pro-6000 Job, torch 2.11). It has to be# dynamic to be useful at all — `build_packed_sequence` pads nothing, so141 unmodified lines"""Patch the block stack with its compiled package. Once, and safe to call at **startup**.Nothing here touches a GPU: the download is CPU work and the `.pt2` archive is not opened until the first forward,which happens inside the `@spaces.GPU` call. Proven on the pool — `diffusers-internal-dev/minimax-h3-generator-aoti`loads `bf16/torch2.11/sm120/dynamic` at startup, patches all 50 blocks, and generates."""if not AOTI or id(transformer) in _LOADED:return7 unmodified linesrepo_id=AOTI_REPO,repo_type=AOTI_REPO_TYPE,allow_patterns=f"{key}/package/*",token=os.environ.get("HF_TOKEN"),)package_dir = Path(local) / key / "package"if not package_dir.is_dir():187 unmodified linesif not token:raise RuntimeError("`HF_TOKEN` is needed to push the AoTI package.")api = HfApi(token=token)api.create_repo(repo_id=AOTI_REPO, repo_type=AOTI_REPO_TYPE, private=True, exist_ok=True)api.upload_folder(folder_path=str(package_dir),path_in_repo=f"{key}/package",1 unmodified line234567853 unmodified lines6263646566676869707172141 unmodified lines2142152162172182192202217 unmodified lines229230231232233234187 unmodified lines4224234244254264274281 unmodified lineShared byte-identically by every MiniMax-H3 Space. A Space only ever calls `maybe_load()`; the compile path runs fromthe debug Space's "Compile (AoTI)" tab, or off-Space from `job_bf16_aoti.py` on an `rtx-pro-6000` Job, and pushes itsartifacts to `multimodalart/minimax-h3-aoti` under `<width>/torch<X.Y>/sm<cc>/<shape>`.What is measured, so nobody has to guess whether this is worth turning on. Unquantized bfloat16, 124 frames,everything resident, one dynamic-sequence package serving every row — on an RTX PRO 6000 Blackwell, torch 2.11,53 unmodified linesfrom pathlib import PathAOTI = os.environ.get("H3_AOTI", "0") == "1"# A public **model** repo. It used to be a private dataset, which is why the repo type is still a variable: the# artifacts are keyed by quant/torch/arch under `<width>/torch<X.Y>/sm<cc>/<shape>` rather than laid out the way# `spaces.aoti_load` expects, so the download is done by hand either way (see `maybe_load`).AOTI_REPO = os.environ.get("H3_AOTI_REPO", "multimodalart/minimax-h3-aoti")AOTI_REPO_TYPE = os.environ.get("H3_AOTI_REPO_TYPE", "model")# `dynamic` is the one package that serves every canvas, duration *and prompt*, and for bfloat16 it is what gets built:# a dynamic sequence dimension exports and compiles cleanly (measured on an rtx-pro-6000 Job, torch 2.11). It has to be# dynamic to be useful at all — `build_packed_sequence` pads nothing, so141 unmodified lines"""Patch the block stack with its compiled package. Once, and safe to call at **startup**.Nothing here touches a GPU: the download is CPU work and the `.pt2` archive is not opened until the first forward,which happens inside the `@spaces.GPU` call. Proven on the pool: `bf16/torch2.11/sm120/dynamic` loads at startup,patches all 50 blocks, and generates. The repo is public, so no token is passed for it."""if not AOTI or id(transformer) in _LOADED:return7 unmodified linesrepo_id=AOTI_REPO,repo_type=AOTI_REPO_TYPE,allow_patterns=f"{key}/package/*",)package_dir = Path(local) / key / "package"if not package_dir.is_dir():187 unmodified linesif not token:raise RuntimeError("`HF_TOKEN` is needed to push the AoTI package.")api = HfApi(token=token)api.create_repo(repo_id=AOTI_REPO, repo_type=AOTI_REPO_TYPE, private=False, exist_ok=True)api.upload_folder(folder_path=str(package_dir),path_in_repo=f"{key}/package",
README.md+6-5
app.py+10-17
h3_aoti.py+9-7