reframx
A modular, code-first framework for neural network research.
Downloads & Community Adoption
Health & Engineering Analysis (5 Pillars)
1. Governance & Community50 / 200 ▾
2. PEP Metadata & Packaging200 / 200 ▾
3. Security & Supply Chain150 / 200 ▾
4. Documentation, SEO & Ecosystem155 / 200 ▾
5. Engineering, CI & Quality65 / 200 ▾
Official Documentation & Usage Guide — reframx
Show full original documentation (English README) ▾
reframx
A modular, Python-first, code-first framework for neural network research.
Core philosophy: Researchers own their architectures, losses, data pipelines, and training algorithms.
reframxprovides contract-driven composition, validation, pluggable execution backends, model instrumentation, plugins, and portable.rfxexperiment snapshots — without forcing a fixed model hierarchy or a singleforward -> loss -> backward -> steploop.
Key Features
- Zero-dependency core: Core contracts, validation, execution engine, instrumentation, plugins, and
.rfxpackaging rely only on the Python standard library. - Contract-driven composition:
ComponentSpec,Requirement,RequirementGroup(all_of/any_of),Capability,IOContract, andvalidate_requirements()with concisestr/dictshorthand. - Full research freedom + sensible defaults:
BaseMethodfor arbitrary multi-forward / multi-backward / multi-optimizer algorithms.SupervisedMethodand PyTorch built-ins (TorchClassificationMethod,TorchRegressionMethod,CrossEntropyObjective,BCEWithLogitsObjective,MSEObjective,TorchAccuracyEvaluator,TorchRegressionEvaluator) for rapid standard workflows.
- Pluggable execution backends:
NativeBackend(default, zero dependencies, easy debugging,experiment.stop()).MMEngineBackend(optional, lazy-imported: GPU/DDP/FSDP,OptimWrapper,ParamScheduler,CheckpointHookwithsave_best/save_last,Visualizer).
- Non-invasive PyTorch GPU integration:
TorchModelAdapter,TorchDatasetAdapter, andTorchStrategy(auto device placement, AMPfp16/bf16,GradScaler,max_grad_norm, gradient accumulation) — never overwrites your existing PyTorch/CUDA installation. - Model instrumentation:
rf.probe()/rf.Probe(zero-overhead pass-through viacontextvars),watch_module/watch_modules, automatic tensor detach,tensor_stats, andcheck_nan_inf. - Plugin system:
ComponentRegistryandPluginManagersupportingload_plugin,load_file,load_path(multi-file packages),load_directory, safediscover_entry_points/load_entry_points, and cleanunload_plugin. - Portable
.rfxarchives: Atomic, unencrypted ZIP experiment snapshots (minimal,standard,portable,fullprofiles) with SHA-256 verification and safe state restoration.
Installation
pip install reframx
Optional integrations:
torchandmmengineare intentionally not installed automatically sopip install reframxnever overwrites your platform-specific CUDA/PyTorch build. Install PyTorch for your hardware from pytorch.org, and optionallypip install mmengineforMMEngineBackend.
Quick Start
import torch
from torch import nn
from torch.utils.data import TensorDataset
import reframx as rf
from reframx.integrations.mmengine import MMEngineBackend
from reframx.integrations.pytorch import (
BCEWithLogitsObjective,
TorchAccuracyEvaluator,
TorchClassificationMethod,
TorchDatasetAdapter,
TorchModelAdapter,
TorchStrategy,
)
# 1. Standard PyTorch model and dataset
raw_model = nn.Sequential(nn.Linear(16, 32), nn.ReLU(), nn.Linear(32, 1))
x_train, y_train = torch.randn(256, 16), torch.randint(0, 2, (256, 1)).float()
x_val, y_val = torch.randn(64, 16), torch.randint(0, 2, (64, 1)).float()
train_ds, val_ds = TensorDataset(x_train, y_train), TensorDataset(x_val, y_val)
# 2. Compose & run on GPU with MMEngine
experiment = rf.Experiment(
name="QuickDemo",
task=rf.ClassificationTask(num_classes=2),
method=TorchClassificationMethod(),
model=TorchModelAdapter(raw_model),
dataset=TorchDatasetAdapter(
datasets={"train": train_ds, "val": val_ds},
dataloader_kwargs={"batch_size": 32},
),
objectives=BCEWithLogitsObjective(),
optimizers=torch.optim.AdamW(raw_model.parameters(), lr=1e-3),
evaluator=TorchAccuracyEvaluator(),
strategy=TorchStrategy(device="auto", precision="fp16", max_grad_norm=1.0),
backend=MMEngineBackend(work_dir="./work_dirs/quick_demo"),
)
run = experiment.run(max_epochs=5, catch_interrupt=True)
experiment.export("./work_dirs/quick_demo.rfx", profile="standard")
Documentation
- Getting Started & Quickstart
- User Guide
- Developer Guide: Writing Custom Components
- Developer Guide: Writing Plugins
- Architecture & Class/Module Diagrams
- API Reference
Examples
- examples/common_component.py — Contract & compatibility validation.
- examples/basic/pytorch_experiment.py — Concise PyTorch experiment using built-ins.
- examples/basic/text_attention_binary_classification.py — Multi-Head Attention text classification on GPU with
tiktoken, HuggingFacedatasets, andMMEngineBackend. - examples/custom_task/multilabel_task.py — Custom
BaseTaskwith shorthandRequirementGroup&IOContract. - examples/custom_model/residual_model.py — Plain PyTorch
nn.Module+TorchModelAdapter+ custom validator +.rfxrestore. - examples/custom_method/dual_optimizer_method.py — Manual
BaseMethodwith 2 models, 2 losses, and 2 optimizers. - examples/custom_execution/custom_strategy_and_hooks.py — Gradient accumulation,
EarlyStopOnLossHook,experiment.stop(), andcatch_interrupt=True. - examples/custom_instrumentation/probes_and_module_watch.py —
rf.probe()+ non-invasivewatch_modules()(post_forward&backward) +check_nan_inf. - examples/basic/full_experiment.py & examples/basic/real_binary_classification.py — Zero-dependency pure-Python examples.
License
Released under the MIT License.