SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2404.16897 · IJCAI · 2024

Exploring Learngene via Stage-wise Weight Sharing for Initializing Variable-sized Models

Xin Geng, Xu Yang, Shi-Yu Xia, Wenxuan Zhu

arXiv · PDF · Open in the Atlas

Code that ran

3 of 7 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (3 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 3 have no contract verdict; 0 failures of our instrument; 4 no recorded run), measured 2026-11-22; 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/2404.16897.json · badge: /api/ran/2404.16897.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
AlphaXia/SWS community
Papers with Code archive
3 ran · 4 no recorded run
FunctionStatusWhere it lives
RepeatedModuleList Ran
ran on a synthesized input · constructed an object; no result was computed
AlphaXia/SWS/SWS_vit.py
code served (permissive licence) · get_code("64976ec8888722fc")
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, RepeatedModuleList: 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)

# Create a simple sublist instance class
class SimpleLayer(nn.Module):
    def __init__(self, in_features, out_features, *args, **kwargs):
        super().__init__()
        self.linear = nn.Linear(in_features, out_features)
    
    def forward(self, x):
        return self.linear(x)

# Create a default instance class
class DefaultLayer(nn.Module):
    def __init__(self, in_features, out_features, *args, **kwargs):
        super().__init__()
        self.linear = nn.Linear(in_features, out_features)
    
    def forward(self, x):
        return self.linear(x)

# Define the arguments
ARGS = {
    "Layer_num": 5,
    "sublist_repeated_times": [2, 3],
    "sublist_with_flag": [True, False],
    "Sublist_instance": SimpleLayer,
    "Default_instance": DefaultLayer,
    "in_dim": [4, 5],
    "out_dim": [5, 6],
    "args": (),
    "kwargs": {}
}
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 RepeatedModuleList — 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 RepeatedModuleList 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
RepeatedModuleList_norm Ran
ran on a synthesized input · constructed an object; no result was computed
AlphaXia/SWS/SWS_vit.py
code served (permissive licence) · get_code("29a374042377c6d7")
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, RepeatedModuleList_norm: 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)

# Create a simple stand-in Layer class
class SimpleLayer(nn.Module):
    def __init__(self, *args, normalized_shape=None, **kwargs):
        super().__init__()
        self.normalized_shape = normalized_shape
        if normalized_shape is not None:
            self.norm = nn.LayerNorm(normalized_shape)
        else:
            self.norm = nn.Identity()
    
    def forward(self, x):
        return self.norm(x)

# Create a Default instance class
class DefaultLayer(nn.Module):
    def __init__(self, *args, normalized_shape=None, **kwargs):
        super().__init__()
        self.normalized_shape = normalized_shape
        if normalized_shape is not None:
            self.norm = nn.LayerNorm(normalized_shape)
        else:
            self.norm = nn.Identity()
    
    def forward(self, x):
        return self.norm(x)

# Set up parameters
Layer_num = 5
sublist_repeated_times = [2, 1, 2]  # sum = 5
sublist_with_flag = [True, False, True]  # len = 3
normalized_dim = [4, 3, 5]  # len = 3, matching number of sublists
Sublist_instance = SimpleLayer
Default_instance = DefaultLayer

ARGS = {
    'Layer_num': Layer_num,
    'sublist_repeated_times': sublist_repeated_times,
    'sublist_with_flag': sublist_with_flag,
    'Sublist_instance': Sublist_instance,
    'Default_instance': Default_instance,
    'normalized_dim': normalized_dim,
    'args': (),
    'kwargs': {}
}
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 RepeatedModuleList_norm — 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 RepeatedModuleList_norm 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
SWS_Attention Ran
ran on a synthesized input · constructed an object; no result was computed
AlphaXia/SWS/SWS_vit.py
code served (permissive licence) · get_code("0d6ecc7d0008b522")
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, SWS_Attention: 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)

# Small tensor dimensions: 4 for embedding dim, 3 for sequence length
dim = [4]  # embedding dimension
num_heads = [2]  # number of attention heads
qkv_bias = False
qk_scale = None
attn_drop = 0.1
proj_drop = 0.1

# Create repeated_times_schedule dict
# For a 4-layer model with varying attention configurations
repeated_times_schedule = {
    'attn_qkv': (
        [2, 1, 1],  # 2 layers use first config, 1 layer uses second, 1 layer uses third
        [True, True, False]  # flags for each sublist
    ),
    'attn_proj': (
        [2, 1, 1],  # same structure as attn_qkv
        [True, True, False]  # flags for each sublist
    ),
    'dim': [4, 4, 4]  # input/output dimensions for each sublist (must match number of sublists)
}

num_layers = 4  # total number of layers (sum of repeated_times)

ARGS = {
    'dim': dim,
    'num_heads': num_heads,
    'qkv_bias': qkv_bias,
    'qk_scale': qk_scale,
    'attn_drop': attn_drop,
    'proj_drop': proj_drop,
    'repeated_times_schedule': repeated_times_schedule,
    'num_layers': num_layers
}
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 SWS_Attention — 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 SWS_Attention 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
RepeatedLEBlock Not yet run
unverified (harvested, no recorded run)
AlphaXia/SWS/SWS_vit.py
code served (permissive licence) · get_code("5eabd45424bf9f22")
How it ran

no invocation recorded.

SWS_Block Not yet run
unverified (harvested, no recorded run)
AlphaXia/SWS/SWS_vit.py
code served (permissive licence) · get_code("18de19c2cb8d3fef")
How it ran

no invocation recorded.

SWS_Mlp Not yet run
unverified (harvested, no recorded run)
AlphaXia/SWS/SWS_vit.py
code served (permissive licence) · get_code("4c8baad6b19e7abd")
How it ran

no invocation recorded.

VisionTransformer Not yet run
unverified (harvested, no recorded run)
AlphaXia/SWS/SWS_vit.py
code served (permissive licence) · get_code("be0e5172207a25d4")
How it ran

no invocation recorded.

Also present in other papers' code

Of 7 samples lifted from this paper's linked repositories, 7 carry a function identity and 0 do not. Of the 7 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 7 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-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

In practice, we usually need to build variable-sized models adapting for diverse resource constraints in different application scenarios, where weight initialization is an important step prior to training. The Learngene framework, introduced recently, firstly learns one compact part termed as learngene from a large well-trained model, after which learngene is expanded to initialize variable-sized models. In this paper, we start from analysing the importance of guidance for the expansion of well-trained learngene layers, inspiring the design of a simple but highly effective Learngene approach termed SWS (Stage-wise Weight Sharing), where both learngene layers and their learning process critically contribute to providing knowledge and guidance for initializing models at varying scales. Specifically, to learn learngene layers, we build an auxiliary model comprising multiple stages where the layer weights in each stage are shared, after which we train it through distillation. Subsequently, we expand these learngene layers containing stage information at their corresponding stage to initialize models of variable depths. Extensive experiments on ImageNet-1K demonstrate that SWS achieves consistent better performance compared to many models trained from scratch, while reducing around 6.6× total training costs. In some cases, SWS performs better only after 1 epoch tuning. When initializing variable-sized models adapting for different resource constraints, SWS achieves better results while reducing around 20× parameters stored to initialize these models and around 10× pre-training costs, in contrast to the pre-training and fine-tuning approach.

For agents

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

get_harvested_code_for_paper("2404.16897")
get_code_for_paper("2404.16897")
have("2404.16897")

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

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

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

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

Connect an agent — have() is free.