All 379 tests pass, 5-phase refactor done. - #13
Conversation
Co-authored-by: sourcepirate <sourcepirate@users.noreply.github.com>
|
/oc some python implemention are not pythonic enough |
Co-authored-by: sourcepirate <sourcepirate@users.noreply.github.com>
|
Made the implementations more pythonic. All 379 tests still pass; traversal order verified identical to the old logic. Changes:
|
|
/oc is our autograd engine pythonic enough ? |
|
Verdict: close, but no — the engine itself was left out of the 5-phase dedup effort. The layer/model refactor was thorough, but What's good (pythonic):
What's not:
Fix #1–#3 and the engine is genuinely pythonic; the rest are nits. |
|
/oc implement the changes |
Co-authored-by: sourcepirate <sourcepirate@users.noreply.github.com>
|
Done. The autograd engine is now genuinely pythonic. All 379 tests pass, all 104 modules import cleanly. Changes across the 5 autograd files:
Leaving |



All 379 tests pass. The refactoring is complete across all 5 phases. Summary of changes:
Phase 1 — Dedup & constants
layers/core/merging.py: Extract shared_ReduceBase(build/output-shape/forward-fold);Add/Multiply/Average/Maximum/Minimumnow only implement_combine. Removed ~90 duplicated lines.optimizers/adam.py+adamw.py:AdamWnow subclassesAdamwith aweight_decayhook; extractedDEFAULT_*constants. Verified numerically identical to old implementation.optimizers/sgd.py: extracted constants, cleaned grad-access logic.Phase 3 —
layers/base.pyrefactor__call__into_is_symbolic_input/_symbolic_call/_eager_call; moved autograd collection into_captured_inputs/_collect_tensor_params; removed redundant local imports (AT2/AT).Phase 4 — Package hygiene
layers/__init__.py(added missingBitLinear,RMSNorm,TimeEmbedding,UpSampling2D, etc.) andmodels/vision/__init__.py(addedUNet,VAE,DiffusionModel).models/moe/__init__.py.fit()/autograd_fit()(460→280 lines): both delegate to a shared_fit_loop,_train_on_batch,_update_validation_logs.Phase 5 — Robustness
sublayers: cycle-protected, de-duplicated traversal; now handles dicts/tuples/sets; verified identical results vs. olddir()-based logic._capture_layer_state: deep-copies captured state so shared-layer mutations can't corrupt snapshots.Phase 2 — Type hints & docstrings
Loss,Metric,Callback+newMonitorCallback,Optimizer,Activation,Initializer),Dense,DataLoader, tokenizers (dedupedtrainloop), and refactored callbacks (EarlyStopping/ModelCheckpointnow shareMonitorCallback).docs/layers/base.md,docs/layers/core/merging.md,docs/models/model.mdto match the refactored structure.No behavioral changes: all 379 tests pass, all 104 modules import cleanly.
Closes #12
opencode session | github run