[Internal] Serialize
Package a value so a remote ComfyUI can receive it
- data
- STRING
[Internal] Serialize is the pack's data-to-JSON boundary, and it exists almost entirely to support remote function calls. The headline feature of ComfyUI Functional is that you can run part of a workflow on another ComfyUI instance - pipeline parallelism, or keeping big models loaded on a dedicated worker - and that only works if you can turn whatever you're sending into a plain string and turn the reply back. Serialize does the first half.
What it actually does: takes any supported value and encodes it into a JSON string via a whitelist encoder, then hands you that string. Supported types are basic Python types plus set, tuple, bytes, numpy.ndarray, torch.Tensor, and PIL.Image. Anything outside that whitelist - models, samplers, most ComfyUI-internal objects - raises a ValueError with the helpful note that "it may contain unserializable types." That's a design constraint, not a bug: the README is explicit that model loaders belong inside the remote function body, never in the serialized parameters.
Inputs:
data- any type; the value you want to ship.use_shared_memory- BOOLEAN, defaultFalse. When both ComfyUI instances run on the same machine and you're passing a CPU tensor, turning this on passes shared-memory metadata instead of copying the tensor bytes - a big win for avoiding serialization overhead. Useless (and wrong) across machines, so leave it off unless you know you're local.
Output: one STRING socket with the serialized payload. The node is also flagged as an output node, so the string shows up in the UI's results panel - handy for eyeballing what actually got serialized.
Because it's marked with IS_CHANGED returning NaN, it re-runs every execution rather than trusting the cache - serialization is exactly the kind of side effect where stale results would be a disaster. There's also a module-level buffer that holds the most recently serialized data so shared-memory tensors stay alive until the remote call finishes; the "next Serialize call replaces it" behavior is worth knowing if you batch remote calls in one run.
Install
Ships with the pack like everything else:
cd ComfyUI/custom_nodes && git clone https://github.com/Duanyll/comfyui_functional
then restart ComfyUI, or install Duanyll/comfyui_functional via ComfyUI Manager. No models, no pip deps. You'll typically meet Serialize in workflows built around Call Remote Function, where it materializes at the boundary between your graph and the wire - the pack builds these automatically, so unless you're hand-rolling a remote pipeline you'll probably just watch it work. If your only goal is splitting a job across two GPUs, remember: Function End must have capture disabled for remote calls, and everything crossing the wire has to be in the whitelist above.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| data | * | — | |
| use_shared_memory | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |