当前位置:   article > 正文

OpenAI ChatGPT-4开发笔记2024-08:windows本地环境下载Llama 2

OpenAI ChatGPT-4开发笔记2024-08:windows本地环境下载Llama 2

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
$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")


}
  • 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
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
  • 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
  • 72
  • 73

Step 4: 坐享其成

在这里插入图片描述
在这里插入图片描述
搞定!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/117321
推荐阅读
相关标签
  

闽ICP备14008679号