# atharshlakshmi/framepack-oneframe architecture

> Architecture diagram of the GitHub repository atharshlakshmi/framepack-oneframe, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/atharshlakshmi/framepack-oneframe
- Repository: https://github.com/atharshlakshmi/framepack-oneframe

## Overview

1. **Purpose and boundary**
   - This repository is a research adaptation layer on top of the external **FramePack** codebase.
   - Its job is to turn a video-generation-oriented model stack into a **single-frame image editing inference pipeline**.
   - The main architectural boundary is: this repo orchestrates and optimizes inference, while the core model primitives still live in the separate `FRAMEPACK_PATH` checkout.

2. **Primary runtime path**
   - The main execution flow is: **CLI entrypoint → inference orchestration → model loading → conditioning → diffusion sampling → latent decoding → output image**.
   - The user supplies an input image and text prompt, and the system returns an edited image file.
   - Most of the complexity is in inference-time coordination, not training.

3. **Command-line interface layer**
   - `src/cli_inference.py` is the top-level user entrypoint.
   - It handles argument parsing, resolves model paths/devices/dtypes, and kicks off the inference engine.
   - `run.sh` and `.env.example` support repeatable local execution by wiring environment variables and defaults.

4. **Inference orchestration layer**
   - `src/inference_engine.py` is the central coordinator.
   - It owns the diffusion sampling loop, tensor/device management, and integration of all conditioning signals.
   - This is also where the performance-oriented wrapper `MagCacheWrapper` is applied to skip redundant model work during sampling.

5. **Conditioning subsystem**
   - `src/conditioning_pipeline.py` contains the text and image conditioning logic.
   - It appears to combine multiple text encoders for prompt conditioning, plus image preprocessing/encoding through the VAE and vision encoder stack.
   - The `NullConditioner` is an optimization path used when guidance is effectively neutral, avoiding unnecessary encoding work.

6. **Model loading and weight management**
   - `src/framepack_models.py` is the model lifecycle layer.
   - It loads safetensors shards using the HuggingFace-style manifest index, which prevents incorrect shard ordering.
   - It also configures the VAE, including tiling mode for lower VRAM usage, and manages cached model state for repeated runs.

7. **Latent packing and indexing**
   - `src/latent_packing.py` manages how latent positions map to the single input frame versus generated output regions.
   - This is an important adaptation point for converting a video-style latent layout into a one-frame inference layout.
   - In architecture diagrams, this is the boundary between conditioning/image structure and the sampling state.

8. **External model dependencies**
   - The project depends on several large pretrained assets: a FramePack DiT model, HunyuanVideo VAE, text encoders, and an image encoder.
   - These are loaded from local files under `models/`, but originate from Hugging Face or the external FramePack repository.
   - The repo is therefore not self-contained; model weights and the FramePack checkout are operational dependencies.

9. **Performance and memory optimizations**
   - Several optimizations materially affect the architecture:
     - skipping redundant text encoding with `NullConditioner`
     - aspect-ratio-aware bucket selection for image sizing
     - quality-aware resizing choices
     - manifest-based shard loading
     - VAE tiling/lazy loading
     - cached diffusion forward-pass skipping via `MagCacheWrapper`
   - These optimizations reduce runtime, memory pressure, and repeated computation, and should be shown as cross-cutting concerns rather than separate subsystems.

10. **Experiments and research workflow**
   - `experiments/experiment1` and `experiments/experiment2` are research-support subsystems, not part of the core inference path.
   - Experiment 1 contains ablation-related code (`clip_scorer.py`, `clip_ssl.py`, `run_ablation_study.py`) for evaluating scoring or optimization ideas.
   - Experiment 2 contains prompt data and a qualitative-study script, indicating manual or semi-automated evaluation workflows.
   - These folders are downstream consumers of the core inference code and should be drawn as analysis/evaluation branches.

11. **Documentation and verification**
   - `documentation/technical_summary.md` and the root `README.md` describe the implementation and usage contract.
   - `test_imports.py` and `test_simple.py` serve as lightweight validation that the package can be imported and the basic pipeline initializes correctly.
   - These are supporting artifacts, not core runtime dependencies.

12. **Operational constraints**
   - The repo is tuned for CUDA GPU inference and large VRAM capacity, with BF16/FP16 tradeoffs and optional VAE tiling for memory reduction.
   - The architecture is therefore centered on **local GPU inference**, with no obvious service backend, queue, or distributed system in this repository.
   - The output boundary is simple: a generated image file written to the specified output path.

