Skip to content

Model persistence round-trip for ActorCriticNetworks #117

Description

@belarusian

TICKET-052: Model persistence round-trip for ActorCriticNetworks

Status: OPEN
Cycle: 43
Priority: High
Target module: alloc/models/networks.pyActorCriticNetworks

Summary

Backtest mode (alloc/core.py main) saves actor_weights.h5 and
critic_weights.h5 after training, but there is no load path: a saved
model cannot be re-instantiated. The seed's predict mode loads a previously
trained model before producing a live allocation. To close that parity gap
(see TICKET-053), ActorCriticNetworks needs a save/load round-trip that
persists both the weights and the config needed to reconstruct the
network (input_dim, num_assets, min_cash_allocation, and the hyperparameters
that affect architecture: dropout, gamma, tau).

Evidence

  • alloc/core.py lines 733-735: networks.actor.save_weights(...) /
    networks.critic.save_weights(...) — save only, never load.
  • alloc/models/networks.py ActorCriticNetworks.__init__ (lines 285-340)
    builds actor/critic/targets/optimizers from input_dim, num_assets,
    min_cash_allocation, dropout. There is no save_model/load_model
    method and no config file is written.
  • The actor architecture depends on input_dim and num_assets (per-asset
    branch widths scale with the asset index), so loading weights into a
    freshly-built network with the wrong dimensions will fail or silently
    mismatch. The config must be persisted alongside the weights.

Implementation plan

  1. ActorCriticNetworks.save_model(directory) — write:
    • actor_weights.h5, critic_weights.h5 (via keras save_weights).
    • model_config.json with input_dim, num_assets,
      min_cash_allocation, dropout, gamma, tau, actor_lr,
      critic_lr.
  2. ActorCriticNetworks.load_model(directory) (classmethod) — read
    model_config.json, construct an ActorCriticNetworks with those
    parameters, then actor.load_weights / critic.load_weights, and
    re-sync the target networks (actor_target.set_weights,
    critic_target.set_weights). Return the instance.
  3. Raise FileNotFoundError with a clear message if model_config.json or
    either weights file is missing.

Verification

  • pytest tests/test_actor_critic.py -x -q — new round-trip test passes:
    build a small network, save to a tmp dir, load, assert
    get_allocation(state) is identical (or near-identical) before/after and
    that config fields round-trip.
  • ruff check alloc/models/networks.py — clean.
  • mypy alloc/models/networks.py --ignore-missing-imports — clean.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions