FuncModifyModel
It looks like a Python executor. It is not. Read this before you use it.
- model
- TORCH_MODEL
A node that takes a model and a function text field and "modifies the model using a function" sounds dangerously powerful - and in the EternalKernel pack, it is a trap, just not the fun kind. FuncModifyModel does not run arbitrary Python. Under the hood it's a regex whitelist: exactly four patterns are allowed, and anything else silently falls back to adding a ReLU layer. That's the headline, because it changes how you'll use this node completely.
What it actually supports:
model.add_module('name', nn.ReLU())- add any zero-argtorch.nnlayermodel.add_module('name', nn.Linear(4, 4))- add a layer with constructor argsmodel.eval()- flip the model to eval modemodel.train()- flip it back to train mode
That's the entire grammar. Type model.add_module('relu', nn.ReLU()) and you get a ReLU appended, cleanly. Type anything else - a loop, a lambda, print(), even a valid torch one-liner that doesn't match those regexes - and the node silently adds a safe_relu layer instead, no error, no warning.
How it works
It deep-copies your model, tries to match your function text against those four regex patterns, executes the one that matches, and compares the string representation of before/after to confirm a change happened. If nothing matched, ReLU fallback. If the model genuinely didn't change, it raises a ValueError. The intent was clearly a "safe subset" - and honestly, given how malicious arbitrary-code nodes have been in this ecosystem, a whitelist is the right instinct - but the silent fallback is the bug-in-waiting.
Inputs and output
- model (
TORCH_MODEL) - a Sequential fromSequentialModelProvider. - function (
STRING, multiline) - one of the four supported patterns.
Output: one TORCH_MODEL.
Install
ComfyUI Manager, search "EternalKernel PyTorch Nodes", or:
cd ComfyUI/custom_nodes
git clone https://github.com/TashaSkyUp/EternalKernelPytorchNodes
cd EternalKernelPytorchNodes
pip install -r requirements.txt
Restart ComfyUI; node under ETK/pytorch. No model files. Requirements are the standard stack plus scipy, scikit-learn, transformers, einops.
Common issues
- "I typed code and got a ReLU." Yes. That's the whitelist. Double-check your function against the four patterns - a stray space or a differently-named module won't match, and you'll get the silent fallback.
- Model didn't change. It compares string representations; if the change isn't visible there (or the pattern errored internally), you'll see the
ValueError. The fallback itself is a change, so a bad pattern usually means ReLU, not an error. - It's the only 'run code' node, and it can't really run code. If you need a real arbitrary transform - permuting tensor dims, custom loss - another pack's Python-exec node is what you want.
This pack has no community tutorials, and this node in particular rewards reading the source before using it. The good news: because it deep-copies first, your original model is safe if a pattern misbehaves. And one pack-wide note: the pack patches ComfyUI's validator to ignore return_type_mismatch, so a wrong wire may not error out loudly. Verify before you trust.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| model | TORCH_MODEL | — | |
| function | STRING | model | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| TORCH_MODEL | TORCH_MODEL | — |