[EN] This document delivers the technical specifications and mathematical mechanics regarding the Optax Optimizer Engine Architectural Overhaul achieved via migrating from CR_egregore_jax_test.py to CR_egregore_jax_test_v2.py. It provides a rigorous computational resolution to both XLA graph fragmentation and host-side memory leaks previously encountered during LLM and MoE acceleration pipelines.
[KR] ๋ณธ ๋ฌธ์๋ CR_egregore_jax_test.py์์ CR_egregore_jax_test_v2.py๋ก์ ๋ง์ด๊ทธ๋ ์ด์
์ ํตํด ๋ฌ์ฑํ Optax ์ตํฐ๋ง์ด์ ์์ง ์ํคํ
์ฒ ๊ฐํธ๊ณผ ๊ด๋ จ๋ ๊ธฐ์ ์ ๋ช
์ธ ๋ฐ ์๋ฆฌ ์ญํ์ ๊ฐ์ ์ฌํญ์ ๋ค๋ฃน๋๋ค. LLM ๋ฐ MoE ๊ฐ์ํ ๊ณผ์ ์์ ๋ฐ์ํ๋ XLA ๊ทธ๋ํ ํํธํ์ ํธ์คํธ ๋ฉ๋ชจ๋ฆฌ ๋์ ๋ฌธ์ ๋ฅผ ์ ์ฐํ์ ์ผ๋ก ํด๊ฒฐํ์ต๋๋ค.
1. ์ต์ ํ ์์ง: ๋จ์ผ ์ตํฉ ์ปค๋ ํ์ฑ (Optimization Engine: Single Fused Kernel Formulation)
โ ๊ตฌ ๋ฒ์ (Conventional Baseline - CR_egregore_jax_test.py): ๋ค์ค ๋ถ๊ธฐ ๋ ์ผ (Multi-Transform Rails)
[EN]
- Implementation: Invoked
optax.multi_transformto execute hardware-level physical branching overbackboneandgatenodes based on Python dictionary key paths. - Flaw: The XLA compiler generated numerous dynamic instruction routing branches at the device level, triggering severe Graph Fragmentation and critical branch stalls.
[KR]
- ๊ตฌํ ๋ฐฉ์:
optax.multi_transform์ ํธ์ถํ์ฌ ํ์ด์ฌ ๋์ ๋๋ฆฌ ํค ๊ฒฝ๋ก๋ฅผ ๊ธฐ๋ฐ์ผ๋กbackbone๊ณผgate๋ ธ๋๋ฅผ ๋ฌผ๋ฆฌ ๋ถ๊ธฐํ์ต๋๋ค. - ๋ฌธ์ ์ : XLA ์ปดํ์ผ๋ฌ๊ฐ ์ฅ์น(Device) ๋จ์์ ์๋ง์ ๋ช ๋ น์ด ๋ถ๊ธฐ ํ๋ฆ์ ์์ฑํ์ฌ ๊ทธ๋ํ ํํธํ(Graph Fragmentation) ๋ฐ ๋ถ๊ธฐ ์คํจ์ ์ ๋ฐํ์ต๋๋ค.
โจ ์ ๋ฒ์ (Advanced Paradigm - CR_egregore_jax_test_v2.py): ์์ ์ค๋ฆฌ์ฝ MUX ๋ ์ผ (Pure Silicon MUX Rails)
[EN]
- Implementation: Spans a single underlying
optax.adam(learning_rate=1.0)engine stripped of native weight decay to perfectly unify and track pristine momentum accumulation. - Improvement: Executes inline control entirely through dynamic f32 literal register masks and algebraic Hadamard Products, which are highly optimized for accelerator ALUs. This force-fuses a zero-stall Single Fused Kernel directly inside the on-chip memory layout.
[KR]
- ๊ตฌํ ๋ฐฉ์: ๊ฐ์ค์น ๊ฐ์ ๋ฅผ ๋ฐฐ์ ํ ๋จ์ผ
optax.adam(learning_rate=1.0)์์ง์ผ๋ก ์ ๋ฅ (Momentum)์ ๊นจ๋ํ๊ฒ ํตํฉ ์ถ์ ํฉ๋๋ค. - ๊ฐ์ ํจ๊ณผ: ์ธ๋ถ์์ ๊ฐ์๊ธฐ ALU๊ฐ ๊ฐ์ฅ ์ ํธํ๋ f32 ๋ฆฌํฐ๋ด ๋ง์คํฌ์ ์๋ค๋ง๋ฅด ๊ณฑ(Hadamard Product) ๋์์๋ง์ผ๋ก ์ธ๋ผ์ธ ์ ์ดํฉ๋๋ค. ์ด๋ฅผ ํตํด ๋ถ๊ธฐ ์คํจ์ด ์กด์ฌํ์ง ์๋ **๋จ์ผ ์ตํฉ ์ปค๋(Fused Kernel)**์ ๊ฐ์ ํ์ฑํฉ๋๋ค.
2. ๊ฐ์ค์น ๊ฐ์ ์๋ฆฌ ์ญํ: ์ด์ค ๊ฐ์ ๋ฐ๋ฉธ (Weight Decay Mechanics: Eradicating Double-Dipping)
[EN]
- Implementation: Individually invoked
optax.adamwwithin each divided sub-optimizer track. - Flaw: When integrated with the Layer-wise Learning Rate Decay (LLRD) mask, the weight decay coefficients were inherently distorted as they leaked directly into the Adam internal momentum equations, triggering a critical Double-Dipping defect.
[KR]
- ๊ตฌํ ๋ฐฉ์: ๋ถ๊ธฐ๋ ํ์ ์ตํฐ๋ง์ด์ ๋ด๋ถ์์ ๊ฐ๋ณ์ ์ผ๋ก
optax.adamw๋ฅผ ํธ์ถํ์ต๋๋ค. - ๋ฌธ์ ์ : ๊ณ์ธต๋ณ ์ฐจ๋ฑ ํ์ต๋ฅ (LLRD) ๋ง์คํฌ์ ๊ฒฐํฉํ ๋, Adam ๋ด๋ถ ๋ชจ๋ฉํ ๊ณ์ฐ ์์ ๊ฐ์ค์น ๊ฐ์ ๊ณ์๊ฐ ์์ฒ ์๊ณก๋์ด ์ ์ ๋๋ ์ด์ค ๊ฐ์ (Double-Dipping) ๊ฒฐํจ์ด ๋ฐ์ํ์ต๋๋ค.
[EN]
- Implementation: Implanted the algebraic sign synchronization formulation rigorously proved in (
PJHkorea/egregore-core-jax/README_OPTIMIZERS.md) directly into the core segment. - Improvement: Reconstructs pristine, original AdamW LLRD specifications directly on accelerator memory layout without triggering any momentum vector distortions.
[KR]
- ๊ตฌํ ๋ฐฉ์: (
PJHkorea/egregore-core-jax/README_OPTIMIZERS.md)์ ์ฆ๋ช ๋ ๋์์ ๋ถํธ ํฉ์น ๊ณต์์ ์ฝ์ด ์ธ๊ทธ๋จผํธ์ ์ด์ํ์ต๋๋ค. - ๊ฐ์ ํจ๊ณผ: ๊ฐ์๊ธฐ ๋ฉ๋ชจ๋ฆฌ์์์ ๋ชจ๋ฉํ ์๊ณก ์์ด ์ค๋ฆฌ์ง๋ AdamW LLRD ๊ณต์ ๊ท๊ฒฉ์ ์ฌํํฉ๋๋ค.
[EN]
-
$u$ : Adam momentum update delta vector -
$\text{lr}$ : Layer-wise Learning Rate Decay (LLRD) scaler -
$p$ : Current weight parameter tensor -
$\text{wd}$ : Weight decay coefficient
[KR]
-
$u$ : Adam ๋ชจ๋ฉํ ์ ๋ฐ์ดํธ ๋ฒกํฐ -
$\text{lr}$ : ๊ณ์ธต๋ณ ์ฐจ๋ฑ ํ์ต๋ฅ (LLRD) -
$p$ : ํ์ฌ ๊ฐ์ค์น ๋งค๊ฐ๋ณ์ (Parameter) -
$\text{wd}$ : ๊ฐ์ค์น ๊ฐ์ ๊ณ์ (Weight Decay)
๐ก Computational Sign Synchronization Spec (Supplementary)
[EN] The raw
updates($u$ ) vector returned by the underlyingoptax.adambackend natively incorporates the Negative Gradient Direction so it can be directly integrated via parameter addition (params = params + updates). Therefore, to achieve seamless synchronization with the negative scaling trajectory of the Weight Decay componentโwhich physically shrinks parameter magnitudeโcoupling the two components via algebraic addition ($+$ ) instead of subtraction ($-$ ) is the mathematically and numerically accurate implementation.[KR]
optax.adam๋ฐฑ์๋๊ฐ ์์ฒด ์ฐ์ฐ์ ๊ฑฐ์ณ ๋ฐํํ๋updates($u$ ) ๋ฒกํฐ๋ ๊ฐ์ค์น์ ๋ฐ๋ก ๋ํด์ง ์ ์๋๋ก ์ด๋ฏธ **์์ ๋ณ์ ๋ฐฉํฅ์ฑ(Negative Gradient Direction)**์ด ๋ด์ฅ๋์ด ์์ต๋๋ค. ๋ฐ๋ผ์ ๊ฐ์ค์น๋ฅผ ๋ฌผ๋ฆฌ์ ์ผ๋ก ์ค์ฌ์ผ ํ๋ Weight Decay ์ฑ๋ถ์ ์์ ์ค์ผ์ผ๋ง ๋ฐฉํฅ๊ณผ ๋ฌด๊ฒฐํ๊ฒ ๋๊ธฐํํ๊ธฐ ์ํด ๋์ํ์ ์ผ๋ก ๋นผ๊ธฐ($-$ )๊ฐ ์๋ ๋ํ๊ธฐ($+$ ) ๊ธฐํธ๋ก ๊ฒฐํฉํ๋ ๊ฒ์ด ์์นํด์์ ์ผ๋ก ์์ ํ ์ฌ๋ฐ๋ฅธ ๊ตฌํ์ ๋๋ค.
3. ํธ์คํธ ๋ฉ๋ชจ๋ฆฌ ์ธํ๋ผ: ์ค๋ณต ํธ๋ ์ด์ฑ ๋ฐ ํ์ ํฌ๋์ ์ ๋กํ (Host Memory Infrastructure: Zero Tracing Overhead & Type Safety)
[EN]
- Implementation: Relied on heavy and complex hyperparameter conditional routing logic due to the lack of an embedded, standardized LLRD scaling mechanism.
- Flaw: Exponentially inflated static tracing overhead over the host CPU when compiling large-scale deep learning models.
[KR]
- ๊ตฌํ ๋ฐฉ์: LLRD ์ค์ผ์ผ๋ฌ ์์ฒด๊ฐ ๋ด์ฅ๋์ด ์์ง ์์ ๋ณต์กํ ํ์ดํผํ๋ผ๋ฏธํฐ ๋ถ๊ธฐ ๋ก์ง์ ์์กดํ์ต๋๋ค.
- ๋ฌธ์ ์ : ๊ฑฐ๋ ๋ชจ๋ธ ์ปดํ์ผ ์ ํธ์คํธ CPU์ ์ ์ ํธ๋ ์ด์ฑ ์ค๋ฒํค๋๊ฐ ๊ธ์ฆํ์ต๋๋ค.
[EN]
- Implementation: Structurally compressed and restricted the
tree_flatten_with_pathinvocation to exactly a Single-Pass (1 Time) execution sequence inside the scheduler loop. - Mechanism: Established a high-density
[LEAF-LEVEL TENSOR RECONSTRUCTION]pipeline that pairs lightweightmapped_scalarswith original leaf weights (v) viazipprimitives for deferred device-level tensor allocations. - Improvement: Computationally purged host-side CPU memory leaks and eliminated catastrophic Host OOM (Out-Of-Memory) Crashes during massive LLM and MoE model compilation phases.
[KR]
- ๊ตฌํ ๋ฐฉ์:
tree_flatten_with_pathํธ์ถ์ ์ค์ผ์ค๋ฌ ๋ฃจํ ๋ด์์ ์ ํํ ๋จ 1ํ๋ก ํ๊ณ ์์ถํ์ต๋๋ค. - ๊ธฐ๋ฏน ๋์
:
mapped_scalars์ ์๋ณธ ๋ฆฌํ ๊ฐ์ค์น v๋ฅผzip์ผ๋ก ๋ฌถ์ด ํ ์๋ฅผ ์ฌํ ํ์ฅํ๋[LEAF-LEVEL TENSOR RECONSTRUCTION]๋งค์ปค๋์ฆ์ ์ ์ฐฉ์์ผฐ์ต๋๋ค. - ๊ฐ์ ํจ๊ณผ: ๊ฑฐ๋ LLM/MoE ๋ชจ๋ธ ์ปดํ์ผ ์ ๋ฐ์ํ๋ ํธ์คํธ CPU์ ๋ฉ๋ชจ๋ฆฌ ๋์ ๋ฐ Host OOM(Out-Of-Memory) ํฌ๋์๋ฅผ ์ ์ฐํ์ ์ผ๋ก ํด๊ฒฐํ์ต๋๋ค.
| Evaluation Metric | Baseline (CR_egregore_jax_test.py) |
Advanced Paradigm (CR_egregore_jax_test_v2.py) |
Architectural Impact |
|---|---|---|---|
| Optimizer Topology |
optax.multi_transform (Physical Branching) |
Single optax.adam + Inline Masking |
Compilation Graph Optimization |
| XLA Kernel Footprint | Fragmented instruction routing paths | Single Fused Kernel (Force-Fused) | Zero Hardware Branch Stalls |
| Mathematical Precision | Inherent momentum dynamics distortion | 100% Exact AdamW LLRD Formulation | Algebraic Sign Synchronization ( |
| Host Compilation Stability | Redundant tracing & Host OOM vulnerability | Single-Pass Squeeze & Leaf-Level Reconstruction | Total Elimination of CPU Memory Leaks |
[EN]
- v1 (optax.multi_transform): Navigating the parameter PyTree to separate
backboneandgatenodes caused the XLA compiler to generate fragmented sub-graphs and induced repetitive host-interpreter interventions. This accumulated severe scheduling latency and device-level kernel launch overheads. - v2 (Silicon MUX Engine): Integrates the entire routing mechanics into a single, unified mathematical equation graph. By leveraging the pre-baked
lr_mask_treeandwd_mask_tree, parameter updates are finalized inside a single-cycle Hadamard tensor product kernel. This thoroughly obliterates host-device synchronization bottlenecks, drastically shrinking optimizer execution time.
[KR]
- v1 (optax.multi_transform): ํ๋ผ๋ฏธํฐ ํธ๋ฆฌ๋ฅผ ์ํํ๋ฉฐ backbone๊ณผ gate ๋ ธ๋๋ฅผ ๋ถ๊ธฐํ ๋, XLA๋ ๋ด๋ถ์ ์ผ๋ก ๋ถํ๋ ๊ฐ์ ์๋ธ ๊ทธ๋ํ(Sub-graphs)๋ค์ ์์ฑํ๊ฑฐ๋ ํธ์คํธ(Host) ์ธํฐํ๋ฆฌํฐ์ ๊ฐ์ ์ ์ ๋ฐํฉ๋๋ค. ์ด๋ก ์ธํด ๋๋ฐ์ด์ค ์ค์ผ์ค๋ง ๋ฐ ์ปค๋ ๋ฐ์น(Kernel Launch) ์ค๋ฒํค๋๊ฐ ๋์ ๋ฉ๋๋ค.
- v2 (์ค๋ฆฌ์ฝ MUX ์์ง): ๋จ ํ๋์ ๊ฑฐ๋ํ ํต์ผ๋ ์์ ๊ทธ๋ํ๋ก ํตํฉ๋์์ต๋๋ค. ์ด๋ฏธ ์์ฑ๋
lr_mask_tree์wd_mask_tree๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๋จ ํ ๋ฒ์ ์๋ค๋ง๋ฅด ํ๋ ฌ๊ณฑ ์ปค๋ ์์์ ๊ฐ์ค์น ์ ๋ฐ์ดํธ๊ฐ ๋๋ฉ๋๋ค. ํธ์คํธ-๋๋ฐ์ด์ค ๊ฐ ๋๊ธฐํ ๋ณ๋ชฉ์ด ์์ ํ ๊ฑฐ์ธ๋์ด ์ตํฐ๋ง์ด์ ๊ฐ๋ ์๊ฐ์ด ํ๊ธฐ์ ์ผ๋ก ๋จ์ถ๋ฉ๋๋ค.
[EN]
- v1 (String-Product Algebraic Masking): Although v1 avoided conditional branches via string product masking (
"gate" * (root_key_name == "gate")), it still relied heavily on string manipulation, variable-length text allocations, and dynamic sequence evaluation at the host-compiler boundary. This prevented the XLA compiler from achieving full register-level inline numerical scaling. - v2 (Pure FP32 Register MUX): Converts matching predicates directly into accelerator-native floating-point literals via
is_gate = (root_key_name == "gate") * jnp.float32(1.0). By completely extinguishing string data execution footprints, the instruction stream forces the accelerator ALU to perform raw, single-cycle algebraic mixing over steady 32-bit register rails, maximizing raw silicon computing efficiency.
[KR]
- v1 (๋ฌธ์์ด ๊ณฑ์
๋์ ๋ง์คํน): ๊ตฌ ๋ฒ์ ์ญ์
"gate" * (root_key_name == "gate")์ ๊ฐ์ ๋ฌธ์์ด ๊ณฑ์ ๊ธฐ๋ฏน์ ํตํด ๋ฐํ์if/else๋ถ๊ธฐ๋ฌธ์ ํํผํ์ผ๋, ์ฌ์ ํ ๋ฌธ์์ด ๋ฐ์ดํฐ์ ๋์ ๋ฉ๋ชจ๋ฆฌ ํ ๋น๊ณผ ํ ์คํธ ์ํ์ค ์ฐ์ฐ ์ค๋ฒํค๋๊ฐ ์ปดํ์ผ๋ฌ ๊ฒฝ๊ณ๋ฉด์ ์์กดํ์ฌ ์์ ํ ์์น ํด์์ ์ธ๋ผ์ธํ๋ฅผ ๋ฌ์ฑํ์ง ๋ชปํ์ต๋๋ค. - v2 (์์ FP32 ๋ ์ง์คํฐ MUX): ์ผ์น ์ฌ๋ถ ํ์ ๊ฒฐ๊ณผ๋ฅผ
is_gate = (root_key_name == "gate") * jnp.float32(1.0)์ ๊ฐ์ด ๊ฐ์๊ธฐ ๋ค์ดํฐ๋ธ ๋ถ๋์์์ ๋ฆฌํฐ๋ด ๋ง์คํฌ๋ก ์ฆ์ ์์ถ์์ผฐ์ต๋๋ค. ๋ฌธ์์ด ์ฐ์ฐ์ ํ์ ์ ์ ์ฐ๋ง์์ ์๋ฒฝํ ๋ฐ๋ฉธํจ์ผ๋ก์จ, ๊ฐ์๊ธฐ ALU๊ฐ 32๋นํธ ๋ ์ง์คํฐ ๋ ์ผ ์์์ ๋จ 1ํด๋ญ์ ์ง์ฐ๋ ์์ด ์์ ๋ถ๋์์์ ๋์ ์ฐ์ฐ๋ง์ผ๋ก ์ฐจ๋ฑ ๊ฐ์ค์น ์ ๋ฐ์ดํธ๋ฅผ ์งํํ๋๋ก ํ๋์จ์ด ๋ฐ์ฐฉํ ์ต์ ํ๋ฅผ ์์ฑํ์ต๋๋ค.
[EN]
- Aggressive Kernel Fusion: By purging explicit
jnp.whereconditional blocks and organically coupling XLA-native hardware primitives (jnp.sign,jnp.reciprocal,jnp.einsum), the XLA compiler executes highly aggressive 'Kernel Fusion'. Intermediate tensors are immediately consumed inside high-speed on-chip registers/SRAM instead of being redundantly read/written over the high-latency global memory (VRAM) bus. - Lazy Evaluation Contamination Shielding: Explicitly seals every telemetry metric and loss artifact with
jax.lax.stop_gradient. This systematically cuts off unreferenced backpropagation computational graphs from permanently occupying device memory, preventing HBM leakage. It dramatically expands the system threshold when handling ultra-large batch configurations or high-dimensional latent space layers without triggering OOM (Out of Memory) exceptions.
[KR]
- ๊ณต๊ฒฉ์ ์ปค๋ ์ตํฉ (Kernel Fusion):
jnp.where์กฐ๊ฑด์ ๋ถ๊ธฐ๋ฅผ ์ง์ฐ๊ณ XLA ์ ์ฉ ํ๋ฆฌ๋ฏธํฐ๋ธ์ธjnp.sign,jnp.reciprocal,jnp.einsum๋ฑ์ ์ ๊ธฐ์ ์ผ๋ก ์ฐ๊ฒฐํ์ต๋๋ค. ์ด ๋๋ถ์ XLA ์ปดํ์ผ๋ฌ๋ ์ค๊ฐ ํ ์(Intermediate Tensors)๋ค์ ๊ธ๋ก๋ฒ ๋ฉ๋ชจ๋ฆฌ(VRAM)์ ์ผ๋ค ์ฝ์ง ์๊ณ , ๊ณ ์ ์จ์นฉ ๋ ์ง์คํฐ/SRAM ์์์ ์ฐ์ฐ์ ๋ฌถ์ด ์ฒ๋ฆฌํ๋ '์ปค๋ ์ตํฉ'์ ํจ์ฌ ๊ณต๊ฒฉ์ ์ผ๋ก ์ํํฉ๋๋ค. - ์ง์ฐ ํ๊ฐ(Lazy Evaluation) ์ค์ผ ๋ฐฉ์ง: ๊ฐ ๋ฉํธ๋ฆญ๊ณผ ์์ค ํจ์ ์ํฐํฉํธ๋ง๋ค
jax.lax.stop_gradient๋ฅผ ๊ผผ๊ผผํ๊ฒ ๋ฐฐ์นํ์ฌ, ๋ถํ์ํ ์ญ์ ํ ๋ฏธ๋ถ ๊ทธ๋ํ๊ฐ ๊ฐ์๊ธฐ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ ์ ํ๊ณ ์๋ ํ์(๋ฉ๋ชจ๋ฆฌ ๋์ ๋ฐ HBM ๊ณ ๊ฐ)์ ์์ฒ ์ฐจ๋จํ์ต๋๋ค. ๋ฐฐ์น ํฌ๊ธฐ๋ฅผ ๋ ํค์ฐ๊ฑฐ๋ ์ด๊ณ ์ฐจ์ latent ์ฐ์ฐ์ ์ํํ ๋ OOM ๋ฐ์ ํ๋ฅ ์ ํฌ๊ฒ ๋ฎ์ถฐ์ค๋๋ค.
- This project is governed by the GPLv3 License. Derivative models, framework re-engineering fork scripts, and computational extensions of identical architecture cannot be made proprietary; they must be fully disclosed and distributed to the public under the exact same open-source licensing terms.