Skip to content

Commit

Permalink
feat: allow ilab model download to pull from OCI registries
Browse files Browse the repository at this point in the history
Check if repository supplied during ilab model download meets the URL
structure of an OCI registry. If so, leverage skopeo to copy image layers
into cache, and apply mapping logic to move the model files into the
permanent models directory.

This PR also refactors existing ilab model download code to introduce base
and implementation classes to support multiple downloading backends
(HF vs OCI). Assumes skopeo is installed on the system and uses OCI v1.1

Signed-off-by: Jaideep Rao <jrao@redhat.com>
  • Loading branch information
jaideepr97 committed Jul 24, 2024
1 parent 186a367 commit 500669b
Show file tree
Hide file tree
Showing 5 changed files with 310 additions and 33 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ on:

env:
LC_ALL: en_US.UTF-8
REGISTRY_AUTH_FILE: /run/containers/1001/auth.json

defaults:
run:
Expand Down Expand Up @@ -67,15 +68,15 @@ jobs:
if: matrix.platform != 'macos-latest'
uses: ./.github/actions/free-disk-space

- name: Install the expect package
- name: Install the expect and skopeo package
if: startsWith(matrix.platform, 'ubuntu')
run: |
sudo apt-get install -y expect
sudo apt-get install -y expect skopeo
- name: Install tools on MacOS
if: startsWith(matrix.platform, 'macos')
run: |
brew install expect coreutils bash
brew install expect coreutils bash skopeo
- name: Setup Python ${{ matrix.python }}
uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5.1.1
Expand Down
27 changes: 27 additions & 0 deletions scripts/functional-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,31 @@ fi
# download the latest version of the ilab
ilab model download

test_oci_model_download_with_vllm_backend(){
# Enable globstar for recursive globbing
shopt -s globstar

# Run the ilab model download command with REGISTRY_AUTH_FILE
REGISTRY_AUTH_FILE=$HOME/auth.json ilab model download --repository docker://quay.io/ai-lab/models/granite-7b-lab --release latest --model-dir models/instructlab

patterns=(
"models/instructlab/config.json"
"models/instructlab/tokenizer.json"
"models/instructlab/tokenizer_config.json"
"models/instructlab/*.safetensors"
)

for pattern in "${patterns[@]}"
do
matching_files=("$pattern")
if [ ${#matching_files[@]} -eq 0 ]
then
echo "No files found matching pattern: $pattern"
exit 1
fi
done
}

# check that ilab model serve is working
test_bind_port(){
local formatted_script
Expand Down Expand Up @@ -546,6 +571,8 @@ test_server_chat_template() {
# MAIN #
########
# call cleanup in-between each test so they can run without conflicting with the server/chat process
test_oci_model_download_with_vllm_backend
cleanup
test_bind_port
cleanup
test_ctx_size
Expand Down
6 changes: 6 additions & 0 deletions src/instructlab/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class STORAGE_DIR_NAMES:
ILAB = "instructlab"
DATASETS = "datasets"
CHECKPOINTS = "checkpoints"
OCI = "oci"
MODELS = "models"
TAXONOMY = "taxonomy"
INTERNAL = (
Expand Down Expand Up @@ -98,6 +99,10 @@ def _reset(self):
def CHECKPOINTS_DIR(self) -> str:
return path.join(self._data_dir, STORAGE_DIR_NAMES.CHECKPOINTS)

@property
def OCI_DIR(self) -> str:
return path.join(self._cache_home, STORAGE_DIR_NAMES.OCI)

@property
def DATASETS_DIR(self) -> str:
return path.join(self._data_dir, STORAGE_DIR_NAMES.DATASETS)
Expand Down Expand Up @@ -545,6 +550,7 @@ def ensure_storage_directories_exist():
DEFAULTS._data_dir,
DEFAULTS.CHATLOGS_DIR,
DEFAULTS.CHECKPOINTS_DIR,
DEFAULTS.OCI_DIR,
DEFAULTS.DATASETS_DIR,
DEFAULTS.EVAL_DATA_DIR,
DEFAULTS.INTERNAL_DIR,
Expand Down
Loading

0 comments on commit 500669b

Please sign in to comment.