SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2607.11475 · 2026

HyperSafe: Inference-Time Safety Recovery for Fine-Tuned Language Models

Yibo Yang, Carlos Hinojosa, Aznaur Aliev, Abdelrahman Bang, An Ghanem

arXiv · PDF · Open in the Atlas

Code that ran

10 of 11 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (7 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 1 violated it and 9 have no contract verdict; 0 failures of our instrument; 1 no recorded run), measured 2026-11-23; 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/2607.11475.json · badge: /api/ran/2607.11475.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
nokronim/project-safety-remedy community
Papers with Code archive
10 ran · 1 no recorded run
FunctionStatusWhere it lives
CrossLayerAttention Ran
ran on a synthesized input · constructed an object; no result was computed
nokronim/project-safety-remedy/seq2seq/train_hypernetwork_v15.py
code served (permissive licence) · get_code("533548b75a077ca8")
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, CrossLayerAttention: 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

torch.manual_seed(0)

ARGS = {
    "input_dim": 3584,
    "proj_dim": 256,
    "num_queries": 4,
    "num_heads": 4,
    "output_dim": 512,
    "num_layers": 28,
    "use_pos_encoding": False,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type CrossLayerAttention — 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 CrossLayerAttention 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
DirectionEncoder Ran
ran on a synthesized input · constructed an object; no result was computed
nokronim/project-safety-remedy/seq2seq/train_hypernetwork_v15.py
code served (permissive licence) · get_code("306afb2923100ee8")
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, DirectionEncoder: 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

torch.manual_seed(0)

ARGS = {
    "input_dim": 3584,
    "output_dim": 512,
    "num_layers": 28,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type DirectionEncoder — 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 DirectionEncoder 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
DomainFusion Ran
ran on a synthesized input
nokronim/project-safety-remedy/seq2seq/train_hypernetwork_v15.py
code served (permissive licence) · get_code("145e92e5ccacf11b")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 1, dtype family float, shape (5,) as a later run recorded it. The image it ran in was not recorded. 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

class DomainFusion(nn.Module):
    """Fuse direction + magnitude encodings into a single global embedding."""

    def __init__(self, direction_dim: int=512, magnitude_dim: int=128, output_dim: int=512):
        super().__init__()
        self.net = nn.Sequential(nn.Linear(direction_dim + magnitude_dim, output_dim), nn.LayerNorm(output_dim), nn.GELU())

    def forward(self, direction_emb: torch.Tensor, magnitude_emb: torch.Tensor) -> torch.Tensor:
        """
        Args:
            direction_emb: [direction_dim] from DirectionEncoder
            magnitude_emb: [magnitude_dim] from MagnitudeEncoder
        Returns:
            [output_dim] fused global embedding
        """
        return self.net(torch.cat([direction_emb, magnitude_emb], dim=-1))


INIT_ARGS = {
    "direction_dim": 4,
    "magnitude_dim": 3,
    "output_dim": 5,
}

ARGS = {
    "direction_emb": torch.randn(4),
    "magnitude_emb": torch.randn(3),
}

if __name__ == "__main__":
    model = DomainFusion(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Output: {output}")
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
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 (5,) — shape (5,) 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
LayerCorrectionNetwork Ran
ran on a synthesized input · constructed an object; no result was computed
nokronim/project-safety-remedy/seq2seq/train_hypernetwork_v15.py
code served (permissive licence) · get_code("4241e591d0575aeb")
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, LayerCorrectionNetwork: 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

torch.manual_seed(0)

ARGS = {
    'layer_idx': 0,
    'backbone_hidden': 3584,
    'side_hidden': 896,
    'side_intermediate': 4736,
    'hidden_dim': 512,
    'rank': 32,
    'direction_magnitude_split': False,
    'local_proj_dim': 256,
    'dropout': 0.1,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type LayerCorrectionNetwork — 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 LayerCorrectionNetwork 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
LoRADeltaLambda Ran
ran on a synthesized input · constructed an object; no result was computed
nokronim/project-safety-remedy/seq2seq/train_hypernetwork_v15.py
code served (permissive licence) · get_code("db35166d9498d4a4")
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, LoRADeltaLambda: 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

torch.manual_seed(0)

# Define mean_weights dictionary with the expected keys and shapes
mean_weights = {
    'lambda_classifier.classifier.0.weight': torch.randn(896, 896),
    'lambda_classifier.classifier.0.bias': torch.randn(896),
    'lambda_classifier.classifier.1.weight': torch.randn(896),
    'lambda_classifier.classifier.1.bias': torch.randn(896),
    'lambda_classifier.classifier.4.weight': torch.randn(1, 896),
    'lambda_classifier.classifier.4.bias': torch.randn(1),
}

# Input tensor h with distinct batch and feature dimensions
h = torch.randn(2, 4)

# Define ARGS for LoRADeltaLambda constructor
ARGS = {
    'input_dim': 4,
    'side_hidden': 896,
    'rank': 4,
    'freeze_norm': False,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type LoRADeltaLambda — 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 LoRADeltaLambda 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
LowRankGenerator Ran
ran on a synthesized input · constructed an object; no result was computed
nokronim/project-safety-remedy/seq2seq/train_hypernetwork_v15.py
code served (permissive licence) · get_code("92a98c65e3df7852")
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, LowRankGenerator: 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

torch.manual_seed(0)

class LowRankGenerator(nn.Module):
    """Generate weight matrix via low-rank factorization: W = U @ V."""

    def __init__(self, input_dim: int, out_rows: int, out_cols: int, rank: int):
        super().__init__()
        self.out_rows = out_rows
        self.out_cols = out_cols
        self.rank = rank
        self.to_U = nn.Linear(input_dim, out_rows * rank)
        self.to_V = nn.Linear(input_dim, rank * out_cols)

    def forward(self, h: torch.Tensor) -> torch.Tensor:
        U = self.to_U(h).view(self.out_rows, self.rank)
        V = self.to_V(h).view(self.rank, self.out_cols)
        return U @ V

ARGS = {
    'input_dim': 4,
    'out_rows': 3,
    'out_cols': 5,
    'rank': 2
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type LowRankGenerator — 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 LowRankGenerator 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
MagnitudeEncoder Ran
ran on a synthesized input
nokronim/project-safety-remedy/seq2seq/train_hypernetwork_v15.py
code served (permissive licence) · get_code("78583e50cbc724c4")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 1, dtype family float, shape (16,) as a later run recorded it. The image it ran in was not recorded. 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

class MagnitudeEncoder(nn.Module):
    """Encode per-layer log magnitudes [num_layers] -> [magnitude_hidden_dim]."""

    def __init__(self, num_layers: int=28, hidden_dim: int=128):
        super().__init__()
        self.net = nn.Sequential(nn.Linear(num_layers, hidden_dim), nn.LayerNorm(hidden_dim), nn.GELU(), nn.Linear(hidden_dim, hidden_dim))

    def forward(self, log_magnitudes: torch.Tensor) -> torch.Tensor:
        """
        Args:
            log_magnitudes: [num_layers] log1p of per-layer norms
        Returns:
            [hidden_dim] magnitude encoding
        """
        return self.net(log_magnitudes.float())


INIT_ARGS = {
    "num_layers": 4,
    "hidden_dim": 16,
}

ARGS = {
    "log_magnitudes": torch.randn(4),
}

if __name__ == "__main__":
    model = MagnitudeEncoder(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Output: {output}")
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
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 (16,) — shape (16,) 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
SharedCorrectionNetwork Ran
ran on a synthesized input · constructed an object; no result was computed
nokronim/project-safety-remedy/seq2seq/train_hypernetwork_v15.py
code served (permissive licence) · get_code("74379134a6f30905")
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, SharedCorrectionNetwork: 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

torch.manual_seed(0)

ARGS = {
    'backbone_hidden': 3584,
    'side_hidden': 896,
    'hidden_dim': 512,
    'rank': 32,
    'direction_magnitude_split': False,
    'dropout': 0.1,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type SharedCorrectionNetwork — 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 SharedCorrectionNetwork 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
SmallGenerator Ran
ran on a synthesized input · constructed an object; no result was computed
nokronim/project-safety-remedy/seq2seq/train_hypernetwork_v15.py
code served (permissive licence) · get_code("926c79b52654b1c6")
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, SmallGenerator: 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

torch.manual_seed(0)

ARGS = {
    "input_dim": 4,
    "output_dim": 3,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type SmallGenerator — 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 SmallGenerator 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
is_fixed_key Ran
ran, violated the contract we drafted
nokronim/project-safety-remedy/seq2seq/train_hypernetwork_v15.py
code served (permissive licence) · get_code("189f9f177067f202")
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 bool, ndim 0, dtype family float, shape () as a later run recorded it. The image it ran in was not recorded. 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

# Set random seed for reproducibility
torch.manual_seed(0)

# The function is_fixed_key takes a single parameter 'key' which is a string
# It checks if any of the FIXED_KEY_PATTERNS are contained in that key string

# Test case 1: A key that contains 'ladder_downsample'
test_key_1 = "module.ladder_downsample.weight"

# Test case 2: A key that contains 'ladder_gate'
test_key_2 = "layer.ladder_gate.bias"

# Test case 3: A key that doesn't match any pattern
test_key_3 = "conv.weight"

# We'll use the first test case as the main argument
ARGS = {
    "key": test_key_1
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type bool, ndim 0, dtype family float, shape () — shape () 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
HyperNetworkV15 Not yet run
unverified (harvested, no recorded run)
nokronim/project-safety-remedy/seq2seq/train_hypernetwork_v15.py
code served (permissive licence) · get_code("a1b48721b0ef890b")
How it ran

no invocation recorded.

Also present in other papers' code

Of 11 samples lifted from this paper's linked repositories, 11 carry a function identity and 0 do not. Of the 11 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 11 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.

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-23.

Repositories linked to this paper

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

Abstract

Safety alignment in large language models can be fragile under fine-tuning, as even benign task adaptation may increase harmful compliance. Existing defenses mainly follow two directions: they either intervene during or after fine-tuning through retraining or weight modification, which can be costly and may hurt task performance, or they use model-agnostic safety classifiers, which may miss failures specific to a given fine-tuned checkpoint. These limitations motivate a post-hoc, model-specific, and non-invasive approach to safety restoration. To meet these requirements, we propose HyperSafe, a framework that restores safety behavior by generating a model-specific Safe Side Network (SSN) for each finetuned checkpoint. HyperSafe uses layer-wise activation fingerprints to capture how fine-tuning changes the model's inner representations. With a small set of given calibration prompts, the hypernetwork maps these fingerprints to the parameters of the SSN in a single forward pass. The generated SSN runs alongside the frozen fine-tuned model and performs prompt-level safety classification: harmful prompts are routed to refusal, while safe prompts are answered by the original fine-tuned model. Thus, HyperSafe requires no gradient updates, no safety data at deployment time, and no modification to the deployed model weights. We evaluate HyperSafe on two model families, Qwen2-7B and LLaMA-3-8B, across multiple safety benchmarks. HyperSafe reduces harmful response rates from 19-31% to below 1% on every held-out checkpoint, while keeping downstream task accuracy within 1% of the fine-tuned baseline on average. Code is available at https://github.com/nokronim/project-safety-remedy

For agents

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

get_harvested_code_for_paper("2607.11475")
get_code_for_paper("2607.11475")
have("2607.11475")

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

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

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

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

Connect an agent — have() is free.