SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2302.12400 · ICLR · 2023

Towards Stable Test-Time Adaptation in Dynamic Wild World

Mingkui Tan, Yaofo Chen, Peilin Zhao, Yifan Zhang, Jiaxiang Wu, Shuaicheng Niu, Zhiquan Wen

arXiv · PDF · Open in the Atlas

Code that ran

4 of 5 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (1 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 1 has no contract verdict; 3 failures of our instrument; 1 no recorded run); 1 of them was also run on the host, not in the jail, by the peer-agreement lane that set its level, measured 2026-11-22; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2302.12400.json · badge: /api/ran/2302.12400.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
mr-eggplant/SAR canonical (classifier label)
classifier basis: classifier_2025
2 ran · 1 no recorded run
mr-eggplant/sar community
Papers with Code archive
2 ran · 0 no recorded run
FunctionStatusWhere it lives
softmax_entropy Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
mr-eggplant/SAR/sar.py
code served (permissive licence) · get_code("8f4830ebee73f4a1")
How it ran

Ran in Syntology's jail on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned Tensor, ndim 1, dtype family float, shape (2,) as a later run recorded it. The image it ran in was not recorded. The comparison behind this sample's level is a different run: the peer-agreement lane ran it again on the host, not in the jail (report dated 2026-09-05T00:57:04Z). If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# The function softmax_entropy takes a single parameter: x (torch.Tensor)
# It expects logits as input and computes entropy of the softmax distribution
# The tensor should have shape (batch_size, num_classes) based on the operations:
# - x.softmax(1) applies softmax over dimension 1
# - x.log_softmax(1) applies log_softmax over dimension 1
# - .sum(1) sums over dimension 1

# Create a small tensor with batch size 2 and 4 logits
x = torch.randn(2, 4)

