NWG-Net prototype

nwg_net.py contains the network structure for a dataset-conditioned ResNet-50 weight denoiser. train_reward_demo.py provides a demo training loop that unrolls a deterministic DDIM reverse chain and backpropagates the classification loss through every denoising step. The repository also includes demo checkpoints and a small synthetic dataset; see the sections below to run the demos.

from nwg_net import NWGNet, resnet50_parameter_specs

model = NWGNet(num_classes=10)
parameter_names = {spec.name for spec in resnet50_parameter_specs(num_classes=10)}
noisy_parameters = {
    name: value for name, value in resnet.state_dict().items()
    if name in parameter_names
}
epsilon = model(images, labels, timestep, noisy_parameters)

Inputs are a support set of 224x224 RGB images and integer labels, one scalar timestep, and a mapping of noisy trainable ResNet-50 parameters. The output maps the same parameter names to predicted noise tensors of matching shapes. BatchNorm running statistics are buffers and are omitted from the diffusion input and output.

The default uses a 256-wide latent, 4096-scalar chunks, and a rank-64 chunk bottleneck. The dataset encoder keeps the CLS output, label-token output, and 32 learned readout tokens per sample by default, for a total of 34 * N context tokens. Set --image-tokens 8 to use eight readouts per sample. Stage latents attend directly to these tokens. This preserves sample-level context at the cost of memory and attention work growing with the support-set size. Reduce dim or set hierarchy_depth=1 for an even smaller model.

Sparse binary forward demo

Run python generate_sparse_demo.py to create 500 grayscale 224x224 samples, with exactly 5,018 randomly placed ones per sample, and save them to data/sparse_binary_500.pt. The label is the index of the modulo-10 pixel bucket with the most ones, giving a 10-class task. The script repeats each image across RGB channels, runs NWG-Net once, and measures the random noisy ResNet baseline. Both the dataset image encoder and ResNet evaluation use batches of 32.

Run python train_reward_demo.py --steps 100 --log-every 10 to optimize NWG-Net through a differentiable ResNet-50. Each optimizer update averages gradients from 16 micro-rounds by default; each micro-round conditions on all 500 examples and chooses a new 50-example classification batch. It applies per-tensor noise scaling to account for different ResNet parameter magnitudes. The script minimizes cross-entropy, equivalent to maximizing reward -CE. It saves the resulting hypernetwork and optimizer state to checkpoints/nwg_reward_demo.pt.

ResNet training checks

These short runs trained a randomly initialized ResNet-50 on the same 500 synthetic images for 10 epochs with AdamW at learning rate 1e-3. Accuracy is measured on those training images. LayerNorm runs replaced each BatchNorm2d with channel-wise LayerNorm at each spatial location. The classifier was also frozen except for the listed module.

Trainable parameters Normalization Batch size Final training accuracy
conv1 BatchNorm in eval mode 32 10.2%
conv1 LayerNorm 32 10.0%
layer4 (ResNet conv5_x) LayerNorm 32 11.4%
fc LayerNorm 32 10.0%
All ResNet-50 parameters LayerNorm 16 11.4%

The fc-only run reached 12.2% training accuracy at epoch 8 and ended at 10.0%. The task label is computed as the modulo-10 pixel bucket with the most ones, so it depends on fine-grained pixel positions. The table reports training accuracy for this diagnostic setup.

Token autoencoder

Run python token_autoencoder.py --steps 100 --device cuda to generate 16 random sequences of 512 token IDs from a 50,257-token vocabulary and train an autoencoder. A global Fourier transform mixes information across all 8,192 token positions into a [64, 64, 64] latent tensor. The decoder applies the inverse transform and predicts token IDs using the shared token embedding. The script saves the model, input sequences, and latent tensor to artifacts/token_autoencoder_global.pt. The included run reconstructed all tokens in its training sequences after 100 steps.

Pass --resume to restore the model and AdamW state. With this flag, --steps sets the number of additional updates. To use a bundled 8-readout checkpoint, run python train_reward_demo.py --resume --image-tokens 8 --steps 1000 --log-every 25. The trainer unrolls a deterministic DDIM reverse chain of --diffusion-steps steps (default 10) and backpropagates the classification loss through the entire chain.

checkpoints/nwg_reward_demo.pt contains the 100-update, 16-round-accumulation checkpoint. checkpoints/nwg_reward_t10_recursive_1step.pt resumes those weights and applies one optimizer update after a differentiable T=10 DDIM chain with gradient accumulation set to 1. The earlier resumed 1,000-update process was terminated; its unsaved updates are not in either checkpoint.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support