Main entry points: [`src/inference_engine.py`](https://github.com/atharshlakshmi/framepack-oneframe/blob/master/src/inference_engine.py) (Inference engine), [`src/framepack_models.py`](https://github.com/atharshlakshmi/framepack-oneframe/blob/master/src/framepack_models.py) (Model loader), [`src/conditioning_pipeline.py`](https://github.com/atharshlakshmi/framepack-oneframe/blob/master/src/conditioning_pipeline.py) (Conditioning pipeline), [`src/cli_inference.py`](https://github.com/atharshlakshmi/framepack-oneframe/blob/master/src/cli_inference.py) (CLI entrypoint)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core runtime"]
  node_cli["CLI entrypoint<br/>command interface<br/>[cli_inference.py]"]
  node_engine["Inference engine<br/>orchestrator"]
  node_sample_loop(("Sampling loop<br/>diffusion control"))
  node_cache_wrap{{"MagCache<br/>optimization wrapper"}}
  node_cond["Conditioning pipeline"]
  node_null_cond{{"Null conditioner<br/>fast path"}}
  node_latent["Latent packing<br/>layout adapter<br/>[latent_packing.py]"]
end

subgraph group_models["Model stack"]
  node_models_loader["Model loader<br/>weight management"]
  node_vae_cfg[("VAE config<br/>memory tuning")]
  node_text_enc["Text encoders<br/>pretrained encoder"]
  node_vision_enc["Vision encoder<br/>pretrained encoder"]
  node_vae[("VAE<br/>latent codec")]
  node_dit{{"FramePack DiT<br/>diffusion model"}}
  node_framepack_dep["FramePack checkout<br/>external dependency"]
  node_models_dir[("Local weights<br/>assets")]
end

subgraph group_research["Experiments"]
  node_exp1["Experiment 1<br/>ablation suite"]
  node_exp2["Experiment 2<br/>study workflow"]
end

subgraph group_support["Support"]
  node_docs["Technical summary<br/>documentation"]
  node_readme["README<br/>documentation<br/>[README.md]"]
  node_tests(("Smoke tests<br/>validation<br/>[test_simple.py]"))
end

node_cli -->|"start"| node_engine
node_engine -->|"load"| node_models_loader
node_models_loader -.->|"depends on"| node_framepack_dep
node_models_loader -->|"reads"| node_models_dir
node_models_loader -->|"configures"| node_vae_cfg
node_models_loader -->|"instantiates"| node_dit
node_models_loader -->|"instantiates"| node_vae
node_cond -->|"encodes"| node_text_enc
node_cond -->|"encodes"| node_vision_enc
node_cond -->|"uses"| node_vae
node_cond -.->|"fast path"| node_null_cond
node_engine -->|"condition"| node_cond
node_engine -->|"pack"| node_latent
node_engine -->|"run"| node_sample_loop
node_sample_loop -.->|"optimize"| node_cache_wrap
node_sample_loop -->|"denoise"| node_dit
node_sample_loop -->|"decode"| node_vae
node_sample_loop -->|"index"| node_latent
node_engine -.->|"documented by"| node_readme
node_engine -.->|"described by"| node_docs
node_tests -.->|"checks"| node_cli
node_exp1 -.->|"evaluates"| node_engine
node_exp2 -.->|"studies"| node_engine

click node_cli "https://github.com/atharshlakshmi/framepack-oneframe/blob/master/src/cli_inference.py"
click node_engine "https://github.com/atharshlakshmi/framepack-oneframe/blob/master/src/inference_engine.py"
click node_sample_loop "https://github.com/atharshlakshmi/framepack-oneframe/blob/master/src/inference_engine.py"
click node_cache_wrap "https://github.com/atharshlakshmi/framepack-oneframe/blob/master/src/inference_engine.py"
click node_cond "https://github.com/atharshlakshmi/framepack-oneframe/blob/master/src/conditioning_pipeline.py"
click node_null_cond "https://github.com/atharshlakshmi/framepack-oneframe/blob/master/src/conditioning_pipeline.py"
click node_latent "https://github.com/atharshlakshmi/framepack-oneframe/blob/master/src/latent_packing.py"
click node_models_loader "https://github.com/atharshlakshmi/framepack-oneframe/blob/master/src/framepack_models.py"
click node_vae_cfg "https://github.com/atharshlakshmi/framepack-oneframe/blob/master/src/framepack_models.py"
click node_exp1 "https://github.com/atharshlakshmi/framepack-oneframe/tree/master/experiments/experiment1"
click node_exp2 "https://github.com/atharshlakshmi/framepack-oneframe/tree/master/experiments/experiment2"
click node_docs "https://github.com/atharshlakshmi/framepack-oneframe/blob/master/documentation/technical_summary.md"
click node_readme "https://github.com/atharshlakshmi/framepack-oneframe/blob/master/README.md"
click node_tests "https://github.com/atharshlakshmi/framepack-oneframe/blob/master/test_simple.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_engine,node_sample_loop,node_cache_wrap,node_cond,node_null_cond,node_latent toneBlue
class node_models_loader,node_vae_cfg,node_text_enc,node_vision_enc,node_vae,node_dit,node_framepack_dep,node_models_dir toneAmber
class node_exp1,node_exp2 toneMint
class node_docs,node_readme,node_tests toneRose
```

## Components

### Core runtime

Local single-frame editing inference path

- [CLI entrypoint](https://github.com/atharshlakshmi/framepack-oneframe/blob/master/src/cli_inference.py): command interface · Parses args, resolves runtime settings, and starts inference · `src/cli_inference.py`
- [Inference engine](https://github.com/atharshlakshmi/framepack-oneframe/blob/master/src/inference_engine.py): orchestrator · Coordinates the full editing run on GPU · `src/inference_engine.py`
- [Sampling loop](https://github.com/atharshlakshmi/framepack-oneframe/blob/master/src/inference_engine.py): diffusion control · Runs iterative denoising and step-level execution · `src/inference_engine.py`
- [MagCache](https://github.com/atharshlakshmi/framepack-oneframe/blob/master/src/inference_engine.py): optimization wrapper · Skips redundant forward work during sampling · `src/inference_engine.py`
- [Conditioning pipeline](https://github.com/atharshlakshmi/framepack-oneframe/blob/master/src/conditioning_pipeline.py): conditioning · Builds text and image conditioning inputs · `src/conditioning_pipeline.py`
- [Null conditioner](https://github.com/atharshlakshmi/framepack-oneframe/blob/master/src/conditioning_pipeline.py): fast path · Bypasses encoding when guidance is neutral · `src/conditioning_pipeline.py`
- [Latent packing](https://github.com/atharshlakshmi/framepack-oneframe/blob/master/src/latent_packing.py): layout adapter · Maps single-frame image regions into latent space · `src/latent_packing.py`

### Model stack

Model loading and external pretrained dependencies

- [Model loader](https://github.com/atharshlakshmi/framepack-oneframe/blob/master/src/framepack_models.py): weight management · Loads shards, manifests, and cached model state · `src/framepack_models.py`
- [VAE config](https://github.com/atharshlakshmi/framepack-oneframe/blob/master/src/framepack_models.py): memory tuning · Configures VAE loading and tiling for lower VRAM · `src/framepack_models.py`
- **Text encoders**: pretrained encoder · Prompt encoding backbone used for conditioning
- **Vision encoder**: pretrained encoder · Encodes the input image into conditioning features
- **VAE**: latent codec · Encodes and decodes image latents
- **FramePack DiT**: diffusion model · Core generative model adapted for one-frame editing
- **FramePack checkout**: external dependency · Upstream codebase providing core model primitives
- **Local weights**: assets · On-disk pretrained model files consumed at runtime

### Experiments

Evaluation and ablation workflows

- [Experiment 1](https://github.com/atharshlakshmi/framepack-oneframe/tree/master/experiments/experiment1): ablation suite · CLIP scoring and ablation studies · `experiments/experiment1`
- [Experiment 2](https://github.com/atharshlakshmi/framepack-oneframe/tree/master/experiments/experiment2): study workflow · Prompt sets and qualitative evaluation scripts · `experiments/experiment2`

### Support

Documentation and lightweight validation

- [Technical summary](https://github.com/atharshlakshmi/framepack-oneframe/blob/master/documentation/technical_summary.md): documentation · Implementation notes and usage contract · `documentation/technical_summary.md`
- [README](https://github.com/atharshlakshmi/framepack-oneframe/blob/master/README.md): documentation · Top-level usage and repository overview · `README.md`
- [Smoke tests](https://github.com/atharshlakshmi/framepack-oneframe/blob/master/test_simple.py): validation · Import and basic initialization checks · `test_simple.py`

## Connections

- CLI entrypoint → Inference engine: start · CLI launches the inference coordinator
- Inference engine → Model loader: load · Inference requests model weights and cached state
- Model loader → FramePack checkout: depends on · Uses upstream FramePack primitives and conventions
- Model loader → Local weights: reads · Loads local pretrained weight files
- Model loader → VAE config: configures · Applies VAE memory/runtime settings
- Model loader → FramePack DiT: instantiates · Constructs the diffusion backbone
- Model loader → VAE: instantiates · Builds the latent codec
- Conditioning pipeline → Text encoders: encodes · Transforms prompt text into conditioning features
- Conditioning pipeline → Vision encoder: encodes · Extracts image features for conditioning
- Conditioning pipeline → VAE: uses · Relies on VAE-side image preprocessing or encoding
- Conditioning pipeline → Null conditioner: fast path · Avoids encoding when guidance is effectively neutral
- Inference engine → Conditioning pipeline: condition · Consumes text and image conditioning inputs
- Inference engine → Latent packing: pack · Prepares single-frame latent layout
- Inference engine → Sampling loop: run · Executes the diffusion sampling process
- Sampling loop → MagCache: optimize · Wraps repeated model work during denoising
- Sampling loop → FramePack DiT: denoise · Calls the generative backbone each step
- Sampling loop → VAE: decode · Converts final latents back to an image
- Sampling loop → Latent packing: index · Uses packing rules to align source and generated regions
- Inference engine → README: documented by · Usage and execution contract are described in the README
- Inference engine → Technical summary: described by · Implementation notes document the architecture
- Smoke tests → CLI entrypoint: checks · Smoke tests verify package import and startup
- Experiment 1 → Inference engine: evaluates · Ablation work consumes the core inference pipeline
- Experiment 2 → Inference engine: studies · Qualitative workflows use the inference path for prompts
