Skip to content

Studio FLUX.3 upsampler: pin the sidecar to the native sd.cpp image card - #14696

Merged
danielhanchen merged 3 commits into
mainfrom
recheck_upsampler_native_place
Oct 28, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
recheck_upsampler_native_place

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Studio: pin the FLUX.3 prompt upsampler to the native sd.cpp image card

The Enhance prompt sidecar (#14137) finds the image model's card by reading placed_ordinal off the active engine's state. The diffusers state has that field. The native sd.cpp state (_SdState) does not: it records its card as physical_gpu_id. So when FLUX.3 runs on native sd.cpp, the upsampler always reads "no card":

native physical_gpu_id: 1
_resident_cuda_ordinal(): None
_child_device_mask(...):  {}

On a host with more than one visible GPU, the on-demand launch then starts llama-server with no device mask. llama.cpp's default splits layers over every visible card, so the 6-7.5 GB sidecar can land on cards the image model never claimed, and the free-memory probe (_accelerator_memory_mib(None)) and the later release_if_tight read the current device rather than the card the sidecar uses. The speculative warm start already declined in this case ("placement"), but the first enhanced generate still launched unpinned.

Change

_SdState gains a read-only placed_ordinal property. It maps physical_gpu_id back to the torch-visible ordinal through get_parent_visible_gpu_ids(), which is the same list _resolved_server_physical_gpu_id used to build the physical id. It returns None when:

  • physical_gpu_id is None (CPU, Metal, Vulkan, --offload-to-cpu, automatic multi-GPU, one-shot mode), or
  • the load used an UNSLOTH_DIFFUSION_SD_CPP_DEVICE off-torch card, or
  • the id is not in the parent-visible list.

In all three cases the answer stays what it was before. Nothing assigns placed_ordinal on an _SdState, and it is not a dataclass field, so construction, replace() and equality are unchanged.

The upsampler and the segmentation helper both read placed_ordinal through getattr, so both now see the native card. For the upsampler that means _child_device_mask pins llama-server to the image model's card (honouring a parent CUDA_VISIBLE_DEVICES / HIP_VISIBLE_DEVICES mask), the memory probe reads that card, and the warm start no longer declines a resolvable native placement. Single-GPU hosts are unchanged, since _child_device_mask returns no mask when torch sees one card.

Tests

New studio/backend/tests/test_sd_cpp_upsampler_placement.py:

  • the upsampler reads the native card for an unmasked host ([0, 1], card 1 and card 0) and for a parent mask (3,5, physical 5 is ordinal 1), and None for an id outside the mask
  • unresolved and off-torch native placements stay unplaced
  • with CUDA_VISIBLE_DEVICES=3,5 and two torch cards, the llama-server child env becomes CUDA_VISIBLE_DEVICES=5

On main 4 of the 6 cases fail (assert None == 1, and {} == {'CUDA_VISIBLE_DEVICES': '5'} for the mask). With this change all 6 pass, and the existing test_flux3_prompt_upsampler.py, test_diffusion_segment.py, test_gpu_arbiter.py and test_swap_kv_resume.py pass unchanged.

Not covered

  • A real two-card run with FLUX.3 on native sd.cpp and the upsampler GGUF was not done here. The tests run the real helpers against the native state schema.
  • A native load whose placement is unresolved (--offload-to-cpu, automatic multi-GPU) still launches the sidecar unpinned on a multi-GPU host, as before.

_SdState records its card as physical_gpu_id, but the upsampler and the
segmentation helper read placed_ordinal off the active engine state, so a
native sd.cpp FLUX.3 load read as unplaced and llama-server launched with no
device mask on multi-GPU hosts. Map physical_gpu_id back to the torch-visible
ordinal through get_parent_visible_gpu_ids.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T02:47:18.908453Z 1661142 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 7c7aec894c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 1661142a90

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit facc3a6 into main Oct 28, 2026
@danielhanchen
danielhanchen deleted the recheck_upsampler_native_place branch October 28, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant