Apply StyleGAN Direction
The slider for a face you can't prompt
- stylegan_latent
- directions
- STYLEGAN_LATENT
This is the payoff node of the whole direction-discovery chain in ComfyUI-StyleGan. You've got a StyleGAN face latent, and you want it to smile more, look older, turn its head - without a prompt, because StyleGAN doesn't take prompts. GANSpace and SeFa hand you anonymous direction vectors; this node is the thing you push them through. One latent in, one latent out, moved a measurable amount along one direction.
What it's doing under the hood
StyleGAN latents live in W-space: a [batch, num_ws, w_dim] tensor where each of the num_ws layers controls a different band of features. The math in the node is embarrassingly simple, and that's the point - it clones your latent and adds strength * direction to the rows you didn't mask out. Nothing is retrained, nothing is inverted, no second model. If you've ever wished inpainting had a version with zero drift, this is it: the identity stays put because you're not resampling pixels, you're nudging the code that produced them.
component_index picks which direction out of the bundle you're applying, and it's clamped - min(component_index, directions.shape[0] - 1). Ask for component 9 from a 5-component bundle and you get component 4, quietly. Keep that in mind when an edit looks suspiciously like the last one you tried.
The mask dropdown is a 16-bit layer mask and the hex in each label is literally the number: total (0xFFFF) touches everything, coarse (0xFF00) the first eight layers, mid (0x0FF0) the middle, fine (0x00FF) the last eight. alt1/alt2/alt3 are interleaved patterns for when you want to split by odd/even layer. Coarse is the band people reach for first for pose and expression; fine is where texture and color live. One quirk worth knowing: the mask string is padded on the left to fit the model's layer count, so on a 1024px checkpoint with more than sixteen W+ rows the "coarse" band starts a couple of layers in rather than at zero.
The inputs that matter
You need a stylegan_latent (from GenerateStyleGANLatent, LoadStyleGANLatentImg, or another direction node) and a directions bundle (from DiscoverGANSpaceDirections, DiscoverSeFaDirections, or LoadStyleGANDirections). Then component_index, strength, mask.
strength is the only number you'll tune, and its sane range depends entirely on where the directions came from. GANSpace components are scaled to roughly one standard deviation, so ±1 to ±3 does real work. SeFa components are unit-normalized, so ±5 to ±20 is the useful band - the defaults here (1.0) will look like nothing on a SeFa direction. Negative strengths just flip the edit, which is also how you find out that "smile" is really "smile ←→ frown" on one axis.
Output is a single STYLEGAN_LATENT. Wire it into StyleGANSampler to see it, into another ApplyStyleGANDirection to stack a second component, or SaveStyleGANLatentImg if you like the result. Composing two or three nodes is the normal way to build a specific look - one for age, one for expression, one for lighting - and each one costs nothing to render until the sampler runs.
Install
ComfyUI Manager, search ComfyUI-StyleGan (registry publisher dflfd), or:
cd ComfyUI/custom_nodes
git clone https://github.com/dfl/ComfyUI-StyleGan
Then restart. Models go in ComfyUI/models/stylegan/ - .pkl works, and LoadStyleGAN converts it to a .safetensors cache the first time. Direction bundles are read from ComfyUI/models/stylegan_directions/, a deliberately separate folder so the two pickers don't show each other's files. The heavy part is the runtime-compiled CUDA extensions (CUDA Toolkit + ninja + MSVC/GCC); the first StyleGAN render spends 30–60s building plugins and logs Setting up PyTorch plugin ... Done. Discovery nodes don't need those ops, but this one feeds a sampler, so you need them working eventually.
Where people get burned
- The edit does nothing. Almost always a strength scale mismatch - you're applying SeFa components at strength 1.0. Try ±10 before you conclude the direction is dead.
- The edit is mush. Past a certain strength these directions break down; the pack's own worked example (a GANSpace smile direction on
BroGANv1.2.0, coarse mask) shows visible ghosting at +9. Back off to 5–7. - You're driving yourself mad picking components blind. Don't. Run
StyleGANDirectionSweepfirst, look at what each index actually does, then come back and setstrengthwith your eyes open. - Apple Silicon. The README flags that StyleGAN3 synthesis can differ noticeably between PyTorch versions on the same MPS device - a direction that should show a clear effect can come out flat. If the numbers look right and the image doesn't, try another PyTorch version before blaming the direction.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| stylegan_latent | STYLEGAN_LATENT | — | |
| directions | STYLEGAN_DIRECTIONS | — | |
| component_index | INT | 0 | — |
| strength | FLOAT | 1.00-50–50 | — |
| mask | COMBO | 7 options: total (0xFFFF), coarse (0xFF00), mid (0x0FF0), fine (0x00FF), alt1 (0xF0F0), alt2 (0x0F0F), +1 |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STYLEGAN_LATENT | STYLEGAN_LATENT | — |