Model Mode (DEPRECATED)
Train vs eval — the tiny toggle that changes what your model does
- model
- model
CdlModelMode switches a model between train and eval mode, and returns the same instance with the mode applied. That's the whole job. It looks like a nothing node - one dropdown, one wire in, one wire out - until you hit a model whose behavior genuinely changes between the two modes, at which point it becomes the difference between a correct result and garbage.
Here's the mechanism behind it: in train mode, layers like Dropout actively zero out random units, and BatchNorm uses the current batch's statistics. In eval mode, Dropout becomes identity (no randomness) and BatchNorm switches to its running averages. So the same weights can produce meaningfully different outputs depending on the mode. Run inference while the model is still in train mode and you get noisy, unreproducible predictions. Run training in eval mode and your BatchNorm layers quietly stop learning their running statistics.
For the pack's textbook networks this matters unevenly. CdlLeNet uses Sigmoid and pooling only - no Dropout, no BatchNorm - so mode barely changes its output, which is why the pack's inference nodes don't fight over it. But the deeper CV nets, RNNs, and anything with Dropout care a lot. And for inference, ComfyDL's Model Forward node defensively calls eval() itself anyway. Where CdlModelMode earns its keep is setting up a model that flows into a training branch (where you want train) while a parallel Model Forward branch infers (eval) - or just making the intent of your graph explicit.
How it works
The implementation is two lines: model.train() or model.eval(), depending on the dropdown, then the same model object back. No copy is made - this is a state toggle on the original instance, so any downstream node sees the mode you set.
Inputs and output
model- anycdlModel.mode-trainoreval, defaulteval.
The single output is model, same instance, mode applied.
Installing ComfyDL
It's part of the ComfyDL pack:
cd ComfyUI/custom_nodes
git clone https://github.com/Cynthia-lxx/ComfyDL
pip install -r ComfyDL/requirements.txt
Restart ComfyUI. The only extra dependency is matplotlib; torch comes with ComfyUI. ComfyUI Manager users: search "ComfyDL", and if it's missing from the built-in list (the pack isn't on the official registry yet), use Install via Git URL with the repo link.
Common issues
The classic confusion is expecting this node to do training or inference. It doesn't - it only sets the mode flag; the actual forward pass is Model Forward and the learning lives in the optimizer nodes. The subtler trap: because it mutates the model in place, two branches sharing one model share the mode too. Set eval on the inference branch and your training branch downstream is now in eval mode as well. If your graph does both at once, that's exactly when you want Model Clone first so each branch gets its own state.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| model | cdlModel | — | |
| mode | COMBO | eval | 2 options: train, eval |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| model | cdlModel | — |