Step 1: Ask for permission on Meta's website
To be able to download the model, you first need to agree to some terms and conditions from Meta. You can go to this link, then press Download the model, then you will be taken to a form where you have to fill in your information. After that, you can press Accept and continue. Meta will then process your request, and when they are done, they will send you an email. For me, this only took a few minutes, but there is no guarantee it will always be that quick.
Step 2: Clone the repository
After receiving the permission, you can clone this Git repository. To download the Llama2 model, you need to run the download.sh file, which is where the issues with using Windows come in, as you cannot run a .sh file out of the box with Windows. Do make this work, you can go to step 3.
Step 3: Downloading the model
Meta提供的下载时一个.sh文件,其中用到wget和md5sums 在windows并不存在,我们下载来用:
wget
md5sums下载后放入path当中。
Meta提供的下载时一个.sh文件,Windows无法直接使用。有三个解决方案:
1. 用git bash去跑
安装git
,然后运行git bash
,在git bash里面可以跑.sh
2. 改.sh为powershell
shell
$PRESIGNED_URL = "https://download.llamameta.net/*?Policy=your_funky_url"
$MODEL_SIZE = "70B" #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 = "F:\Llama2" # where all files should end up
if(!(Test-Path -Path $TARGET_FOLDER)){
New-Item -ItemType directory -Path $TARGET_FOLDER
}
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 -Uri ($PRESIGNED_URL.Replace('*',"LICENSE")) -OutFile ($TARGET_FOLDER+"/LICENSE")
Invoke-WebRequest -Uri ($PRESIGNED_URL.Replace('*',"USE_POLICY.md")) -OutFile ($TARGET_FOLDER+"/USE_POLICY.md")
#Write-Host "Downloading tokenizer"
Invoke-WebRequest -Uri ($PRESIGNED_URL.Replace('*',"tokenizer.model")) -OutFile ($TARGET_FOLDER+"/tokenizer.model")
# Model sizes
$model_sizes = $MODEL_SIZE.Split(',')
foreach ($m in $model_sizes)
{
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"
$path = $TARGET_FOLDER+"/"+$MODEL_PATH
if(!(Test-Path -Path $path)){
New-Item -ItemType directory -Path $path
}
for ($s=0; $s -le $SHARD; $s++)
{
$fileName = "consolidated.{0:D2}.pth" -f $s
Invoke-WebRequest -Uri ($PRESIGNED_URL.Replace('*',$MODEL_PATH+"/"+$fileName)) -OutFile ($path+"/"+$fileName)
}
Invoke-WebRequest -Uri ($PRESIGNED_URL.Replace('*',$MODEL_PATH+"/params.json")) -OutFile ($path+"/params.json")
}
3. 改.sh为.bat给cmd跑
:: Copyright (c) Meta Platforms, Inc. and affiliates.
:: This software may be used and distributed according to the terms of the Llama 2 Community License Agreement.
:: Prerequisites:
:: 0. Windows machine
:: 1. wget installed
:: 2. You've broken up your presigned url into its URL variables (separated by "?" and "&")
:: RUN AT YOUR OWN RISK: I removed the md5sum dependency because I couldn't get the windows version to work right with this script.
:: Example:
:: download.bat YOUR_POLICY YOUR_SIGNATURE YOUR_KPID 7B .
:: Model size options = 7B,13B,70B,7B-chat,13B-chat,70B-chat
:: Unlike the bash script, this only takes one model at a time
:: First argument = Policy field from presigned url
:: Second argument = Signature field from presigned url
:: Third argument = Key-Pair-Id field from presigned url
:: Fourth argument = model size (only one at a time)
:: Fifth argument = target folder
:: WARNING: This will NOT work in PowerShell
:: WARNING: You must run cmd.exe as Administrator. I have a cmd shortcut on my desktop that I right click then click "Run as Administrator"
@ECHO Off
SET POLICY=%1
SET SIGNATURE=%2
SET KEY_PAIR_ID=%3
SET MODEL_SIZE=%4
SET TARGET_FOLDER=%5
IF %MODEL_SIZE%=="" SET MODEL_SIZE=7B
IF %TARGET_FOLDER%=="" SET TARGET_FOLDER=.
ECHO "Downloading LICENSE and Acceptable Usage Policy"
wget "https://download.llamameta.net/LICENSE?Policy=%POLICY%&Signature=%SIGNATURE%&Key-Pair-Id=%KEY_PAIR_ID%" -O "%TARGET_FOLDER%/LICENSE"
wget "https://download.llamameta.net/USE_POLICY.md?Policy=%POLICY%&Signature=%SIGNATURE%&Key-Pair-Id=%KEY_PAIR_ID%" -O "%TARGET_FOLDER%/USE_POLICY.md"
ECHO "Downloading tokenizer"
wget "https://download.llamameta.net/tokenizer.model?Policy=%POLICY%&Signature=%SIGNATURE%&Key-Pair-Id=%KEY_PAIR_ID%" -O "%TARGET_FOLDER%/tokenizer.model"
wget "https://download.llamameta.net/tokenizer_checklist.chk?Policy=%POLICY%&Signature=%SIGNATURE%&Key-Pair-Id=%KEY_PAIR_ID%" -O "%TARGET_FOLDER%/tokenizer_checklist.chk"
IF %MODEL_SIZE%==7B SET /A SHARD=0
IF %MODEL_SIZE%==7B SET MODEL_PATH=llama-2-7b
if %MODEL_SIZE%==7B-chat SET /A SHARD=0
if %MODEL_SIZE%==7B-chat SET MODEL_PATH=llama-2-7b-chat
if %MODEL_SIZE%==13B SET /A SHARD=1
if %MODEL_SIZE%==13B SET MODEL_PATH=llama-2-13b
if %MODEL_SIZE%==13B-chat SET /A SHARD=1
if %MODEL_SIZE%==13B-chat SET MODEL_PATH=llama-2-13b-chat
if %MODEL_SIZE%==70B SET /A SHARD=7
if %MODEL_SIZE%==70B SET MODEL_PATH=llama-2-70b
if %MODEL_SIZE%==70B-chat SET /A SHARD=7
if %MODEL_SIZE%==70B-chat SET MODEL_PATH=llama-2-70b-chat
ECHO "Downloading model to %MODEL_PATH% with shard %SHARD% because MODEL_SIZE is %MODEL_SIZE%"
MKDIR "%TARGET_FOLDER%/%MODEL_PATH%"
FOR %%s IN (0, 1, %SHARD%) DO (
wget "https://download.llamameta.net/%MODEL_PATH%/consolidated.%s%.pth?Policy=%POLICY%&Signature=%SIGNATURE%&Key-Pair-Id=%KEY_PAIR_ID%" -O "%TARGET_FOLDER%/%MODEL_PATH%/consolidated.%s%.pth"
)
wget "https://download.llamameta.net/%MODEL_PATH%/params.json?Policy=%POLICY%&Signature=%SIGNATURE%&Key-Pair-Id=%KEY_PAIR_ID%" -O "%TARGET_FOLDER%/%MODEL_PATH%/params.json"
wget "https://download.llamameta.net/%MODEL_PATH%/checklist.chk?Policy=%POLICY%&Signature=%SIGNATURE%&Key-Pair-Id=%KEY_PAIR_ID%" -O "%TARGET_FOLDER%/%MODEL_PATH%/checklist.chk"
ECHO DONE
Step 4: 坐享其成
搞定!