This repository studies hypernetworks along two complementary lines:
- Static hypernetworks (TensorFlow 2) — convolution layers whose kernels are generated from learned embeddings for small-scale image classification.
- Dynamic hypernetworks (PyTorch) — HyperLSTM-style sequence modeling experiments (PTB, enwik8, Shakespeare) with training/eval/ablation scripts.
The two tracks use different stacks (TensorFlow vs PyTorch). Install and run the part you need using the sections below.
Static hypernetwork idea: generate convolution kernels from learned embeddings.
- Part 1 — Static hypernetworks (TensorFlow, vision)
- Part 2 — Dynamic hypernetworks (PyTorch, sequence modeling)
- Repository layout (overview)
TensorFlow 2 code for static hypernetworks in image classification: baseline CNN / ResNet-style models, hypernetwork-based convolutions, a custom training loop, and controlled experiments on compact vision datasets.
Quick visuals from the repo’s experiments and notes:
Hyperparameter Tuning on MNIST: Baseline vs. Hypernetwork
Hyperparameter Tuning on Fashion-MNIST: Baseline vs. Hypernetwork
- Standard convolutions and hypernetwork-generated convolutions
- A lightweight
SimpleCNNbaseline - A ResNet-v2 style
resnet50 - A CIFAR-style
wrn40_2(WideResNet-40-2) withBasicBlock - Training, validation, checkpointing, TensorBoard logging, and test evaluation
- Reporting from the best validation checkpoint
python -m venv venv
.\venv\Scripts\activate
python -m pip install --upgrade pip
pip install -r requirements.txtrequirements.txt pins: tensorflow==2.15.0, numpy==1.26.4, matplotlib==3.8.4, tensorboard==2.15.1, scipy.
Supported datasets:
mnist,fashion_mnist,cifar10— viatf.keras.datasetssvhn—.matfiles under../data/svhnby default (train_32x32.mat,test_32x32.mat)
Loaders live in static/my_datasets/. Labels are one-hot; images are normalized to [0, 1].
| Model | Summary |
|---|---|
simplecnn |
Two conv layers (the second can be HyperConv2D), pooling, dense head; grayscale 28×28×1 or RGB 32×32×3 |
resnet50 |
Subclassed ResNet-v2 with BottleneckBlock |
wrn40_2 |
WideResNet-40-2: 3×3 stem, 16 channels, 3 stages, 6 BasicBlocks per stage, widths 32→64→128 |
Hypernetwork pieces are in static/model/utils.py: HyperConv2D, SharedHyperConvMLP. With hyper_mode=True, selected layers use hyper-convolutions instead of plain Conv2D.
Notebook: open static/static_hypernetwork.ipynb.
CLI grid runner (recommended):
# Train baseline + hyper side-by-side (same grid)
python static/static_hypernetwork.py train --datasets cifar10 --models wrn40_2 --hyper-modes both
# Evaluate the best validation checkpoint on test split
python static/static_hypernetwork.py eval --datasets cifar10 --models wrn40_2 --hyper-modes bothThe underlying training/evaluation logic lives in static/solve/static_hypernet.py (class Solver).
Useful defaults: batch size 1024, Adam, initial LR 5e-4, exponential decay 0.99, global gradient clip norm 100.0, seed 42.
TensorBoard:
tensorboard --logdir runsUnder save_dir: latest/, best/, history/, training_state.json. After training, the solver can reload the best validation checkpoint and report test metrics. REFERENCE_TEST_METRICS includes a small reference table (e.g. CIFAR-10 + WRN-40-2 baseline); exact matching depends on augmentation, splits, schedules, etc.
Practical notes: Keras may show Output Shape: multiple for subclassed models; TF 2.15 can emit internal deprecation warnings; SVHN needs local .mat files; wrn40_2 is the natural CIFAR-style choice over resnet50 for many setups.
Suggested starting points: simplecnn on mnist for a quick sanity check; wrn40_2 on cifar10 for main experiments; compare hyper_mode=False vs True under identical settings.
PyTorch experiments inspired by HyperNetworks, focused on HyperLSTM-style dynamic modulation for character/byte-level modeling (e.g., PTB, enwik8, Shakespeare). This track includes training scripts, evaluation, ablations, and plotting utilities under dynamic/.
| Path | Role |
|---|---|
dynamic/train_all_ptb_unified.py |
Train PTB variants (baseline/LN/HyperLSTM, etc.) |
dynamic/train_all_enwik8.py |
Train enwik8 variants |
dynamic/train_shakespeare.py |
Train Shakespeare baselines |
dynamic/train_shakespeare_hyper.py |
Train Shakespeare HyperLSTM variants |
dynamic/eval_all.py |
Evaluate all datasets and write summaries |
dynamic/eval_ablation.py |
Ablation study runner |
dynamic/plot_training_curves.py |
Plot training curves from logs |
dynamic/plot_evaluation.py |
Plot evaluation charts |
dynamic/data/ |
Dataset files/splits (e.g., PTB) |
dynamic/model_weights/ |
Saved checkpoints (organized by dataset) |
dynamic/logs/ |
Training logs/progress logs |
dynamic/eval_results_summary.csv |
Aggregated evaluation summary |
dynamic/ablation_summary.csv |
Aggregated ablation summary |
Use a separate virtualenv; do not reuse the TensorFlow requirements.txt for this track.
python -m venv venv-pt
# Windows: .\venv-pt\Scripts\activate
pip install "torch>=1.12"From the repo root:
cd dynamic
python train_shakespeare_hyper.py
python eval_all.py
python plot_evaluation.pyFor more dataset-specific instructions (PTB/enwik8, checkpoints), see dynamic/README.md.
HyperNetworks/
├── assets/ # README visuals (GIFs/figures)
├── documentations/ # Paper PDF(s)
│ └── 1609.09106v4.pdf
├── static/ # TensorFlow 2: static hypernetworks (vision)
│ ├── model/ # CNN / ResNet / HyperConv2D utils
│ ├── my_datasets/ # MNIST/Fashion-MNIST/CIFAR-10/SVHN loaders
│ ├── solve/ # Training/eval (Solver)
│ ├── utils/ # Visualization helpers
│ ├── static_hypernetwork.py
│ ├── static_hypernetwork.ipynb
│ └── run_static_hypernetwork.sh
├── dynamic/ # PyTorch: dynamic hypernetworks (HyperLSTM-style)
│ ├── README.md
│ ├── data/ # PTB splits, etc.
│ ├── logs/ # Training logs
│ ├── model_weights/ # Checkpoints (by dataset)
│ ├── evaluation_charts/ # Generated plots
│ ├── eval_ablation_results/ # Ablation outputs
│ ├── train_*.py # Training entrypoints (PTB/enwik8/Shakespeare)
│ ├── eval_*.py # Evaluation/ablation
│ ├── plot_*.py # Plotting utilities
│ ├── eval_results_summary.csv
│ └── ablation_summary.csv
├── requirements.txt # pip deps for TensorFlow (static track)
└── README.md



