KJNodes/memorygenerated

Model Memory Usage Factor Override(ModelMemoryUsageFactorOverride)

This node implements its functionality by cloning the input model and adding a wrapper to it.

Model Memory Usage Factor Override

model
MODEL
memory_usage_factor
1.000
KJNodes

The Model Memory Usage Factor Override node implements its functionality by cloning the input model and adding a wrapper to it.

The Model Memory Usage Factor Override node is an experimental tool used to dynamically adjust the model's memory usage factor during the sampling process. Its core function is to override the model's original memory usage strategy, allowing users to fine-tune it based on hardware conditions or performance requirements to optimize VRAM usage.

Node Functionality

This node implements its functionality by cloning the input model and adding a wrapper to it. This wrapper intervenes during the sampling preparation phase (PREPARE_SAMPLING), applying the user-specified memory_usage_factor value to the model, thereby overriding its internal default memory usage factor. Its internal implementation involves potential adjustments to the model's forward propagation process (such as the wan_ffn_chunked_forward method) to control the chunking strategy of tensors during computation, which in turn affects peak VRAM usage.

Node Parameter Description - Model Memory Usage Factor Override

Connection Inputs (Inputs)

Parameter NameData TypeRequiredDefault ValueValue Range/OptionsDescription
modelMODELYes--**: The base model whose memory usage factor needs to be adjusted. This parameter receives a standard MODEL type data flow.

Control Parameters (Parameters)

Parameter NameData TypeRequiredDefault ValueValue Range/OptionsDescription
memory_usage_factorFLOATYes1.00.0 - 100.0 (Step: 0.001)**: The multiplier used to override the model's original memory usage factor. The value range is from 0.0 to 100.0, with an adjustment step of 0.001. The default value of 1.0 means no change.

Output

Parameter NameData TypeDescription
MODELMODEL**: Outputs a new, modified model instance whose memory usage behavior has been adjusted according to the input factor.

Usage Scenarios

When you are processing high-resolution images or complex models and encounter Out of Memory (OOM) errors, you can insert this node between the Load Checkpoint node and the KSampler node. By appropriately reducing the value of memory_usage_factor (e.g., setting it to 0.8), you can attempt to reduce the VRAM required for a single computation, thereby completing the generation task with limited GPU memory.

Notes

This node is marked as experimental (EXPERIMENTAL). Its behavior and effects may vary depending on different model architectures or ComfyUI versions. Adjusting the memory usage factor may affect generation speed and, at extreme values, could even lead to degraded image quality or computational errors. It is recommended to validate the results after making adjustments.

The Model Memory Usage Factor Override node is from the ComfyUI-KJNodes node package.

Comments

Sign in with GitHub to join the discussion.

Loading comments…