Skip to content

Archive pipeline runs and artifacts to HuggingFace#642

Draft
anth-volk wants to merge 3 commits intomainfrom
feature/pipeline-hf-archival
Draft

Archive pipeline runs and artifacts to HuggingFace#642
anth-volk wants to merge 3 commits intomainfrom
feature/pipeline-hf-archival

Conversation

@anth-volk
Copy link
Copy Markdown
Collaborator

Summary

  • Publish full pipeline run records (metadata, diagnostics, intermediate build artifacts) to a dedicated HF model repo (PolicyEngine/policyengine-us-data-pipeline)
  • All existing uploads to policyengine/policyengine-us-data are unchanged
  • Archival is non-fatal — pipeline never fails due to archival issues

Fixes #641

Changes

policyengine_us_data/utils/data_upload.py

  • Extract _batched_hf_upload() shared helper from upload_to_staging_hf (deduplicates ~30 lines of batch/retry logic)
  • Add upload_to_pipeline_repo() thin wrapper targeting PolicyEngine/policyengine-us-data-pipeline
  • Validate HUGGING_FACE_TOKEN before attempting uploads (fail-fast instead of misleading 401 after retries)

modal_app/pipeline.py

  • Add _mirror_to_pipeline_repo() — non-fatal subprocess wrapper with 10-min timeout, env-var data passing (no f-string injection), narrow exception handling
  • Add _archive_artifacts() — unified helper for archiving named artifacts from the pipeline volume
  • write_run_meta() gains mirror param (set to False in the failure handler to prevent hanging on network errors)
  • archive_diagnostics() mirrors diagnostic files to the pipeline repo after volume commit
  • _write_validation_diagnostics() builds mirror list inline as files are written (no re-probing filesystem)
  • Archive Step 1 intermediate artifacts (STEP1_ARTIFACTS) and Step 2 metadata (STEP2_ARTIFACTS) after each step completes

changelog.d/pipeline-hf-archival.added.md

  • Towncrier changelog fragment

Test plan

  • Create PolicyEngine/policyengine-us-data-pipeline model repo on HuggingFace (one-time)
  • Run make pipeline on Modal with small epoch count
  • Verify HF repo contains {run_id}/meta.json, {run_id}/diagnostics/*, {run_id}/artifacts/*
  • Verify existing uploads to policyengine/policyengine-us-data are unchanged
  • Verify pipeline failure handler writes meta.json locally but does not attempt HF mirror

🤖 Generated with Claude Code

anth-volk and others added 3 commits March 26, 2026 23:27
Publish full run records (metadata, diagnostics, intermediate build
artifacts) to a dedicated HF model repo
(PolicyEngine/policyengine-us-data-pipeline) so run history survives
Modal volume deletion. All existing uploads to the main data repo
are unchanged.

- Add upload_to_pipeline_repo() utility with retry and batching
- Mirror meta.json, diagnostics, and validation files on every write
- Archive Step 1 intermediate artifacts (acs, puf, extended_cps, etc.)
- Archive Step 2 calibration_package_meta.json

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add 10-minute subprocess timeout to _mirror_to_pipeline_repo
- Pass data via env vars instead of f-string code injection
- Narrow exception handling to SubprocessError/OSError
- Add mirror=False param to write_run_meta for error handlers
- Validate HUGGING_FACE_TOKEN before attempting uploads
- Extract _batched_hf_upload shared helper (dedup ~30 lines)
- Consolidate _archive_build/package_artifacts into _archive_artifacts
- Fix TOCTOU race between exists() and stat() with try/except
- Build validation mirror list inline instead of re-probing filesystem
- Add proper type hints to new functions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@anth-volk anth-volk requested a review from juaristi22 March 26, 2026 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Archive pipeline runs and intermediate artifacts to HuggingFace

1 participant