ARGS = {
    "x": x
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 1, dtype family float, shape (2,) — shape (2,) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
SAR Ran
ran on a synthesized input · constructed an object; no result was computed
mr-eggplant/sar/sar.py
code served (permissive licence) · get_code("0b21b722b7d11209")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, SAR: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
import math

torch.manual_seed(0)

# Create a simple model that takes input and outputs logits
class SimpleClassifier(nn.Module):
    def __init__(self, input_dim, num_classes):
        super().__init__()
        self.fc = nn.Linear(input_dim, num_classes)
    
    def forward(self, x):
        return self.fc(x)

# Create a simple optimizer wrapper that has first_step and second_step methods
# This mimics SAM (Sharpness-Aware Minimization) optimizer interface
class SAMOptimizer:
    def __init__(self, base_optimizer, rho=0.05):
        self.base_optimizer = base_optimizer
        self.rho = rho
        self.state = {}
    
    def zero_grad(self):
        self.base_optimizer.zero_grad()
    
    def first_step(self, zero_grad=False):
        # SAM first step - compute gradient perturbation
        for group in self.base_optimizer.param_groups:
            for p in group['params']:
                if p.grad is None:
                    continue
                self.state[id(p)] = p.data.clone()
                p.data.add_(p.grad, alpha=self.rho)
        if zero_grad:
            self.zero_grad()
    
    def second_step(self, zero_grad=False):
        # SAM second step - restore and update
        for group in self.base_optimizer.param_groups:
            for p in group['params']:
                if p.grad is None:
                    continue
                p.data = self.state[id(p)]
        self.base_optimizer.step()
        if zero_grad:
            self.zero_grad()
    
    def state_dict(self):
        return self.base_optimizer.state_dict()
    
    def load_state_dict(self, state_dict):
        self.base_optimizer.load_state_dict(state_dict)
    
    def param_groups(self):
        return self.base_optimizer.param_groups

# Build the model and optimizer
input_dim = 4
num_classes = 3
model = SimpleClassifier(input_dim, num_classes)
base_optimizer = torch.optim.SGD(model.parameters(), lr=0.01)
optimizer = SAMOptimizer(base_optimizer)

# Define ARGS
ARGS = {
    'model': model,
    'optimizer': optimizer,
    'steps': 1,
    'episodic': False,
    'margin_e0': 0.4 * math.log(1000),
    'reset_constant_em': 0.2
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type SAR — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a SAR output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
forward_and_adapt_sar Ran
ran; our contract draft was wrong, not the code
mr-eggplant/SAR/sar.py
code served (permissive licence) · get_code("24bd16fbfdab09ae")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned tuple. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
from torch.optim import SGD

torch.manual_seed(0)

# Build a minimal model that takes input and produces logits
class SimpleModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 3)
    
    def forward(self, x):
        return self.linear(x)

# Build a minimal optimizer with first_step and second_step methods (SAM-like)
class SAMOptimizer:
    def __init__(self, params, lr=0.1):
        self.base_optimizer = SGD(params, lr=lr)
        self.param_groups = self.base_optimizer.param_groups
    
    def zero_grad(self):
        self.base_optimizer.zero_grad()
    
    def first_step(self, zero_grad=False):
        # Simulate SAM first step
        for group in self.param_groups:
            for p in group['params']:
                if p.grad is not None:
                    p.data.add_(p.grad, alpha=-group['lr'])
        if zero_grad:
            self.zero_grad()
    
    def second_step(self, zero_grad=False):
        # Simulate SAM second step
        self.base_optimizer.step()
        if zero_grad:
            self.zero_grad()

# Create instances
model = SimpleModel()
x = torch.randn(2, 4)  # batch_size=2, input_dim=4
optimizer = SAMOptimizer(model.parameters(), lr=0.1)
margin = 0.5
reset_constant = 0.2
ema = None

ARGS = {
    'x': x,
    'model': model,
    'optimizer': optimizer,
    'margin': margin,
    'reset_constant': reset_constant,
    'ema': ema
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
forward_and_adapt_sar Ran
ran; our contract draft was wrong, not the code
mr-eggplant/sar/sar.py
code served (permissive licence) · get_code("a35027bc24dbd26d")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
import numpy as np

torch.manual_seed(0)

# Build a minimal model that takes input and outputs logits
class SimpleModel(nn.Module):
    def __init__(self, input_dim=4, output_dim=3):
        super().__init__()
        self.linear = nn.Linear(input_dim, output_dim)
    
    def forward(self, x):
        return self.linear(x)

# Build a minimal optimizer that supports first_step and second_step (SAM-like)
class SAMOptimizer:
    def __init__(self, params, lr=0.1):
        self.param_groups = [{'params': list(params), 'lr': lr}]
        self.lr = lr
        self.state = {}
    
    def zero_grad(self):
        for group in self.param_groups:
            for p in group['params']:
                if p.grad is not None:
                    p.grad.zero_()
    
    def first_step(self, zero_grad=False):
        # Simple first step: update parameters
        for group in self.param_groups:
            for p in group['params']:
                if p.grad is not None:
                    p.data = p.data - group['lr'] * p.grad
        if zero_grad:
            self.zero_grad()
    
    def second_step(self, zero_grad=False):
        # Simple second step: update parameters again
        for group in self.param_groups:
            for p in group['params']:
                if p.grad is not None:
                    p.data = p.data - group['lr'] * p.grad
        if zero_grad:
            self.zero_grad()

# Create instances
model = SimpleModel(input_dim=4, output_dim=3)
optimizer = SAMOptimizer(model.parameters(), lr=0.01)

# Create input tensor: batch size 2, input dimension 4
x = torch.randn(2, 4)

# Parameters for the function
margin = 1.0
reset_constant = 0.2
ema = None  # Start with None, will be initialized in the function

ARGS = {
    'x': x,
    'model': model,
    'optimizer': optimizer,
    'margin': margin,
    'reset_constant': reset_constant,
    'ema': ema
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
update_ema Not yet run
unverified (harvested, no recorded run)
mr-eggplant/SAR/sar.py
code served (permissive licence) · get_code("317e20a5c06dee54")
How it ran

no invocation recorded. this sample carries JSON test cases instead of a setup block; get_reference_implementation serves them with the level they back.

Also present in other papers' code

Of 5 samples lifted from this paper's linked repositories, 5 carry a function identity and 0 do not. Of the 4 distinct functions with an identity, 3 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 0 the same month, 3 later) and 1 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
softmax_entropy
brick of this paper's assembly: loss
22 other papers
3 dated earlier, 18 later, 1 undated · 4 only as an assembly brick
2006.10726 (2020-06)
TENT: FULLY TEST-TIME ADAPTATION BY ENTROPY MINIMIZATION
2105.08714 (2021-05)
Fighting Gradients with Gradients: Dynamic Defenses against Adversarial Attacks
2110.14038 (2021-10)
Robustness of Graph Neural Networks at Scale
and 19 more not named here
update_ema
brick of this paper's assembly: helper
5 other papers
4 later, 1 undated
2311.14402 (2023-11)
TEA: Test-time Energy Adaptation
2408.13983 (2024-08)
Dual-Path Adversarial Lifting for Domain Shift Correction in Online Test-time Adaptation
2505.20704 (2025-05)
Beyond Entropy: Region Confidence Proxy for Wild Test-Time Adaptation
and 2 more not named here
forward_and_adapt_sar
brick of this paper's assembly: update_rule
2 other papers
1 later, 1 undated
2311.14402 (2023-11)
TEA: Test-time Energy Adaptation
openreview_QYPKLGyz7K
SaTeen: Learning Structural Alignment for Continual Test-Time Adaptation

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-22.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Test-time adaptation (TTA) has shown to be effective at tackling distribution shifts between training and testing data by adapting a given model on test samples. However, the online model updating of TTA may be unstable and this is often a key obstacle preventing existing TTA methods from being deployed in the real world. Specifically, TTA may fail to improve or even harm the model performance when test data have: 1) mixed distribution shifts, 2) small batch sizes, and 3) online imbalanced label distribution shifts, which are quite common in practice. In this paper, we investigate the unstable reasons and find that the batch norm layer is a crucial factor hindering TTA stability. Conversely, TTA can perform more stably with batch-agnostic norm layers, i.e., group or layer norm. However, we observe that TTA with group and layer norms does not always succeed and still suffers many failure cases. By digging into the failure cases, we find that certain noisy test samples with large gradients may disturb the model adaption and result in collapsed trivial solutions, i.e., assigning the same class label for all samples. To address the above collapse issue, we propose a sharpness-aware and reliable entropy minimization method, called SAR, for further stabilizing TTA from two aspects: 1) remove partial noisy samples with large gradients, 2) encourage model weights to go to a flat minimum so that the model is robust to the remaining noisy samples. Promising results demonstrate that SAR performs more stably over prior methods and is computationally efficient under the above wild test scenarios. The source code is available at https://github.com/mr-eggplant/SAR.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2302.12400")
get_code_for_paper("2302.12400")
have("2302.12400")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2302.12400.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2302.12400.svg)](https://syntology.ai/paper/2302.12400)

Connect an agent — have() is free.