|
AQIT 0.1.0
|
Classes | |
| class | SimulateRequest |
| class | CompareRequest |
Functions | |
| bool | _is_heavy_sim_model (dict[str, Any] cfg) |
| int | _sim_batch_limit (dict[str, Any] cfg) |
| list[torch.Tensor] | _grad_vector (torch.Tensor loss, list[torch.nn.Parameter] params, bool retain_graph=False) |
| list[torch.Tensor] | _hvp (torch.Tensor loss, list[torch.nn.Parameter] params, list[torch.Tensor] v) |
| list[torch.Tensor] | _hvp_from_fn (loss_fn, list[torch.nn.Parameter] params, list[torch.Tensor] v) |
| float | _grad_dot (list[torch.Tensor] ga, list[torch.Tensor] gb) |
| float | _tensor_list_norm (list[torch.Tensor] ts) |
| float | _normalized_influence (list[torch.Tensor] ga, list[torch.Tensor] gb) |
| list[torch.Tensor] | _lissa_inverse_hvp (test_loss_fn, train_loss_fn, int n_train, list[torch.nn.Parameter] params, float scale=25.0, float damping=0.05, int n_iter=10) |
| list[dict] | _influence_via_grad_dot (test_loss_fn, list[int] train_indices, list[dict] rows, list[torch.nn.Parameter] params, train_loss_fn) |
| dict[int, float] | _ntk_diagonal (torch.Tensor loss, list[torch.nn.Parameter] params, list[torch.Tensor] grads) |
| float | _power_iteration_max_eigenvalue (torch.Tensor loss, list[torch.nn.Parameter] params, int n_iter=3) |
| int | _hidden_state_index (model, int sae_layer) |
| torch.Tensor|None | _sae_grad_scores_from_batch (model, sae, int sae_layer, torch.Tensor input_ids, torch.Tensor attention_mask, torch.Tensor|None base_acts_mean) |
| dict[str, Any] | _run_dataset_quality (list[dict] rows) |
| dict | _detect_ai_generated (list[dict] rows) |
| None | _run_simulation (SimulateRequest req, asyncio.Queue queue, asyncio.AbstractEventLoop loop) |
| training_simulate (SimulateRequest req) | |
| Any | _sanitize (Any obj) |
| dict | compare_simulation_results (dict result_a, dict result_b, str label_a="Run A", str label_b="Run B", *, str run_id_a="", str run_id_b="") |
| compare_simulations (CompareRequest req) | |
Variables | |
| router = APIRouter() | |
| DEVICE = resolve_compute_device() | |
| DTYPE = default_dtype_for_device(DEVICE) | |
| int | _SIM_MAX_SAMPLES = 64 |
| str | _SIM_FT_CKPT_PATH = None |
| str | _SIM_FT_MODEL_ID = None |
| list | _HARMFUL_KEYWORDS |
| list | _AI_FINGERPRINTS |
|
protected |
Check if >30% of responses match common AI generation fingerprints.
Definition at line 445 of file train_simulate.py.
Referenced by _run_dataset_quality().
|
protected |
Definition at line 167 of file train_simulate.py.
Referenced by _normalized_influence().
|
protected |
Detached per-parameter gradient vector for loss.
Definition at line 130 of file train_simulate.py.
Referenced by _influence_via_grad_dot(), _lissa_inverse_hvp(), and _run_simulation().
|
protected |
Map SAE layer index → output_hidden_states tuple index.
Definition at line 284 of file train_simulate.py.
Referenced by _sae_grad_scores_from_batch().
|
protected |
Hessian-vector product H·v via double backprop.
Definition at line 142 of file train_simulate.py.
Referenced by _hvp_from_fn(), _ntk_diagonal(), and _power_iteration_max_eigenvalue().
|
protected |
HVP with a fresh forward inside : avoids reusing freed loss graphs.
Definition at line 156 of file train_simulate.py.
References _hvp().
Referenced by _lissa_inverse_hvp().
|
protected |
First-order influence: -∇L_test · ∇L_train (no Hessian). Reliable on PEFT/LoRA.
Definition at line 219 of file train_simulate.py.
References _grad_vector(), and _normalized_influence().
Referenced by _run_simulation().
|
protected |
HF-only or wide models need lighter simulate passes (VRAM).
Definition at line 62 of file train_simulate.py.
Referenced by _run_simulation(), and _sim_batch_limit().
|
protected |
Approximate H^{-1} · ∇L_test via LiSSA.
v_{t+1} = v_0 + (1 - damping)·v_t - (1/scale)·H·v_t
where v_0 = ∇L_test (held fixed).
train_loss_fn(j) must return a fresh scalar loss for batch j on each call.
Definition at line 192 of file train_simulate.py.
References _grad_vector(), and _hvp_from_fn().
Referenced by _run_simulation().
|
protected |
Cosine-style influence in [-1, 1] : stable for display and ranking.
Definition at line 181 of file train_simulate.py.
References _grad_dot(), and _tensor_list_norm().
Referenced by _influence_via_grad_dot(), and _run_simulation().
|
protected |
Per-parameter diagonal NTK entry via Rayleigh quotient: K_ii ≈ (g^T · H · g) / ||g||^2 Uses one HVP in the gradient direction.
Definition at line 241 of file train_simulate.py.
References _hvp().
Referenced by _run_simulation().
|
protected |
Estimate the largest Hessian eigenvalue via power iteration.
Definition at line 262 of file train_simulate.py.
References _hvp().
Referenced by _run_simulation().
|
protected |
Analyse dataset quality without loading the LLM. Returns a quality report dict (no SSE streaming here : caller handles that).
Definition at line 331 of file train_simulate.py.
References _detect_ai_generated().
Referenced by _run_simulation().
|
protected |
Definition at line 460 of file train_simulate.py.
References _grad_vector(), _influence_via_grad_dot(), _is_heavy_sim_model(), _lissa_inverse_hvp(), _normalized_influence(), _ntk_diagonal(), _power_iteration_max_eigenvalue(), _run_dataset_quality(), _sae_grad_scores_from_batch(), _sim_batch_limit(), and _tensor_list_norm().
|
protected |
Project loss gradient at the SAE layer through W_dec (works with PEFT/LoRA).
Definition at line 295 of file train_simulate.py.
References _hidden_state_index().
Referenced by _run_simulation().
|
protected |
Recursively replace NaN/Inf floats with None so JSON serialization never fails.
Definition at line 1278 of file train_simulate.py.
References _sanitize().
Referenced by _sanitize().
|
protected |
Definition at line 67 of file train_simulate.py.
References _is_heavy_sim_model().
Referenced by _run_simulation().
|
protected |
Definition at line 174 of file train_simulate.py.
Referenced by _normalized_influence(), and _run_simulation().
| dict compare_simulation_results | ( | dict | result_a, |
| dict | result_b, | ||
| str | label_a = "Run A", | ||
| str | label_b = "Run B", | ||
| * | , | ||
| str | run_id_a = "", | ||
| str | run_id_b = "" ) |
Diff two simulation payloads : SAE features, influence, LR, attack-surface scores.
Definition at line 1289 of file train_simulate.py.
Referenced by compare_simulations().
| compare_simulations | ( | CompareRequest | req | ) |
Diff two simulation results. Returns structured comparison.
Definition at line 1500 of file train_simulate.py.
References compare_simulation_results().
| training_simulate | ( | SimulateRequest | req | ) |
Streams simulation events as SSE. Client reads line-by-line.
Definition at line 1255 of file train_simulate.py.
|
protected |
Definition at line 118 of file train_simulate.py.
|
protected |
Definition at line 70 of file train_simulate.py.
|
protected |
Definition at line 58 of file train_simulate.py.
|
protected |
Definition at line 59 of file train_simulate.py.
|
protected |
Definition at line 57 of file train_simulate.py.
| aquin.compute.train_simulate.DEVICE = resolve_compute_device() |
Definition at line 54 of file train_simulate.py.
| aquin.compute.train_simulate.DTYPE = default_dtype_for_device(DEVICE) |
Definition at line 55 of file train_simulate.py.
| aquin.compute.train_simulate.router = APIRouter() |
Definition at line 52 of file train_simulate.py.