File size: 2,485 Bytes
6c5f29f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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"