Practical overview
When it fits
Use Perfusion when prototyping or researching low-rank concept edits in a text-to-image model and you can integrate the wrappers into its embedding and cross-attention path.
Who it is for
- Researchers studying concept editing and personalization in text-to-image models.
- Developers comfortable working with PyTorch modules, embeddings and cross-attention components.
Documented uses
- Wrap key and value projections with rank-one edit modules.
- Prepare a new concept embedding from a superclass term using an embedding wrapper.
- Pass concept-conditioned text encodings through cross-attention components.
- Experiment with combining learned concepts for inference.
Requirements & limits
The repository is public and MIT-licensed. Its documented installation command is `pip install perfusion-pytorch`.
- The examples expose model-level components and require users to supply surrounding model layers and text encodings.
- The README describes Stable Diffusion 1.5 wiring as a to-do, so it does not document a turnkey integration.
- The repository provides wrappers for key/value projections and embeddings, with examples for concept positions and superclass-conditioned encodings.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Wrap key and value projections with Rank1EditModule
Apply the documented Rank-1 edit wrappers to key and value projection layers and call them with concept inputs.
Before you start
- Install
perfusion-pytorchwithpip install perfusion-pytorch. - Have PyTorch
nn.Linearkey and value projections; the example uses 768 input features and 320 output features. - Provide text encodings, concept token indices, and a superclass-conditioned text encoding for the initial calls.
Steps
Import
Rank1EditModulefromperfusion_pytorchand create the key and valuenn.Linearlayers.Wrap the key layer with
Rank1EditModule(to_keys, is_key_proj=True)and the value layer withRank1EditModule(to_values).Call both wrappers with
text_enc,concept_indices, andtext_enc_with_superclassas shown in the example.After training, call
.eval()on both wrappers and invoke them withtext_enc.
Expected outcome
The key and value projections are wrapped for Rank-1 editing; the documented example shows calls during training and subsequent calls in evaluation mode.
Guide limitations
- The example leaves training unspecified and provides no training procedure or validation results.
- The shown
key_pad_maskis not used in the projection calls. - The documented example does not describe inference or image generation.
Prepare superclass-based concept embeddings with EmbeddingWrapper
Wrap an embedding layer and obtain concept and superclass embeddings and associated masks and indices from prompts.
Before you start
- Install
perfusion-pytorchwithpip install perfusion-pytorch. - Have a PyTorch embedding layer; the example uses
nn.Embedding(49408, 512).
Steps
Import
EmbeddingWrapperfromperfusion_pytorchand create the embedding layer.Wrap the layer with
EmbeddingWrapper(embed, superclass_string='dog'), substituting the superclass string for the concept you are preparing.Pass prompts containing the superclass term to the wrapper.
Pass both returned embeddings through the CLIP text transformer, and pass
embed_maskto cross-attention as its key padding mask.
Expected outcome
The example returns concept embeddings, superclass embeddings, an embedding mask, and concept indices for the supplied prompts.
Guide limitations
- The example describes preparation for training and eventual inference but does not provide a training or inference procedure.
- The documented cross-attention mask instruction is specific to use of the returned
embed_maskas a key padding mask. - The README mentions an
OpenClipEmbedWrapperoption but the available text does not document its usage steps.
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 23 October 2026
- Original website title
- lucidrains/perfusion-pytorch · Official homepage title · retained in its source language

