AQIT 0.1.0
Loading...
Searching...
No Matches
loader_shim.py
Go to the documentation of this file.
1# Copyright (c) 2025-present Aquin Labs Private Limited. All Rights Reserved.
2# This file is part of the Aquin Engine. Unauthorized copying, modification,
3# distribution, or use of this file, via any medium, is strictly prohibited.
4# Proprietary and confidential. See LICENSE for terms.
5
6"""
7Patches ingested compute modules so load_model/load_sae delegate to
8aquin.compute.model_loader — same model object as aquin load.
9Call apply() once at engine startup before any tool invocation.
10"""
11from __future__ import annotations
12
13_applied = False
14
15
16def apply() -> None:
17 global _applied
18 if _applied:
19 return
20 _applied = True
21
22 import aquin.compute.causal_trace as _ct
24 import aquin.compute.model_loader as _ml
25
26 # Patch causal_trace.load_model → model_loader.load_model (same signature)
27 _ct.load_model = _ml.load_model
28
29 # Patch feature_analysis.load_sae to accept (model_id, layer=None) → _ml.load_sae
30 def _shim_load_sae(model_id: str, layer: int | None = None):
31 short = _ml.resolve_model_id(model_id)
32 cfg = _ml.get_config(short)
33 resolved_layer = int(layer if layer is not None else cfg["sae_layer"])
34 if layer is not None:
35 resolved_layer = _ml.require_sae_layer(
36 short,
37 resolved_layer,
38 command="trace",
39 )
40 model = _ml.get_loaded_model()
41 if model is None:
42 model = _ml.load_model(short)
43 return _ml.load_sae(model, resolved_layer, short)
44
45 _fa.load_sae = _shim_load_sae