Skip to content

feat: Add Hugging Face Hub integration for .apr model publishing #100

@noahgift

Description

@noahgift

Summary

Add ability to publish trained ML models to Hugging Face Hub directly from aprender, with automatic model card generation.

Motivation

Users of aprender (including renacer) need to:

  1. Share trained models - Push .apr files to HF Hub for team collaboration
  2. Version models - Track model iterations with HF Hub's versioning
  3. Auto-generate model cards - Include training metadata, hyperparameters, metrics

Requested API

use aprender::hf_hub::{HfHubClient, ModelCard, PushOptions};

// Push model to HF Hub
let client = HfHubClient::new()?; // Uses HF_TOKEN env var
client.push_to_hub(
    "org/model-name",
    &model,
    PushOptions::default()
        .with_model_card(ModelCard::auto_generate(&metadata))
        .with_commit_message("Add v1.0.0 trained model")
)?;

// Pull model from HF Hub  
let model: KMeansModel = client.pull_from_hub("org/model-name")?;

Model Card Auto-Generation

Should include:

  • Model type (KMeans, IsolationForest, etc.)
  • Training timestamp
  • Hyperparameters used
  • Training sample count
  • Silhouette score / other metrics
  • aprender version

Example Model Card Output

---
library_name: aprender
tags:
  - anomaly-detection
  - syscall-analysis
  - rust
---

# Model Card: syscall-anomaly-detector

## Model Details
- **Type:** KMeans Clustering
- **Clusters:** 5
- **Features:** 3 (count, total_time, avg_time)
- **Trained:** 2024-01-15T10:30:00Z
- **aprender version:** 0.10.0

## Training Data
- **Samples:** 15,234 syscall records
- **Source:** renacer trace of `cargo build`

## Metrics
- **Silhouette Score:** 0.847
- **Inertia:** 1234.56

## Usage

\`\`\`rust
use aprender::hf_hub::HfHubClient;

let model = HfHubClient::new()?.pull_from_hub("paiml/syscall-anomaly")?;
\`\`\`

Downstream Consumer

renacer will add CLI flags:

  • --push-model hub:org/repo - Push trained model to HF Hub
  • --load-model hub:org/repo - Load model from HF Hub

References

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions