Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Download.ps1): Add download.ps1 for Windows #442

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ In order to download the model weights and tokenizer, please visit the [Meta AI

Once your request is approved, you will receive a signed URL over email. Then run the download.sh script, passing the URL provided when prompted to start the download. Make sure that you copy the URL text itself, **do not use the 'Copy link address' option** when you right click the URL. If the copied URL text starts with: https://download.llamameta.net, you copied it correctly. If the copied URL text starts with: https://l.facebook.com, you copied it the wrong way.

Pre-requisites: make sure you have `wget` and `md5sum` installed. Then to run the script: `./download.sh`.
Pre-requisites: make sure you have `wget` and `md5sum` installed. Then to run the script: `./download.sh` for *nix-like OS or `.\download.ps1` for Windows.

Keep in mind that the links expire after 24 hours and a certain amount of downloads. If you start seeing errors such as `403: Forbidden`, you can always re-request a link.

Expand Down
78 changes: 78 additions & 0 deletions download.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
function Check-MD5Sum {
param (
[Parameter(Mandatory=$true)]
[string]$ChecklistPath
)
$checklist = Get-Content $ChecklistPath
$checklist | ForEach-Object {
$md5sum = $_.split(' ')[0]
$filename = $_.split(' ')[1]
if (Test-Path $filename) {
$hash = Get-FileHash -Algorithm MD5 -Path $filename | Select-Object -ExpandProperty Hash
if ($md5sum -eq $hash) {
Write-Host "${filename}: OK"
}
else {
Write-Host "${filename}: FAILED"
}
}
else {
Write-Host "${filename}: NOT FOUND"
}
}
}


$PRESIGNED_URL = Read-Host -Prompt "Enter the URL from email "
$MODEL_SIZE=Read-Host -Prompt "Enter the list of models to download without spaces (7B,13B,70B,7B-chat,13B-chat,70B-chat), or press Enter for all "
$TARGET_FOLDER="." # where all files should end up
mkdir ${TARGET_FOLDER} -ea 0

if ($MODEL_SIZE -eq "") {
$MODEL_SIZE = "7B,13B,70B,7B-chat,13B-chat,70B-chat"
}

Write-Host "Downloading LICENSE and Acceptable Usage Policy"
Invoke-WebRequest -UserAgent "Wget/1.13.4" -Uri ($PRESIGNED_URL -replace '\*', 'LICENSE') -OutFile "$TARGET_FOLDER/LICENSE"
Invoke-WebRequest -UserAgent "Wget/1.13.4" -Uri ($PRESIGNED_URL -replace '\*', 'USE_POLICY.md') -OutFile "$TARGET_FOLDER/USE_POLICY.md"

Write-Host "Downloading tokenizer"
Invoke-WebRequest -UserAgent "Wget/1.13.4" -Uri ($PRESIGNED_URL -replace '\*', 'tokenizer.model') -OutFile "${TARGET_FOLDER}/tokenizer.model"
Invoke-WebRequest -UserAgent "Wget/1.13.4" -Uri ($PRESIGNED_URL -replace '\*', 'tokenizer_checklist.chk') -OutFile "${TARGET_FOLDER}/tokenizer_checklist.chk"
Push-Location ${TARGET_FOLDER} && Check-MD5Sum -ChecklistPath tokenizer_checklist.chk && Pop-Location

foreach ($m in $MODEL_SIZE.Split(',')) {
if ($m -eq "7B") {
$SHARD = 0
$MODEL_PATH = "llama-2-7b"
} elseif ($m -eq "7B-chat") {
$SHARD = 0
$MODEL_PATH = "llama-2-7b-chat"
} elseif ($m -eq "13B") {
$SHARD = 1
$MODEL_PATH = "llama-2-13b"
} elseif ($m -eq "13B-chat") {
$SHARD = 1
$MODEL_PATH = "llama-2-13b-chat"
} elseif ($m -eq "70B") {
$SHARD = 7
$MODEL_PATH = "llama-2-70b"
} elseif ($m -eq "70B-chat") {
$SHARD = 7
$MODEL_PATH = "llama-2-70b-chat"
}

Write-Host "Downloading ${MODEL_PATH}"
New-Item -ItemType Directory -Path "${TARGET_FOLDER}/${MODEL_PATH}" -Force | Out-Null

for ($s = 0; $s -le $SHARD; $s++) {
$url=($PRESIGNED_URL -replace '\*', "${MODEL_PATH}/consolidated.0${s}.pth")
Invoke-WebRequest -UserAgent "Wget/1.13.4" -Uri $url -OutFile "${TARGET_FOLDER}/${MODEL_PATH}/consolidated.0${s}.pth"
}
$url=($PRESIGNED_URL -replace '\*', "${MODEL_PATH}/params.json")
Invoke-WebRequest -UserAgent "Wget/1.13.4" -Uri $url -OutFile "${TARGET_FOLDER}/${MODEL_PATH}/params.jsoni"
sykuang marked this conversation as resolved.
Show resolved Hide resolved
$url=($PRESIGNED_URL -replace '\*', "${MODEL_PATH}/checklist.chk")
Invoke-WebRequest -UserAgent "Wget/1.13.4" -Uri $url -OutFile "${TARGET_FOLDER}/${MODEL_PATH}/checklist.chk"
Write-Host "Checking checksums"
Push-Location "${TARGET_FOLDER}/${MODEL_PATH}" && Check-MD5Sum -ChecklistPath checklist.chk && Pop-Location
}