How atharshlakshmi/framepack-oneframe works
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: inference_engine.py Inference engine · framepack_models.py Model loader · conditioning_pipeline.py Conditioning pipeline · cli_inference.py CLI entrypoint
Components 20
Core runtime
Local single-frame editing inference path
- CLI entrypoint · Parses args, resolves runtime settings, and starts inference
src/cli_inference.py - Inference engine · Coordinates the full editing run on GPU
src/inference_engine.py - Sampling loop · Runs iterative denoising and step-level execution
src/inference_engine.py - MagCache · Skips redundant forward work during sampling
src/inference_engine.py - Conditioning pipeline · Builds text and image conditioning inputs
src/conditioning_pipeline.py - Null conditioner · Bypasses encoding when guidance is neutral
src/conditioning_pipeline.py - Latent packing · Maps single-frame image regions into latent space
src/latent_packing.py
Model stack
Model loading and external pretrained dependencies
- Model loader · Loads shards, manifests, and cached model state
src/framepack_models.py - VAE config · Configures VAE loading and tiling for lower VRAM
src/framepack_models.py - Text encoders · Prompt encoding backbone used for conditioning
- Vision encoder · Encodes the input image into conditioning features
- VAE · Encodes and decodes image latents
- FramePack DiT · Core generative model adapted for one-frame editing
- FramePack checkout · Upstream codebase providing core model primitives
- Local weights · On-disk pretrained model files consumed at runtime
Experiments
Evaluation and ablation workflows
- Experiment 1 · CLIP scoring and ablation studies
experiments/experiment1 - Experiment 2 · Prompt sets and qualitative evaluation scripts
experiments/experiment2
Support
Documentation and lightweight validation
- Technical summary · Implementation notes and usage contract
documentation/technical_summary.md - README · Top-level usage and repository overview
README.md - Smoke tests · Import and basic initialization checks
test_simple.py
Connections 23
- 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