Pt Apply Function
Where the pack's callables actually get called
- tens
- closure
- TENSOR
Some nodes in ComfyUI-Pt-Wrapper don't give you a tensor - they give you a function. Sp Encode and Hf Tokenizer Encode emit a PTCALLABLE, a configured callable that turns text into tokens. Pt Apply Function is the node that takes that callable, applies it to a tensor, and hands you the result. It's the pack's answer to "how do I call a function inside a node graph," and it's the hinge the whole text-pipeline side swings on.
It sits in the Training category of HowToSD's 200-node PyTorch pack (the spin-off of ComfyUI-Data-Analysis), which tells you where it belongs in the flow. A typical wiring: Hf Tokenizer Encode (configured with a model name) → its PTCALLABLE → Pt Apply Function along with your text tensor → the tokenized result, ready for an embedding or model node. Without this node, callables would be dead ends in a graph that only passes tensors; with it, you can thread functions around like first-class data.
How it works. Two required inputs:
tens- theTENSORyou want processed. In the text case, the tensor holding your input text/sentences.closure- thePTCALLABLEfrom a node like Hf Tokenizer Encode or Sp Encode (or any other pack node that outputs one).
The implementation is literally closure(tens) - it invokes the callable on the tensor and returns whatever it produces as a TENSOR. That's the whole mechanism, and its simplicity is the point: the callable was built with its configuration baked in (padding, truncation, model name), so calling it here is a one-step handoff.
The confusion that trips people up. First, the two inputs are not symmetric - swapping them makes no sense, and the pack will likely error. Second, the callable is configured by its source node, not here - if padding is wrong, you fix it back at Sp/Hf Tokenizer Encode, not at Pt Apply Function; this node has no settings at all. Third, and most important: you must feed tens something the callable expects. The tokenizer callables want a string or a list of strings packed into a tensor - feed them a random feature tensor and you'll get a bizarre error that reads like a bug but is really a type mismatch. If the error mentions encoding or tokenization, the callable is working exactly as designed; your tensor is just not text-shaped.
Install: ComfyUI Manager → "ComfyUI-Pt-Wrapper", or:
cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper
then restart. No model downloads beyond whatever your tokenizer source node pulls (the HF node downloads on first use). The pack's heavy requirements.txt is the setup cost.
Troubleshooting: "object is not callable" or type errors - closure isn't a PTCALLABLE; check you wired the output of a tokenizer node, not a tensor. Wrong output shape - go back to the source node's padding/truncation settings; that's where the behavior lives. Weird encoding errors - the tensor you fed isn't text; the pack's text paths expect text tensors, so trace where your strings went. When in doubt, rebuild the callable: re-run the tokenizer node, since stale configuration gets baked in at build time.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| tens | TENSOR | — | |
| closure | PTCALLABLE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| TENSOR | TENSOR | — |