Repository navigation
fix: zero turnover limit, CAE/SAE minibatch edge cases, attention with no neighbors or long lag - #56
Conversation
A non-positive turnover cap replaced the target book with zeros, which liquidates an existing portfolio instead of forbidding trades. A zero cap now scales weight changes to the previous holdings, and a negative cap is rejected. Co-authored-by: quantum-like <[email protected]>
Hidden beta networks skip one-row minibatches because BatchNorm cannot train on them. When every batch was a single row, fit still returned a converged model whose weights were the random initialization. That fit now fails instead of emitting an untrained beta surface. Co-authored-by: quantum-like <[email protected]>
A configured batch size that left a one-row tail, or a single valid training row, crashed inside BatchNorm during training. Singleton tails are folded into the previous batch, and a one-row sample now raises a clear error before any update. Co-authored-by: quantum-like <[email protected]>
A fully blocked adjacency row, or a node whose only neighbors are missing, produced NaN attention and NaN portfolio weights. Those queries now attend to themselves when present, and otherwise use a finite fallback. Co-authored-by: quantum-like <[email protected]>
When the lag exceeded the window length, the history slice used a negative stop and either crashed or read the end of the same window. Lags that reach past the start of the window now see an empty history. Co-authored-by: quantum-like <[email protected]>
stefan-jansen
left a comment
There was a problem hiding this comment.
Reviewed all five fixes at 077948a. I independently ran the nine added edge-case regressions against main 786ca1b and the submitted implementation: all nine fail on the base and pass with these changes. The fixes are useful, and the five original commits should be retained.
One additional regression must be corrected before merging. MacroGraphAttention now creates a three-dimensional attention mask with shape (batch_size * n_periods, n_assets, n_assets). PyTorch requires its first dimension to include the number of attention heads. The public DeepPortfolioModel.fit workflow with d_model=4, macro_gnn_heads=2, batch_size=2, three periods and two assets fails with an expected mask shape of (12, 2, 2), receiving (6, 2, 2). Both connected and isolated-node graphs fail; corresponding one-head controls pass.
I reproduced those two failures and verified that repeating each per-observation mask across attention heads corrects all four public fit/predict cases. I am appending that focused repair and the regressions to this submission, together with a hardware-qualification fixture that actually exercises a two-head graph containing an isolated node. Existing managed-portfolio, turnover/cost, checkpoint and chunk-invariance checks remain passing. Final-head full/platform/hardware qualification is still required; the unpublished correction is not covered by the current hosted run.
Current submitted-head CI has 31 successful checks, two expected skips, and failures in Dependency Audit and its dependent Qualify Candidate. The audit log identifies urllib3 2.7.0 and virtualenv 21.7.1; the security lock repair belongs in the existing dependency PR #57. These failures are separate from the numerical fixes and must be resolved before ordinary protected integration.
AI assistance: Codex performed this maintainer review, independent reproductions and repair preparation. No release is requested.
Closes #55.
Correct model-training edge cases that previously liquidated holdings, returned untrained CAE parameters, crashed SAE BatchNorm, or produced invalid attention results:
Retain the five original contributor commits and attribution. Append the multi-head correction and four public DeepPortfolioModel fit/predict cases covering one/two heads and isolated/connected assets.
Verification
At 01406ca, with dependency repair #57 integrated:
The zero-limit correction changes prior erroneous liquidation behavior. No release is requested.
AI assistance: The original fix commits retain Cursor Agent attribution. Codex reviewed the submission, prepared the graph-mask correction, and ran maintainer verification.