OpenViSTAI · Agents · Blockchain · Crypto
Menu
Image & Video AI

Perfusion

Perfusion is a Python and PyTorch implementation of Key-Locked Rank One Editing, a method for adding or editing concepts in text-to-image models through low-rank changes to model parameters.

Independent OpenViST project profile, based on linked sources.

Perfusion — Hands-on research prototypes for concept editing in text-to-image models
OpenViST project illustration. See the linked sources for product details.
Understand the project

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.
Before you choose

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.

Source-based practical guide

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-pytorch with pip install perfusion-pytorch.
  • Have PyTorch nn.Linear key 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

  1. Import Rank1EditModule from perfusion_pytorch and create the key and value nn.Linear layers.

  2. Wrap the key layer with Rank1EditModule(to_keys, is_key_proj=True) and the value layer with Rank1EditModule(to_values).

  3. Call both wrappers with text_enc, concept_indices, and text_enc_with_superclass as shown in the example.

  4. After training, call .eval() on both wrappers and invoke them with text_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_mask is not used in the projection calls.
  • The documented example does not describe inference or image generation.
Source-based practical guide

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-pytorch with pip install perfusion-pytorch.
  • Have a PyTorch embedding layer; the example uses nn.Embedding(49408, 512).

Steps

  1. Import EmbeddingWrapper from perfusion_pytorch and create the embedding layer.

  2. Wrap the layer with EmbeddingWrapper(embed, superclass_string='dog'), substituting the superclass string for the concept you are preparing.

  3. Pass prompts containing the superclass term to the wrapper.

  4. Pass both returned embeddings through the CLIP text transformer, and pass embed_mask to 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_mask as a key padding mask.
  • The README mentions an OpenClipEmbedWrapper option but the available text does not document its usage steps.
Evidence and transparency

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