Skip to main content

One-line training diagnostics & feature engineering for DL, ML, and RecSys. Track dynamics, discover feature synergies, get automated prescriptions.

Project description

🌊 GradTracer

Flow-based Diagnostics for Embedding Systems & Compression

InstallationCore FocusAI Agent Integration


GradTracer is a specialized diagnostic library designed for Embedding-heavy Recommendation Systems (RecSys) and Model Compression.

Rather than competing with general-purpose loggers like TensorBoard or Weights & Biases, GradTracer tracks step-by-step training dynamics (dG/dt)—such as embedding drift, gradient oscillation, and exposure frequency—to diagnose silent failures (e.g., representation collapse) that traditional scalar metrics miss.

Crucially, every GradTracer module exports its findings as structured causal XML, allowing AI coding assistants (Cursor, Copilot, Antigravity) to automatically parse the diagnosis and apply statistically backed prescriptions.

🎯 Core Focus: RecSys & Compression

1. Embedding Dynamics Tracker & Bayesian Auto-Fix (v0.6+)

General DL diagnostics often fail for RecSys because embedding tables are highly sparse and suffer from popularity bias. EmbeddingTracker identifies:

  • Zombie Embeddings: Items with high update velocity but oscillating gradient directions (failing to generalize).
  • Dead Embeddings: Items suffering from severe cold-start or broken negative sampling.
  • Popularity Bias: Exposure distribution skew (Gini/Entropy) that hurts long-tail coverage.
  • Frequency-Aware Saliency: Normalizes update velocity by exposure frequency to identify truly important embeddings for pruning.
  • ⚡ [NEW] Bayesian Auto-Fix: Pass auto_fix=True to let GradTracer actively intercept and dynamically scale gradients for Zombie embeddings during the backward pass based on SNR and global loss posteriors.
  • 🌍 [NEW] DDP Support: Automatically handles torch.distributed.all_reduce to aggregate embedding stats across multiple GPUs.

2. Dynamics-Aware Compression Suite

Instead of blindly pruning based on weight magnitude, GradTracer uses training dynamics to guide compression:

  • Dynamic Saliency (SaliencyAnalyzer): Ranks layers by how actively they are learning (velocity + momentum).
  • Quantization Guidance (QuantizationAdvisor): Recommends mixed-precision (4/8/16-bit) based on layer-specific gradient SNR and weight variance.

3. Deep Tree Dynamics (v0.6)

  • Node-Level GBDT Tracking (TreeDynamicsTracker): Unlike basic feature importance, GradTracer unpacks the raw tree structure to track Leaf Velocity (Variance) and Feature Split Concentration. Evaluates mathematically if trees are stagnating or exploding.
  • [NEW] Broad Support: Now fully supports XGBoost, LightGBM, and CatBoost.

4. Complex Architectures (v0.6)

  • FlowManager: Centralized multi-tracker hub designed for Two-Tower, GNN, or Sequential architectures to calculate cross-layer correlations (e.g., User Tower vs. Item Tower).

🤖 AI Agent XML Export

GradTracer serves as a "Decision Layer" for AI coding assistants. By calling .to_agent_xml(), models receive exact logic and prescriptions.

from gradtracer.analyzers.embedding import EmbeddingTracker

tracker = EmbeddingTracker(model.item_emb, auto_fix=True, track_interval=100)
# ... training loop (tracker.step()) ...

print(tracker.to_agent_xml())
<gradtracer_embedding_report layer="item_emb">
  <causal_model type="ZOMBIE_EMBEDDINGS">
    <premise>8.5% of embeddings have high update velocity but strictly negative cosine similarity between steps.</premise>
    <implies>Optimizer is oscillating. Conflicting gradients from different users are pulling these embeddings back and forth.</implies>
    <action>AUTO_FIX_ENGAGED</action>
    <expected_effect>Scaled down gradients for 1,204 oscillatory indices based on Bayesian variance.</expected_effect>
    <confidence>0.92</confidence>
  </causal_model>
</gradtracer_embedding_report>

📊 Mathematical & Statistical Validation

GradTracer's recommendations are backed by formal statistical tests. As demonstrated in our Validation Notebooks, our Auto-Fix logic and embedding prescriptions yield Statistically Significant Improvements mathematically guaranteed via:

  • NDCG@10 & Hit Rate@10 Paired t-tests demonstrating statistically rigorous ranking improvements when Auto-Fix intercepts oscillatory parameters in MovieLens-100K MF baselines.
  • Cosine Similarity Tracking guaranteeing true oscillatory embeddings rather than in-sample noise.

🚀 Quick Start

pip install git+https://github.com/hw01931/GradTracer.git

🧩 Experimental Modules

While optimized for RecSys and Compression, GradTracer still includes its original Python dynamics modules:

  • FlowTracker: General PyTorch training stability (SNR, Stagnation).
  • FeatureAnalyzer: VIF-filtered interaction suggestions.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gradtracer-0.6.0.tar.gz (70.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gradtracer-0.6.0-py3-none-any.whl (67.6 kB view details)

Uploaded Python 3

File details

Details for the file gradtracer-0.6.0.tar.gz.

File metadata

  • Download URL: gradtracer-0.6.0.tar.gz
  • Upload date:
  • Size: 70.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gradtracer-0.6.0.tar.gz
Algorithm Hash digest
SHA256 8b382a39813c11a956f51e739a12af94c5820efe7c1391326e3a4e040f92ac93
MD5 74acbc9432828de88e0debb90299fe47
BLAKE2b-256 da0a900d40bbebb2904dd90650d7c1c65ee5712e20432699709a4b0ad425ea6b

See more details on using hashes here.

Provenance

The following attestation bundles were made for gradtracer-0.6.0.tar.gz:

Publisher: publish.yml on hw01931/GradTracer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gradtracer-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: gradtracer-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 67.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gradtracer-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f297aa03094bf7be13229b4b993ce920ad7e77fa6c6381b309d0bc7ce41d1cd7
MD5 190a99ac5dadff792a40da95d6f8885b
BLAKE2b-256 71a6b4140d01f73fb3db7c85c78e7214bcd8d6e15817fadcb984eb1ff638fb5c

See more details on using hashes here.

Provenance

The following attestation bundles were made for gradtracer-0.6.0-py3-none-any.whl:

Publisher: publish.yml on hw01931/GradTracer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page