How d-jepa/djepa-imagenet works
Purpose and entry points
D-JEPA is the official PyTorch implementation of “Denoising with a Joint-Embedding Predictive Architecture” for ImageNet-scale latent image generation. The workflow first caches pretrained-VAE latents, then trains or evaluates a D-JEPA model with configurable base/large/huge presets.
Primary entry points:
• main_cache.py — dataset-to-latent caching job.
• main_djepa.py — D-JEPA training/evaluation job.
• scripts/cache_vae.sh, scripts/djepa_base.sh, scripts/djepa_large.sh, scripts/djepa_huge.sh — launch presets.
Latent-data preparation boundary
Images are encoded once by a pretrained KL16 VAE and persisted as cached latents, separating expensive image encoding from model training. The VAE checkpoint is an external artifact expected under pretrained_models/vae/kl16.ckpt; it is not versioned in this tree.
Relevant implementation:
• main_cache.py
• models/pretrained_vae.py
• scripts/cache_vae.sh
This establishes the central data boundary: cache generation consumes source images and the VAE; D-JEPA consumes latent representations rather than raw images.
D-JEPA model architecture
The principal generative/predictive model is defined in models/djepa.py, with Transformer-style building blocks in models/block.py. It likely combines joint-embedding prediction with denoising objectives and exposes model construction used by the training engine.
Core model/loss units:
• models/djepa.py
• models/block.py
• models/jepaloss.py
• models/denoising_mlp.py
The architecture boundary is explicit: model modules own network and objective definitions, while engine modules own execution of training and evaluation steps.
Denoising and sampling backends
The repository supports multiple diffusion/flow-style loss and sampling implementations beneath a shared D-JEPA training flow:
• Gaussian diffusion: models/diffloss/gaussian_diffusion/gaussian_diffusion.py, models/diffloss/gaussian_diffusion/diffloss.py
• Flow matching: models/diffloss/flow_match/flow_match.py, models/diffloss/flow_match/flowloss.py
These backends are architecturally important because they determine the denoising target, time/noise trajectory, and generation procedure applied to latent tokens.
Training, evaluation, and distributed execution
main_djepa.py delegates training/evaluation orchestration to the D-JEPA engine. The engine coordinates batches, forward/loss computation, optimization, checkpoint/evaluation behavior, and likely distributed-runtime concerns.
Relevant paths:
• main_djepa.py
• engine/djepa.py
• engine/__init__.py
Model-scale launch configurations are represented by:
• scripts/djepa_base.sh
• scripts/djepa_large.sh
• scripts/djepa_huge.sh
Data loading and augmentation flow
Dataset ingestion and latent/cache access are centralized in utility modules, with crop logic separated from loader construction:
• util/loader.py
• util/crop.py
• main_cache.py
Control flow is therefore: source dataset → loader/cropping → VAE cache job, then cached latent loader → D-JEPA engine → denoising loss/sampler.
Optimization, evaluation, and external assets
Training schedules and distributed/general runtime utilities are modularized:
• util/lr_sched.py
• util/wd_sched.py
• util/ema_sched.py
• util/misc.py
Evaluation quality is tied to bundled ImageNet ADM FID statistics:
• fid_stats/adm_in256_stats.npz
Material external dependencies/services are Conda-managed Python/PyTorch dependencies, the downloadable KL16-VAE checkpoint, and Hugging Face-hosted pretrained D-JEPA weights referenced by the README.
Main entry points: engine/djepa.py D-JEPA engine · loader.py Dataset loader · models/djepa.py D-JEPA model · main_cache.py Latent cache job
Components 21
Latent preparation
Encode source images once before D-JEPA training.
- VAE cache launcher
scripts/cache_vae.sh - Latent cache job · Creates persistent VAE latents from image batches.
main_cache.py - Source image dataset
- Dataset loader · Builds image and cached-latent data access.
util/loader.py - Crop transforms
util/crop.py - Pretrained KL16 VAE · Encodes images into training latents.
models/pretrained_vae.py - Cached latents · Boundary between image encoding and D-JEPA execution.
Training runtime
Train or evaluate D-JEPA on cached latents.
- D-JEPA scale presets · Base, large, and huge launch configurations.
scripts/djepa_base.sh - D-JEPA job · Starts training or evaluation.
main_djepa.py - D-JEPA engine · Coordinates batches, optimization, checkpoints, and evaluation.
engine/djepa.py - Distributed runtime · Shared distributed and general execution support.
util/misc.py - Optimizer schedules · Learning-rate, weight-decay, and EMA scheduling.
util/lr_sched.py
Model and objectives
Network definitions and interchangeable denoising backends.
- D-JEPA model · Main predictive and generative network.
models/djepa.py - Transformer blocks
models/block.py - JEPA objective
models/jepaloss.py - Denoising MLP
models/denoising_mlp.py - Gaussian diffusion backend · Defines Gaussian diffusion loss and sampling trajectory.
models/diffloss/gaussian_diffusion/gaussian_diffusion.py - Flow matching backend · Defines flow-matching loss and generation trajectory.
models/diffloss/flow_match/flow_match.py
External assets
Checkpoints, statistics, and published weights.
- KL16 VAE checkpoint · Downloaded artifact; not versioned in the repository.
- ImageNet ADM FID stats
fid_stats/adm_in256_stats.npz - Published D-JEPA weights · Hugging Face-hosted pretrained model artifacts.
Connections 21
- VAE cache launcher → Latent cache job: launches
- Source image dataset → Dataset loader: ingested by
- Crop transforms → Dataset loader: applies crops
- Dataset loader → Latent cache job: image batches
- KL16 VAE checkpoint → Pretrained KL16 VAE: loads
- Pretrained KL16 VAE → Latent cache job: encodes images
- Latent cache job → Cached latents: persists
- D-JEPA scale presets → D-JEPA job: launches
- Cached latents → Dataset loader: read as training data
- Dataset loader → D-JEPA engine: latent batches
- D-JEPA job → D-JEPA engine: delegates to
- Distributed runtime → D-JEPA engine: supports execution
- Optimizer schedules → D-JEPA engine: controls optimization
- D-JEPA engine → D-JEPA model: trains and evaluates
- Transformer blocks → D-JEPA model: compose
- D-JEPA model → JEPA objective: optimizes
- D-JEPA model → Denoising MLP: uses
- Denoising MLP → Gaussian diffusion backend: selects backend
- Denoising MLP → Flow matching backend: selects backend
- D-JEPA engine → ImageNet ADM FID stats: evaluates against
- Published D-JEPA weights → D-JEPA model: pretrained artifact