-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
enhanced the download.sh script for better usability #52
Open
rjarun8
wants to merge
3
commits into
meta-llama:main
Choose a base branch
from
rjarun8:enhancement/download-script
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,154 @@ | ||
#!/bin/bash | ||
|
||
# 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. | ||
|
||
read -p "Enter the URL from email: " PRESIGNED_URL | ||
echo "" | ||
ALL_MODELS="7b,13b,34b,7b-Python,13b-Python,34b-Python,7b-Instruct,13b-Instruct,34b-Instruct" | ||
read -p "Enter the list of models to download without spaces ($ALL_MODELS), or press Enter for all: " MODEL_SIZE | ||
TARGET_FOLDER="." # where all files should end up | ||
mkdir -p ${TARGET_FOLDER} | ||
|
||
if [[ $MODEL_SIZE == "" ]]; then | ||
MODEL_SIZE=$ALL_MODELS | ||
fi | ||
|
||
echo "Downloading LICENSE and Acceptable Usage Policy" | ||
wget ${PRESIGNED_URL/'*'/"LICENSE"} -O ${TARGET_FOLDER}"/LICENSE" | ||
wget ${PRESIGNED_URL/'*'/"USE_POLICY.md"} -O ${TARGET_FOLDER}"/USE_POLICY.md" | ||
|
||
for m in ${MODEL_SIZE//,/ } | ||
do | ||
case $m in | ||
7b) | ||
SHARD=0 ;; | ||
13b) | ||
SHARD=1 ;; | ||
34b) | ||
SHARD=3 ;; | ||
7b-Python) | ||
SHARD=0 ;; | ||
13b-Python) | ||
SHARD=1 ;; | ||
34b-Python) | ||
SHARD=3 ;; | ||
7b-Instruct) | ||
SHARD=0 ;; | ||
13b-Instruct) | ||
SHARD=1 ;; | ||
34b-Instruct) | ||
SHARD=3 ;; | ||
*) | ||
echo "Unknown model: $m" | ||
# Function to check for prerequisites | ||
check_prerequisites() { | ||
missing=false | ||
command -v wget >/dev/null 2>&1 || { missing=true; echo "wget is missing."; } | ||
command -v md5sum >/dev/null 2>&1 || { missing=true; echo "md5sum is missing."; } | ||
|
||
if [ "$missing" = true ]; then | ||
echo "Would you like to install the missing prerequisites? (y/n)" | ||
read install | ||
if [ "$install" == "y" ]; then | ||
sudo apt update | ||
sudo apt install -y wget coreutils | ||
else | ||
echo "Exiting because prerequisites are not met." | ||
exit 1 | ||
fi | ||
fi | ||
} | ||
|
||
# Function to log messages with colors | ||
log() { | ||
local message="$1" | ||
local arrow="➜" | ||
echo -e "${YELLOW}${arrow} ${message}${NC}" | sed 's/-e//' | ||
} | ||
|
||
# Function to download a file | ||
download_file() { | ||
local url=$1 | ||
local dest=$2 | ||
local verbose=$3 # Accepts 'true' or 'false' | ||
|
||
if [ "$verbose" == "true" ]; then | ||
wget -c --show-progress $url -O $dest & | ||
else | ||
wget -c --quiet --show-progress $url -O $dest & | ||
fi | ||
} | ||
|
||
# Function to download and verify a model | ||
download_model() { | ||
local model=$1 | ||
local shard=$2 | ||
local presigned_url=$3 | ||
local target_folder=$4 | ||
local verbosity=$5 | ||
local model_path="CodeLlama-$model" | ||
|
||
log "${YELLOW}📦 Downloading ${model_path}${NC}" | ||
mkdir -p ${target_folder}/${model_path} | ||
|
||
for s in $(seq -f "%02g" 0 ${shard}) | ||
do | ||
log "${YELLOW} Downloading ${model_path}/consolidated.${s}.pth${NC}" | ||
download_file ${presigned_url/'*'/"${model_path}/consolidated.${s}.pth"} ${target_folder}/${model_path}/consolidated.${s}.pth ${verbosity} | ||
done | ||
wait | ||
|
||
download_file ${presigned_url/'*'/"${model_path}/params.json"} ${target_folder}/${model_path}/params.json ${verbosity} | ||
download_file ${presigned_url/'*'/"${model_path}/tokenizer.model"} ${target_folder}/${model_path}/tokenizer.model ${verbosity} | ||
download_file ${presigned_url/'*'/"${model_path}/checklist.chk"} ${target_folder}/${model_path}/checklist.chk ${verbosity} | ||
wait | ||
|
||
log "${YELLOW}🔍 Checking checksums for ${model_path}${NC}" | ||
(cd ${target_folder}/${model_path} && md5sum -c checklist.chk) | ||
if [ $? -eq 0 ]; then | ||
log "${GREEN}✅ All files for ${model_path} downloaded and verified successfully!${NC}" | ||
else | ||
log "${RED}❌ Checksum verification failed for ${model_path}${NC}" | ||
exit 1 | ||
esac | ||
fi | ||
} | ||
|
||
# Main script logic | ||
main() { | ||
check_prerequisites | ||
|
||
GREEN='\033[0;32m' | ||
RED='\033[0;31m' | ||
YELLOW='\033[0;33m' | ||
NC='\033[0m' | ||
|
||
MODEL_PATH="CodeLlama-$m" | ||
echo "Downloading ${MODEL_PATH}" | ||
mkdir -p ${TARGET_FOLDER}"/${MODEL_PATH}" | ||
log "${GREEN}======================================" | ||
log " Llama Model Download Utility " | ||
log "======================================${NC}" | ||
|
||
for s in $(seq -f "0%g" 0 ${SHARD}) | ||
log "${YELLOW}📨 Enter the URL from the email: ${NC}" | ||
read PRESIGNED_URL | ||
# Initialize to default verbosity | ||
VERBOSE_DOWNLOAD=false | ||
|
||
log "${YELLOW}Would you like to see download progress? (y/n):${NC}" | ||
read -r VERBOSE_DOWNLOAD_INPUT | ||
|
||
# Convert input to lowercase | ||
VERBOSE_DOWNLOAD_INPUT=$(echo "$VERBOSE_DOWNLOAD_INPUT" | tr '[:upper:]' '[:lower:]') | ||
|
||
if [[ "$VERBOSE_DOWNLOAD_INPUT" == "y" ]]; then | ||
VERBOSE_DOWNLOAD=true | ||
fi | ||
|
||
|
||
ALL_MODELS="7b,13b,34b,7b-Python,13b-Python,34b-Python,7b-Instruct,13b-Instruct,34b-Instruct" | ||
log "${YELLOW}📜 Enter the list of models to download ($ALL_MODELS) example: 7b,13b , or press Enter for all: ${NC}" | ||
read MODEL_SIZE | ||
log "Press 'c' to cancel or any other key to continue." | ||
read -n 1 cont | ||
if [ "$cont" == "c" ]; then | ||
log "${RED}❌ User canceled the operation.${NC}" | ||
exit 0 | ||
fi | ||
|
||
TARGET_FOLDER="downloaded_models" | ||
mkdir -p ${TARGET_FOLDER} | ||
|
||
if [[ $MODEL_SIZE == "" ]]; then | ||
MODEL_SIZE=$ALL_MODELS | ||
fi | ||
|
||
log "${YELLOW}📥 Downloading LICENSE and Acceptable Usage Policy ${NC}" | ||
download_file ${PRESIGNED_URL/'*'/"LICENSE"} ${TARGET_FOLDER}"/LICENSE" ${VERBOSE_DOWNLOAD} | ||
download_file ${PRESIGNED_URL/'*'/"USE_POLICY.md"} ${TARGET_FOLDER}"/USE_POLICY.md" ${VERBOSE_DOWNLOAD} | ||
wait | ||
log "${GREEN}✅ LICENSE and Acceptable Usage Policy downloaded successfully!${NC}" | ||
|
||
for m in ${MODEL_SIZE//,/ } | ||
do | ||
wget ${PRESIGNED_URL/'*'/"${MODEL_PATH}/consolidated.${s}.pth"} -O ${TARGET_FOLDER}"/${MODEL_PATH}/consolidated.${s}.pth" | ||
local SHARD=0 | ||
case $m in | ||
7b) SHARD=0 ;; | ||
13b) SHARD=1 ;; | ||
34b) SHARD=3 ;; | ||
7b-Python) SHARD=0 ;; | ||
13b-Python) SHARD=1 ;; | ||
34b-Python) SHARD=3 ;; | ||
7b-Instruct) SHARD=0 ;; | ||
13b-Instruct) SHARD=1 ;; | ||
34b-Instruct) SHARD=3 ;; | ||
*) | ||
log "${RED}❌ Unknown model: $m${NC}" | ||
exit 1 | ||
esac | ||
download_model $m $SHARD $PRESIGNED_URL $TARGET_FOLDER ${VERBOSE_DOWNLOAD} | ||
done | ||
|
||
wget ${PRESIGNED_URL/'*'/"${MODEL_PATH}/params.json"} -O ${TARGET_FOLDER}"/${MODEL_PATH}/params.json" | ||
wget ${PRESIGNED_URL/'*'/"${MODEL_PATH}/tokenizer.model"} -O ${TARGET_FOLDER}"/${MODEL_PATH}/tokenizer.model" | ||
wget ${PRESIGNED_URL/'*'/"${MODEL_PATH}/checklist.chk"} -O ${TARGET_FOLDER}"/${MODEL_PATH}/checklist.chk" | ||
echo "Checking checksums" | ||
(cd ${TARGET_FOLDER}"/${MODEL_PATH}" && md5sum -c checklist.chk) | ||
done | ||
log "${GREEN}=========================================" | ||
log " Congratulations! Download Completed " | ||
log "=========================================${NC}" | ||
} | ||
|
||
# Execute the main function | ||
main "$@" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a log at line 82, do we need this as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case he changes his mind ;)