memaudit-code / scripts /hf_upload_memaudit.ps1
edgeclustr's picture
Upload MemAudit code artifacts
6c5f29f verified
Raw
History Blame Contribute Delete
2.49 kB
param(
[Parameter(Mandatory = $true)]
[string]$Namespace,
[string]$DatasetRepo = "memaudit-data",
[string]$CodeRepo = "memaudit-code",
[string]$PackageDir = "memaudit_submission_package"
)
$ErrorActionPreference = "Stop"
function Invoke-Hf {
& hf @args
if ($LASTEXITCODE -ne 0) {
throw "hf command failed: hf $($args -join ' ')"
}
}
if (-not (Get-Command hf -ErrorAction SilentlyContinue)) {
throw "The Hugging Face CLI `hf` is not available on PATH."
}
if (-not (Test-Path $PackageDir)) {
throw "Package directory not found: $PackageDir. Run scripts/prepare_submission_artifacts.py first."
}
$datasetDir = Join-Path $PackageDir "dataset"
$codeDir = Join-Path $PackageDir "code"
$croissant = Join-Path $datasetDir "croissant_metadata.json"
if (-not (Test-Path $datasetDir) -or -not (Test-Path $codeDir) -or -not (Test-Path $croissant)) {
throw "Package directory must contain code/, dataset/, and dataset/croissant_metadata.json."
}
if (-not $env:HF_TOKEN) {
Write-Host "HF_TOKEN is not set. Using the currently logged-in hf account." -ForegroundColor Yellow
Write-Host "For double-blind review, make sure this is an anonymous account or namespace." -ForegroundColor Yellow
Invoke-Hf auth whoami
}
$datasetId = "$Namespace/$DatasetRepo"
$codeId = "$Namespace/$CodeRepo"
$datasetUrl = "https://huggingface.co/datasets/$datasetId"
Write-Host "Updating Croissant dataset URL: $datasetUrl"
$text = Get-Content -Raw $croissant
$text = $text.Replace("TO_BE_FILLED_WITH_ANONYMIZED_DATASET_URL", $datasetUrl)
[System.IO.File]::WriteAllText((Resolve-Path $croissant), $text, [System.Text.UTF8Encoding]::new($false))
Write-Host "Validating Croissant metadata with mlcroissant..."
@"
import mlcroissant as mlc
mlc.Dataset(r"$croissant")
print("croissant_ok")
"@ | python -
Write-Host "Creating or reusing Hugging Face dataset repos..."
Invoke-Hf repo create $datasetId --repo-type dataset --exist-ok
Invoke-Hf repo create $codeId --repo-type dataset --exist-ok
Write-Host "Uploading dataset artifacts to $datasetId ..."
Invoke-Hf upload $datasetId $datasetDir . --repo-type dataset --commit-message "Upload MemAudit dataset artifacts"
Write-Host "Uploading code artifacts to $codeId ..."
Invoke-Hf upload $codeId $codeDir . --repo-type dataset --commit-message "Upload MemAudit code artifacts"
Write-Host ""
Write-Host "Dataset URL: $datasetUrl"
Write-Host "Code URL: https://huggingface.co/datasets/$codeId"
Write-Host "Croissant file: $croissant"