[Feature]: HuggingFace Hub integration via PyTorchModelHubMixin
Débutant
enhancementhelp wantedECSoC26good-backend
46 ★
Poids du clone moyen
Mise à jour
Description
## Problem
The existing `nightmarenet/hub/` module implements custom `push_model`/`pull_model` functions but doesn't integrate with the HuggingFace Hub's standard `ModelHubMixin` pattern. This means NightmareNet models cannot be discovered on the HuggingFace Hub model browser, don't get automatic model cards, and lack `from_pretrained`/`push_to_hub` methods that the ML community expects. Sprint 7 targets HuggingFace Hub integration.
## Solution
Implement `PyTorchModelHubMixin` integration:
- [ ] Create `nightmarenet/hub/hf_integration.py` with `NightmareNetModelHubMixin`
- [ ] Inherit from `PyTorchModelHubMixin` for automatic `save_pretrained`, `from_pretrained`, `push_to_hub`
- [ ] Implement `_save_pretrained()` to serialize model weights + NightmareNet config + training metadata
- [ ] Implement `_from_pretrained()` to load model + restore NightmareNet pipeline state
- [ ] Auto-generate HF model card with NightmareNet-specific sections (robustness metrics, distortion config)
- [ ] Register `nightmarenet` as a library on HuggingFace Hub (library tag)
- [ ] Add code snippet for Hub model page
## Acceptance Criteria
- `model.push_to_hub("username/model-name")` works end-to-end
- `NightmareNetModel.from_pretrained("username/model-name")` loads correctly
- Model card includes: training config, robustness score, distortion types used
- Models appear under `nightmarenet` library filter on HuggingFace Hub
- Unit tests with mocked Hub API (no real uploads in CI)
- Backward compatible with existing `hub/core.py` functions
## Impact Radius
| File | Why it may need attention |
|------|--------------------------|
| `nightmarenet/hub/hf_integration.py` | New file |
| `nightmarenet/hub/core.py` | Existing push/pull - coordinate, don't duplicate |
| `nightmarenet/hub/model_card.py` | Existing card generation - extend for HF format |
| `nightmarenet/hub/__init__.py` | Re-export new mixin |
| `pyproject.toml` | Add `huggingface-hub>=0.20.0` dependency |
| `nightmarenet/training/trainer.py` | May integrate mixin for auto-push after training |
| `nightmarenet/phases/evaluate.py` (L204) | Already calls `push_model` - update to use mixin |
| `README.md` | Add HuggingFace Hub usage example |
| `docs/features/` | Document Hub integration |
| `tests/test_hub.py` | Add mixin tests |
## Lint Scope
- Run `pytest tests/test_hub*.py -v`
- Run `mypy nightmarenet/hub/`
- Verify `huggingface-hub` version compatible with `PyTorchModelHubMixin`
- Test: `from nightmarenet.hub import NightmareNetModelHubMixin` works
> **Important:** Please read CONTRIBUTING.md in full before requesting assignment. Assignment requests without a technical approach will not be considered. PRs demonstrating thorough research, benchmarks, or creative approaches beyond minimum criteria may earn bonus XP labels.
Issues similaires
Tout voir
Python
Débutant
VS Code extension should be robust to YAML parser errors
Seeing this error: ``` Failed to read calkit.yaml: YAMLParseError: A block sequence may not be used as an im…
Mise à jour
Python
Débutant
dash: a manual Refresh control
The dashboard polls: `refreshStats()` (`src/doberman/dash/app.py:408`) every 5 s and `refreshPending()` (`:54…
Mise à jour
Python
Débutant
dash: "Copy details" button on each pending-approval card
Each pending-approval card in the dashboard (`renderPending`, `src/doberman/dash/app.py:448-544`) shows the r…
Mise à jour