Get Rank From Ratio
Size a low-rank truncation automatically — rank = ratio × min(tensor dims)
- a (delta|weight)
- ratio (0.5)
- recipe
Get Rank From Ratio Mecha Recipe answers the annoying question behind every low-rank merge: what rank should I use? Truncation methods need a target rank, and the "right" rank depends on the shape of each tensor - a rank that's sensible for one layer is absurd for another. This node computes it for you: for each tensor, rank = round(min(dim0, dim1) × ratio), capped at the tensor's max possible rank. It returns that as a param recipe you feed straight into Truncate Rank's rank input.
The ratio framing is what makes it useful. Instead of saying "use rank 8 everywhere" (wrong for most layers), you say "keep 50% of each tensor's capacity" - ratio = 0.5 - and every layer gets a rank proportional to its own size. That's a much more portable setting, and it's the reason this node exists rather than just typing a rank into an Int.
Inputs
a (delta|weight)- the recipe to size the rank from. Note the space suffix: it accepts deltas or weights, since truncation typically runs on a delta before it's added back.ratio (0.5)- the fraction of the tensor's smaller dimension to keep. As aMECHA_RECIPE, so you can feed it aFloat, or even schedule it per-block withBlocks Mecha Hyper.
Output: one recipe (MECHA_RECIPE) - a param recipe holding the computed integer rank.
The workflow it completes
Subtract → Get Rank From Ratio ──▶ rank ─┐
▼
Truncate Rank ──▶ Add back to base ──▶ Merger
Truncate (low-rank) merges are how people compress a delta before adding it to a base - SVD the delta, keep only the biggest singular values. This node supplies the "keep only the biggest" number. Start around 0.3–0.5 for real compression and raise toward 1.0 (which means "keep everything") when quality drops.
Install & gotchas
ComfyUI Manager → search mecha → Mecha Merge Node Pack, or:
cd ComfyUI/custom_nodes
git clone https://github.com/ljleb/comfy-mecha.git
pip install -r comfy-mecha/requirements.txt
Restart; only dependency is sd-mecha==1.1.7.
Two things to keep in mind. First, the computed rank is per tensor - it's exactly as good as the ratio is; there's no magic that finds the "perceptual" sweet spot, so budget a couple of runs to tune the ratio. Second, the node only does the math on the shape; it doesn't truncate anything itself. If you wire it into Truncate Rank and nothing gets smaller, check that you actually fed the rank into a truncate node - this node is the ruler, not the saw. And ratio above 1.0 is legal but degenerate (rank can't exceed the tensor's smaller dim, so it just saturates to "keep everything").
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| a (delta|weight) | MECHA_RECIPE | — | |
| ratio (0.5)opt | MECHA_RECIPE | 0.5 | — |
| merge_checkpointingopt | BOOLEAN | false | Speeds up an entire branch of a merge graph that does not change often in exchange of memory. - true: store the first output of this recipe node on cpu memory in fp16. On subsequent workflow executions, as long as the inputs do not change, the cached keys are returned after being cast to the original device and dtype. - false: do not store the output. The recipe and its inputs will re-execute on subsequent workflow executions. Note that the memory used to checkpoint the output is distinct from the cache feature. In general, you probably want to either use this *or* a cache unit, but not both at the same time because the memory adds up. The difference between merge checkpointing and cache is that merge checkpointing completely re-merges from scratch if any input changes. Merge checkpointing is also generally much faster than cache in the fast path. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| recipe | MECHA_RECIPE | — |