Init Seq2Seq Weights
Xavier weight init in one node
- model
- model
Neural networks don't train themselves into good solutions from arbitrary starting weights - a bad initialization can stall or blow up training before it ever gets going. ComfyDL's CdlInitSeq2Seq is the fix, applied as a node: it runs Xavier (Glorot) uniform initialization across a sequence-to-sequence model's linear and GRU layers. You build your encoder, you run this over it, and the weights start in the sweet spot that keeps activations and gradients from either vanishing or exploding.
It's a small node that does one job, and it's a genuine best practice rather than a nicety. The d2l book (which ComfyDL ports into nodes) initializes the seq2seq encoder's weights precisely because the models are sensitive to it.
How it works
Under the hood it calls model.apply(init_seq2seq), which walks every submodule of the model and applies the initializer where it applies. The logic is short and targeted:
- For
nn.Linearlayers - the embedding-to-GRU projections and output heads - weights getxavier_uniform_. - For
nn.GRUmodules it iterates the GRU's flat parameter names and Xavier-initializes every parameter whose name contains "weight" (gate and hidden weights alike), leaving biases alone.
Everything else is left untouched. The choice of Xavier uniform matters because it scales the initial weight range by the number of inputs and outputs of each layer, which keeps the signal variance roughly constant as it flows through - exactly what deep seq2seq stacks need.
Inputs and outputs that matter
model- acdlModel(typically aCdlSeq2SeqEncoderyou built, or any hand-assembled module containingLinear/GRUlayers).
The output is the same model, mutated in place and passed through - so it's a pass-through filter you drop onto the model wire between building and training. Because the node returns the identical instance, you can also stack it anywhere in a model-building chain without breaking downstream connections. There are no weights to download and nothing to configure: wire it in and it does its thing.
Where it fits
The intended flow in ComfyDL is: build a CdlSeq2SeqEncoder → pipe the model through CdlInitSeq2Seq → forward-pass or train it via the Model Utils nodes. If you're experimenting with machine-translation-style workflows and your loss is stuck at random-guess level for suspiciously long, check that you actually ran this - the default PyTorch initializations are fine for many models, but seq2seq GRU stacks are the case where the d2l recipes call for explicit Xavier init.
Installing ComfyDL
cd ComfyUI/custom_nodes
git clone https://github.com/Cynthia-lxx/ComfyDL ./ComfyDL
pip install -r ./ComfyDL/requirements.txt
Then restart ComfyUI. ComfyDL's requirements are minimal (matplotlib, IPython, matplotlib-inline) and this node needs no model downloads. If ComfyUI Manager doesn't surface "ComfyDL" (young pack, may not be in the registry), the clone command above is the dependable install.
Gotchas
In-place mutation is the behavior to know about: this node modifies the model you hand it rather than returning a copy, so if you built one encoder and wanted to compare "Xavier-init vs. default" you'd need two separate builds (or ComfyDL's model-clone utility) - initializing the same instance twice just re-initializes it. And don't expect it to touch convolutional or embedding layers; it's deliberately scoped to Linear and GRU, which is all the seq2seq recipe needs.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| model | cdlModel | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| model | cdlModel | — |