← Back to Pull requests

Added TrainingHubCallback abstraction and Unsloth adapter #128

Closed
unknown closed this pull request without merging on Jul 29, 2026 19:19 UTC
View on GitHub
unknown unknown commented on Jul 24, 2026 06:41 UTC
Author

Summary


  • Add a unified TrainingHubCallback base class and TrainingHubContext dataclass for backend-agnostic training lifecycle hooks

  • Add Unsloth/HuggingFace adapter (UnslothCallbackAdapter) with exception isolation and rank-0 guard

  • Wire callbacks and eval_data_path into lora_sft / Unsloth LoRA backend so user callbacks fire during real training

  • Add unit tests and an Unsloth smoke example (script + notebook)
  • This is the first split of RHOAIENG-54744. InstructLab / Mini-Trainer adapters and torchrun serialization are deferred to RHOAIENG-77627.

    What's included


    | Piece | Details |
    | --- | --- |
    | TrainingHubCallback | 9 no-op lifecycle hooks (on_train_begin … on_train_end) |
    | TrainingHubContext | Normalized step, epoch, loss, learning_rate, is_main_process, output_dir, metrics |
    | Unsloth adapter | Wraps hub callbacks as HF TrainerCallback; forwards eval metrics on on_evaluate |
    | API | lora_sft(..., callbacks=[...], eval_data_path=...) |
    | Unit tests | tests/test_callbacks.py — context, hooks, adapter dispatch, exception isolation, rank guard, eval metrics |
    | Smoke notebook | examples/notebooks/callback_smoke_unsloth.ipynb — guided Unsloth e2e cells (setup, train+eval, pass/fail for all 9 hooks) |
    | Smoke script | examples/scripts/callback_smoke_unsloth.py — same check runnable from a workbench terminal |

    Test plan


  • pytest tests/test_callbacks.py (15 passed)

  • OpenShift A100 smoke with Unsloth + Qwen2.5-0.5B-Instruct

  • - Confirmed all 9 unified hooks fired: begin/epoch/step/log/evaluate/save/end
    - Confirmed on_evaluate receives metrics (after metrics-forwarding fix)

    Refs: RHOAIENG-77626, RHOAIENG-54744

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    Summary by CodeRabbit

    New Features
    Added a unified Training Hub callback framework with a shared training context and standardized lifecycle hooks.
    Introduced an adapter that routes Training Hub callback events (including metrics) into the Unsloth-backed training flow.
    Extended lora_sft/LoRA SFT to accept custom callbacks and optional evaluation data and per-device eval batch sizing.
    Re-exported callback components from the top-level package.
    Bug Fixes
    Evaluation is now conditionally enabled only when evaluation data is provided.
    Tests
    Added unit tests for callback behavior and adapter dispatch, including exception isolation and rank-based dispatch.
    Added end-to-end callback smoke-check script and notebook.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 345 lines (+258 / -87) across 4 files Reviewer: RobotSail Review duration: 7957m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 345 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.350
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #128"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.4% (MEDIUM) · Higher = larger blast radius
    42.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.7% · Safe to merge
    16.7%