Core infrastructure
The worldfoundry/core shared layer — loading, attention, distributed, VRAM, kernels, memory, and the rule that reusable primitives live here, not in family packages.
On this page
Why this layer exists
worldfoundry/core is the shared inference infrastructure that every model family reuses and none of them owns. Checkpoint loading, state-dict remapping, attention backends, distributed collectives, VRAM placement and offload, kernels, configuration, media IO, memory contracts, and safety guardrails all live here once. A family package (worldfoundry/base_models/*, worldfoundry/synthesis/*, worldfoundry/pipelines/*) composes these primitives; it must not recreate them.
This is the layer to read when you are about to copy a utility into a model directory. The rule is explicit: if multiple families actually reuse a capability, it belongs in core; an adapter tied to a specific model belongs with that model. See Native diffusion for how diffusion consumes this layer, and Model runtime for how pipelines and operators do.
Subpackage responsibilities
Subpackage
attentionBackends, rotary embeddings, sequence layouts, KV caches, sparse and parallel attention.
Start here
backends/, rotary/, sequence/, cache/, sparse/, parallel/distributedProcess setup, collectives, model-parallel groups, sequence-parallel runtime and parameter sharding.
Start here
runtime/, collectives/, model_parallel/, sequence_parallel/, sharding/model_loadingModel construction, loading policy and weight conversion; checkpoints is the single owner of safe state-dict loading and assignment.
Start here
checkpoints/, model.py, inference_model.py, lora.pyioAsset materialization, filesystems, structured formats and inference input datasets.
Start here
assets/, filesystem/, formats/, inputs/, paths.py, manifests.pymediaImage, audio and video codecs, frame processing, output types and artifact previews.
Start here
codecs/, processing/, types.py, resolutions.py, artifacts.pyexecutionProcess lifecycle, inference policy, runtime caches, compile preparation, CUDA graph replay and realtime orchestration.
Start here
graphs/, realtime/, inference.py, inference_runtime.py, process.pyplatformAccelerator detection, torch and collective backend selection, and the persistent
torch.compilecache.Start here
device.py, compile_cache.pyconfigurationStructured/Python config, Hydra adapters, overrides, lazy instantiation,
targetfactories and validation.Start here
lazy_config/, factory.py, hydra.py, hydra_utils.py, overrides.py, python.py, validators.pynnReusable neural blocks, transformer math, diffusion primitives, latent codecs and activation checkpointing.
Start here
blocks/, transformer/, diffusion/, latent/, checkpointing/accelerationReusable cache, token pruning, opt-in low-precision linear operators and projection/precision schedules for resident attention.
Start here
quantization/, cache.py, mha_schedule.py, token_pruning.py, technology.pykernelsOperator implementations and dispatch for diffusion, MoE and quantized GEMM, including optional Triton providers.
Start here
capabilities.py, registry.py, diffusion.py, moe.py, quantized_gemm.pyvramPhysical parameter placement, meta initialization, disk state, CPU offload and encoder lifetime.
Start here
device_map.py, initialization.py, disk_map.py, layerwise_offload.py, encoder_lifecycle.pymemorySemantic/context memory contracts, retrieval, conditioning and persistence.
Start here
base.py, conditioning.py, media.py, retrieval.py, store.pygeometryCamera transforms, pose conditioning, trajectories and RGBD warping.
Start here
transforms.py, pose.py, trajectory.py, conditioning.py, warp.pyobservabilityLogging, rank-aware output, terminal formatting, timing, profiling and optional NVTX ranges.
Start here
logging_setup.py, rank_logging.py, formatting.py, colors.py, time.py, torchprofile.pysafetySafety filters and video input guardrails.
Start here
guardrails.py, video_io.pyutilsGeneral Python object/tree helpers and tensor/array utilities with no runtime or media ownership.
Start here
python/, tensors/
Dependency rule
core may depend on PyTorch, diffusers model/operator primitives, and narrow third-party libraries. It must not import worldfoundry.pipelines, worldfoundry.synthesis, worldfoundry.operators, worldfoundry.base_models family packages, or worldfoundry.evals, or worldfoundry.studio. The edge points out of family packages into core, never the reverse.
This keeps family packages thin: a model directory contains checkpoint-compatible tensor math and contract adapters, not a second copy of an offload manager, a distributed bootstrap, a kernel registry, or a quantization system. When you find yourself adding one of those to a family package, move it to core first and import it from there.
The diffusion package restates this rule for its own boundary in Native diffusion. Generic attention, transformer, loading, and offload primitives live in core; diffusion-domain contracts, schedulers, and recipes live in base_models/diffusion_model.
Layering inside core
Core subpackages form a fixed stack. A module imports from its own layer or lower layers, and modules in one layer never import each other in a cycle. From the bottom up:
utils, the root modulesregistry,contracts,env_registry,prompting,action_normalization, and the independent leavesexecution.deadline,model_loading.policyobservabilityioconfiguration,platformdistributedmedia,geometry,kernelsattentionnnmodel_loading/checkpointsacceleration,vrammodel_loadingexecution,memory,safety
A helper that a lower layer needs moves down to that layer instead of being imported upward. tests/core/test_core_module_boundaries.py holds the table and fails on any upward import.
Where it is consumed
- Diffusion —
base_models/diffusion_modelloads checkpoints throughcore/model_loading, runs attention throughcore/attention, and offloads throughcore/vram. Itsoptimizations/re-exports core policy, not a parallel implementation. - Hosted and native runtimes —
synthesis/stages inputs throughcore/ioand writes artifacts throughcore/media. - Memory —
core/memory/base.pydefines the contract; streaming and long-context state insynthesis/*/memoryand action-policy trace state insynthesis/action_generation/memory.pyimplement it. - Distributed execution —
core/distributedis the only place model-parallel groups are initialized; no family package boots its own NCCL group.
Cache and memory identity
Local sharded safetensors caches record the index and referenced shard paths, sizes, and nanosecond modification times in the merged file's metadata. Reuse requires matching source state; changed or missing source files cannot be hidden by a merged cache. Cache publication remains atomic.
MemoryStore default timestamps advance independently of capacity eviction. Explicit and restored numeric timestamps advance the next default timestamp; reset() starts a new timeline, and replace() rebuilds it from the supplied records. Recency ranking uses these record timestamps rather than the bounded list length.
What does not belong here
Training entrypoints, training-only datasets and dataloaders, losses, callbacks, augmentation-only modules, and experiment scripts do not belong in core, nor in base_models. core is inference infrastructure; if a module only matters during training, it should not be added here.
For the directory-level map of every package, see Codebase map. For how a model call flows through these primitives, see Model runtime and Runtime assembly.
Ownership decisions
checkpointis part ofmodel_loading/checkpoints; weight loading, assignment and conversion have one owner.- Media codecs and video processing helpers share
media; downloading and filesystem work stay inio. - CUDA graphs, prewarm, frame prefetch and overlap belong to
execution; encoder placement/lifetime belongs tovram. memorystays separate fromvram: context/retrieval is a model input concern, while placement/offload manages physical memory.- Configuration helpers belong to
configuration, terminal formatting toobservability, and runtime scheduling toexecution. target/class_pathfactories belong toconfiguration; rank-aware logging belongs toobservability.- Accelerator detection and the persistent compile cache belong to
platform; attention projection and precision schedules belong toacceleration; eval-only feature helpers live inworldfoundry/evals. - Wan sequence-parallel adapters and VGGT observation preprocessing live in their model families. Repository inventory audits live in
scripts/model_zoo.
Each subpackage's lazy export table lists only that package's own modules, so worldfoundry.core.io exports I/O names and media helpers come from worldfoundry.core.media. The worldfoundry.core facade maps every public name to the module that defines it. Internal module imports use the owning module directly; there are no compatibility wrappers.
Regression gates
tests/core/test_core_module_boundaries.py checks lazy targets and core imports without optional model dependencies. It also guards against dependencies from core into model/application packages, enforces the layer table above, and keeps every export table pointing at the owning modules. Runtime facade tests run in model environments.
Real-checkpoint changes also require make test-geometry: use fixed inputs, checkpoints, environments and seeds, compare numerical outputs against an accepted reference, and verify the replay hashes still match the current source. Moving files must preserve computation as well as importability.