How junghwamin/nmfc-plan2-v3-module-variants works
Purpose and entry points
This is a PyTorch experiment system for reproducing and comparing NMFC v3 module variants across four axes: energy, logit, APT warmup, and reference bank. Primary entry point is python -m src.train --config <yaml> via src/train.py; experiment matrices live in configs/cifar100_variants.yaml and configs/ood_cifar10_variants.yaml.
Variant registry and compatibility boundary
src/variants.py is the architectural switchboard. It resolves and validates variant: config blocks, encodes experiment names, rejects incompatible combinations, and selects head/warmup implementations. The key compatibility boundary is v1 preservation: absent or v1-equivalent variants route to the existing NMFCHead; non-v1 variants route to v3 composition.
• src/variants.py
• src/models/heads.py
• src/models/heads_v3.py
Data and embedding pipeline
Image datasets feed either PK-sampled minibatches or indexed shuffled loaders required by online-bank leave-one-out behavior. The encoder produces embeddings consumed by NMFC heads; datasets and sampling are separate from variant math.
• src/datasets/image.py
• src/datasets/samplers.py
• src/models/encoders.py
Head and energy/logit execution
The legacy head retains mean-energy and scaled-logit behavior. VariantNMFCHead implements configurable soft-min energies, hinge-temperature logits, batch versus online references, prediction, and OOD scoring. Soft-min neighbor selection is stop-gradient; hinge logits cap negative energy at a learned/set margin.
• src/models/heads_v3.py
• src/nmfc/softmin.py
• src/nmfc/energy.py
Reference-bank lifecycle
Training references can be minibatch-based or an online, class-balanced FIFO cross-batch memory. Inference is deliberately separated: a frozen, deterministic k-center coreset bank supplies logits and OOD scores rather than reusing transient training references. Bank state supports persistence/restoration.
• src/models/banks.py
• src/models/heads_v3.py
• src/train.py
Two-phase training control
src/train.py orchestrates Phase I representation warmup followed by Phase II NMFC NLL training. Reciprocal MFA uses the inherited APT controller; negative Fisher-J uses the v3 ACS controller. Controllers detect stagnation and latch the transition, with training responsible for loader changes, bank filling, margin setup, optimizer assembly, and history tracking.
• src/train.py
• src/nmfc/apt.py
• src/nmfc/acs.py
Evaluation, outputs, and runtime
Evaluation reports classification, embedding geometry, and OOD AUC; v3 OOD uses minimum positive soft-min energy. Runs are cached/namespaced and write histories and metrics beneath 산출물/; checkpoints and large embeddings are external/regenerable. The system is Python/PyTorch-based, uses CIFAR-10/100 and SVHN data, and requires GPU infrastructure for practical 224px full experiments.
• src/evaluate.py
• src/utils/experiments.py
• 산출물/
Main entry points: train.py Training entry point · heads_v3.py Variant NMFC head · variants.py Variant registry · encoders.py Embedding encoder
Components 16
Experiment Control
Configuration, variant resolution, and two-phase training.
- Variant matrices · CIFAR-100 and OOD CIFAR-10 experiment definitions.
configs/cifar100_variants.yaml - Training entry point · Runs warmup and NMFC training phases.
src/train.py - Variant registry · Validates variants and preserves v1 routing.
src/variants.py - APT controller · Inherited reciprocal-MFA transition controller.
src/nmfc/apt.py - ACS controller · Controls negative Fisher-J warmup transition.
src/nmfc/acs.py
Model and NMFC
Embedding, heads, energy math, and reference banks.
- Embedding encoder · Transforms images into embeddings.
src/models/encoders.py - Legacy NMFC head · Preserves mean-energy and scaled-logit behavior.
src/models/heads.py - Variant NMFC head · Composes energy, logits, references, prediction, and OOD scoring.
src/models/heads_v3.py - Soft-min neighbors · Stop-gradient neighbor selection for configurable soft-min energy.
src/nmfc/softmin.py - Energy and hinge logits · Computes energies and margin-capped logits.
src/nmfc/energy.py - Reference banks · Online FIFO training bank and frozen k-center inference bank.
src/models/banks.py
Data, Evaluation, Outputs
Loaders, reporting, and persisted run artifacts.
- Image datasets · CIFAR and SVHN image loading.
src/datasets/image.py - Batch samplers · PK sampling or indexed shuffled loading.
src/datasets/samplers.py - Evaluation · Reports classification, geometry, and OOD AUC.
src/evaluate.py - Run cache and namespace · Names and caches experiment runs.
src/utils/experiments.py - Run outputs · Histories and metrics; large checkpoints and embeddings are regenerable.
산출물
Connections 22
- Variant matrices → Training entry point: selects run
- Variant matrices → Variant registry: variant block
- Training entry point → Variant registry: resolve head and warmup
- Variant registry → Legacy NMFC head: absent or v1 variant
- Variant registry → Variant NMFC head: non-v1 variant
- Image datasets → Batch samplers: dataset indices
- Batch samplers → Training entry point: minibatches or indexed loader
- Training entry point → Embedding encoder: optimizes representation
- Embedding encoder → Legacy NMFC head: embeddings
- Embedding encoder → Variant NMFC head: embeddings
- Variant NMFC head → Soft-min neighbors: neighbor energies
- Soft-min neighbors → Energy and hinge logits: selected references
- Energy and hinge logits → Variant NMFC head: energies and logits
- Reference banks → Variant NMFC head: training and inference references
- Training entry point → Reference banks: fill, freeze, persist
- APT controller → Training entry point: warmup transition
- ACS controller → Training entry point: warmup transition
- Training entry point → Evaluation: trained model and frozen bank
- Variant NMFC head → Evaluation: positive soft-min OOD score
- Training entry point → Run cache and namespace: cache and namespace
- Evaluation → Run outputs: metrics
- Run cache and namespace → Run outputs: histories