Skip to content

[FEATURE] neuron Phase 8 — structural axis: GrowableLinear/LayerNorm + AdamW state 확장 (nn.Parameter 정적 shape 초월 foundations) #55

Description

@juhy0987

배경 — Phase 4~7 의 결론

Phase 시도 결과
4 per-channel α ≈ scalar (Δ=-0.0015,
5 task 확대 (5000step) per_channel ≈ scalar 재확인, implicit pruning 7.7% 발견
6 positional (sinusoidal) α ≈ per_channel (Δ=-0.0001,
7 amplitude smooth-start sinusoidal task-irrelevant 확정 — 모든 init 에서 amplitude 정체

핵심 결론: Phase 4~7 의 모든 gating function 표현력 확장 axis 가 char-LM 에서 동일 final_loss (~1.78) 로 수렴 → gating axis 의 한계 명확. 그러나 Phase 5 의 implicit pruning + Phase 7 의 amplitude decay 모두 gradient 의 "쓸모없는 자유도 자동 비활성화" 능력 입증 → 다음 axis 의 핵심 메커니즘 후보.

paradigm 의 다음 axis = structural (training-time dynamic parameter count 정의에 가장 가까움).

Phase 8 핵심 — nn.Parameter 정적 shape 초월

PyTorch nn.Parameter__init__ 시점에 고정 shape 으로 생성. 학습 중 shape 변경 불가가 paradigm 의 가장 큰 제약. 해결책:

  1. Parameter replacement — 새 expanded shape 의 Parameter 생성 + module attribute 교체 + optimizer state 동시 확장 (AdamW 의 m/v 도 확장)
  2. Function preservation — 새 dim 의 weights 를 적절히 init (zero 또는 identity-style) 하여 forward 결과가 expansion 직후 변하지 않음
  3. AdamW state 보존 — 기존 dim 의 momentum (m) / variance (v) 그대로, 새 dim 은 zero init

이는 bert2BERT (Chen et al. ACL 2022), LiGO (Wang et al. ICLR 2023), MSG (Yuan et al. NeurIPS 2023) 의 expansion 메커니즘과 동일 패러다임.

검증할 가설

  1. AdamW state 보존 시 학습 continuity — expansion 직후 loss spike 없이 학습 지속 가능?
  2. function preservation 효과 — zero-init vs random-init 신규 dim 의 loss curve 차이?
  3. 반복 expansion 안정성 — 여러 번 expansion 후에도 학습 발산 없이 진행?
  4. AdamW state reset vs 보존 — momentum 보존이 실질적 이익 가져옴?

범위 (Phase 8 = foundations)

신규 모듈 — src/graphlm/neuron/growable.py

  • GrowableLinear(in_features, out_features, bias=True) — 표준 nn.Linear 호환 + 두 메서드:
    • expand_out(delta: int, optimizer=None, init: Literal["zero", "normal"]="zero") — out_features += delta
    • expand_in(delta: int, optimizer=None, init: Literal["zero", "normal"]="zero") — in_features += delta
    • Optimizer 주어지면 AdamW state (m, v) 도 함께 확장
  • GrowableLayerNorm(normalized_shape, ...) + expand(delta) (weight=1.0, bias=0.0 init for new dims — identity-preserving)
  • GrowableEmbedding(num_embeddings, embedding_dim) + expand_dim(delta) (output dim 확장만 — vocab 은 별도 이슈)
  • Helper: _expand_param_with_state(param, new_data, optimizer) — Parameter 교체 + optimizer state 확장 (m/v zero 채움) 의 공통 로직

테스트 — tests/neuron/test_growable.py

  • shape after expansion 검증
  • function preservation: zero-init expand 직후 forward output 불변 (atol=1e-6)
  • AdamW state 확장: 기존 dim 의 m/v 보존 + 새 dim 의 m/v = 0
  • step count 보존 (AdamW.step 카운터)
  • 반복 expansion 안정성 (2회 expansion 후에도 정상 동작)

데모 노트북 — notebooks/11-function-level/18-phase8-growable-foundations.ipynb

  • Growable MLP language model (Transformer 아닌 단순 MLP — foundation 검증 우선)
    • input: token embedding (sliding window 4 tokens)
    • hidden: GrowableLinear → GELU → GrowableLayerNorm → GrowableLinear
    • output: tied LM head
  • 학습 1500 step, 매 500 step 마다 hidden width expansion (예: 128 → 192 → 256)
  • 비교 ablation:
    • AdamW state 보존 vs reset
    • zero-init vs random-init expansion
  • 시각화:
    • loss curve (expansion 지점 표시)
    • hidden width 진화 그래프
    • AdamW preserved/reset 의 loss spike 차이

완료 조건

  • GrowableLinear / GrowableLayerNorm / GrowableEmbedding 구현
  • AdamW state 확장 helper 구현
  • 신규 테스트 ≥5건 통과 (shape / function preservation / state 보존 / 반복 expansion)
  • 데모 노트북 실행 — loss curve continuity 확인
  • make lint / make test 통과
  • PR 머지

후속 (Phase 9+ 후보)

| Phase 9 | 본 foundation 을 활용한 Growable Transformer block 구현 (NeuronGrowingDecoder 와 병렬 architecture) |
| Phase 10 | head 수 동적 증가 (head_dim 고정, n_heads 증가 → hidden_dim 자동 확장) |
| Phase 11 | layer 자체 동적 추가 (depth growth, Net2Deeper 와 통합) |

PyTorch 기반 명시

본 프로젝트는 100% PyTorch (TensorFlow / JAX 의존성 없음). Phase 8 도 torch.nn, torch.optim 만 사용. 향후 paradigm 진행 역시 PyTorch 기반 유지.

참고

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions