Skip to content

Add ability to cancel model loading #4462

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

Merged
merged 31 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
9abe2e4
llama : Add ability to cancel model load
crasm Dec 14, 2023
3425e62
llama : Add test for model load cancellation
crasm Dec 14, 2023
4b1f70c
Fix bool return in llama_model_load, remove std::ignore use
crasm Dec 14, 2023
1160de3
Update llama.cpp
ggerganov Dec 17, 2023
32ebd52
Fail test if model file is missing
crasm Dec 17, 2023
cb8a4be
Merge branch 'cancel-model-load' of github.com:crasm/llama.cpp into c…
crasm Dec 17, 2023
2796953
Revert "Fail test if model file is missing"
crasm Dec 17, 2023
068e7c4
Add test-model-load-cancel to Makefile
crasm Dec 18, 2023
fe6a6fb
Revert "Revert "Fail test if model file is missing""
crasm Dec 18, 2023
6bba341
Simplify .gitignore for tests, clang-tidy fixes
crasm Dec 18, 2023
fd9d247
Label all ctest tests
crasm Dec 18, 2023
4b63355
ci : ctest uses -L main
crasm Dec 18, 2023
aed3cf8
Attempt at writing ctest_with_model
crasm Dec 18, 2023
f80ff4d
ci : get ci/run.sh working with test-model-load-cancel
crasm Dec 19, 2023
121b04d
ci : restrict .github/workflows/build.yml ctest to -L main
crasm Dec 19, 2023
1e79625
update requirements.txt
crasm Dec 19, 2023
9809314
Disable test-model-load-cancel in make
crasm Dec 19, 2023
9a056ed
Remove venv before creation
crasm Dec 20, 2023
293d16f
Restructure requirements.txt
crasm Dec 20, 2023
267cfa4
Merge commit 'c50e40016394f124b97ce39da48148b1f6c01833' into cancel-m…
crasm Dec 20, 2023
a0eab1e
Make per-python-script requirements work alone
crasm Dec 20, 2023
ca122dc
Add comment
crasm Dec 20, 2023
ba46057
Merge remote-tracking branch 'upstream/master' into cancel-model-load
crasm Dec 20, 2023
b853df4
Add convert-persimmon-to-gguf.py to new requirements.txt scheme
crasm Dec 20, 2023
c9a6de8
Add check-requirements.sh script and GitHub workflow
crasm Dec 21, 2023
e86b8cd
Remove shellcheck installation step from workflow
crasm Dec 21, 2023
bdfe4ba
Add nocleanup special arg
crasm Dec 21, 2023
6bc7411
Merge remote-tracking branch 'upstream' into cancel-model-load
crasm Dec 21, 2023
e438257
Fix merge
crasm Dec 21, 2023
f607e53
reset to upstream/master
crasm Dec 22, 2023
5f2ee1c
Redo changes for cancelling model load
crasm Dec 22, 2023
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
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
id: cmake_test
run: |
cd build
ctest --verbose --timeout 900
ctest -L main --verbose --timeout 900

ubuntu-latest-cmake-sanitizer:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -107,7 +107,7 @@ jobs:
id: cmake_test
run: |
cd build
ctest --verbose --timeout 900
ctest -L main --verbose --timeout 900

ubuntu-latest-cmake-mpi:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -141,7 +141,7 @@ jobs:
id: cmake_test
run: |
cd build
ctest --verbose
ctest -L main --verbose

# TODO: build with LLAMA_NO_METAL because test-backend-ops fail on "Apple Paravirtual device" and I don't know
# how to debug it.
Expand Down Expand Up @@ -202,7 +202,7 @@ jobs:
id: cmake_test
run: |
cd build
ctest --verbose --timeout 900
ctest -L main --verbose --timeout 900

macOS-latest-cmake-ios:
runs-on: macos-latest
Expand Down Expand Up @@ -394,7 +394,7 @@ jobs:
if: ${{ matrix.build != 'clblast' && (matrix.build != 'avx512' || env.HAS_AVX512F == '1') }} # not all machines have native AVX-512
run: |
cd build
ctest -C Release --verbose --timeout 900
ctest -L main -C Release --verbose --timeout 900

- name: Test (Intel SDE)
id: cmake_test_sde
Expand All @@ -406,7 +406,7 @@ jobs:
7z x "-o${env:RUNNER_TEMP}" $env:RUNNER_TEMP/sde.tar
$sde = $(join-path $env:RUNNER_TEMP sde-external-${env:SDE_VERSION}-win/sde.exe)
cd build
& $sde -future -- ctest -C Release --verbose --timeout 900
& $sde -future -- ctest -L main -C Release --verbose --timeout 900

- name: Determine tag name
id: tag
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/python-check-requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Python check requirements.txt

on:
push:
paths:
- 'check-requirements.sh'
- 'convert*.py'
- 'requirements*.txt'
pull_request:
paths:
- 'check-requirements.sh'
- 'convert*.py'
- 'requirements*.txt'

jobs:
python-check-requirements:
runs-on: ubuntu-latest
name: check-requirements
steps:
- name: Check out source repository
uses: actions/checkout@v3
- name: Set up Python environment
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Run check-requirements.sh script
run: bash check-requirements.sh nocleanup
16 changes: 0 additions & 16 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,3 @@ examples/jeopardy/results.txt

poetry.lock
poetry.toml

# Test binaries
/tests/test-grammar-parser
/tests/test-llama-grammar
/tests/test-double-float
/tests/test-grad0
/tests/test-opt
/tests/test-quantize-fns
/tests/test-quantize-perf
/tests/test-sampling
/tests/test-tokenizer-0-llama
/tests/test-tokenizer-0-falcon
/tests/test-tokenizer-1-llama
/tests/test-tokenizer-1-bpe
/tests/test-rope
/tests/test-backend-ops
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ TEST_TARGETS = \
tests/test-quantize-fns tests/test-quantize-perf tests/test-sampling tests/test-tokenizer-0-llama \
tests/test-tokenizer-0-falcon tests/test-tokenizer-1-llama tests/test-tokenizer-1-bpe tests/test-rope \
tests/test-backend-ops
# # TODO(crasm): determine how to run tests that depend on openllama model files with make
# tests/test-model-load-cancel

# Code coverage output files
COV_TARGETS = *.gcno tests/*.gcno *.gcda tests/*.gcda *.gcov tests/*.gcov lcov-report gcovr-report
Expand Down Expand Up @@ -730,3 +732,5 @@ tests/test-c.o: tests/test-c.c llama.h

tests/test-backend-ops: tests/test-backend-ops.cpp ggml.o $(OBJS)
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)

tests/test-model-load-cancel: tests/test-model-load-cancel.cpp ggml.o llama.o $(OBJS)
156 changes: 156 additions & 0 deletions check-requirements.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#!/bin/bash
#
# check-requirements.sh checks all requirements files for each top-level
# convert*.py script.
#
# WARNING: This is quite IO intensive, because a fresh venv is set up for every
# python script.
#
# usage: ./check-requirements.sh [<working_dir>]
# ./check-requirements.sh 'nocleanup' [<working_dir>]
#
# where:
# - <working_dir> is a directory that can be used as the base for
# setting up the venvs. Defaults to `/tmp`.
# - 'nocleanup' as the first argument will disable automatic cleanup
# of the files created by this script.
#
# requires:
# - bash >= 3.2.57
# - shellcheck
#
# For each script, it creates a fresh venv, `pip install -r` the
# requirements, and finally executes the python script with no arguments to
# check for a `ModuleNotFoundError`.
#

log() {
local level="$1"; shift
local format="$1"; shift
# shellcheck disable=SC2059
>&2 printf "$level: $format\n" "$@"
}

info() {
log 'INFO' "$@"
}

fatal() {
log 'FATAL' "$@"
exit 1
}

cleanup() {
if [[ -n ${workdir+x} && -d $workdir && -w $workdir ]]; then
info "Removing $workdir"
(
count=0
rm -rfv "$workdir" | while read -r; do
if (( count++ > 750 )); then
printf '.'
count=0
fi
done
printf '\n'
)&
wait $!
info "Removed '$workdir'"
fi
}

abort() {
cleanup
exit 1
}

if [[ $1 == nocleanup ]]; then
shift # discard nocleanup arg
else
trap abort SIGINT SIGTERM SIGQUIT SIGABRT
trap cleanup EXIT
fi

set -eu -o pipefail
this="$(realpath "$0")"
readonly this
cd "$(dirname "$this")"

shellcheck "$this"

workdir=
if [[ -n ${1+x} ]]; then
arg_dir="$(realpath "$1")"
if [[ ! ( -d $arg_dir && -w $arg_dir ) ]]; then
fatal "$arg_dir is not a valid directory"
fi
workdir="$(mktemp -d "$arg_dir/check-requirements.XXXX")"
else
workdir="$(mktemp -d "/tmp/check-requirements.XXXX")"
fi
readonly workdir

info "Working directory: $workdir"

assert_arg_count() {
local argcount="$1"; shift
if (( $# != argcount )); then
fatal "${FUNCNAME[1]}: incorrect number of args"
fi
}

check_requirements() {
assert_arg_count 2 "$@"
local venv="$1"
local reqs="$2"

info "$reqs: beginning check"
(
# shellcheck source=/dev/null
source "$venv/bin/activate"
pip --disable-pip-version-check install -q -r "$reqs"
)
info "$reqs: OK"
}

check_convert_script() {
assert_arg_count 1 "$@"
local py="$1"
local pyname="${py%.py}"

info "$py: beginning check"

local reqs="requirements-$pyname.txt"
if [[ ! -r "$reqs" ]]; then
fatal "$py missing requirements. Expected: $reqs"
fi

local venv="$workdir/$pyname-venv"
python3 -m venv "$venv"

check_requirements "$venv" "$reqs"
set +e
(
# shellcheck source=/dev/null
source "$venv/bin/activate"
py_err="$workdir/$pyname.out"
python "$py" 2> "$py_err"
>&2 cat "$py_err"
grep -e 'ModuleNotFoundError' "$py_err"
)
set -e
# shellcheck disable=SC2181
(( $? )) && fatal "$py: some imports not declared in $reqs"
info "$py: imports OK"
}

# Check requirements.txt
all_venv="$workdir/all-venv"
python3 -m venv "$all_venv"
check_requirements "$all_venv" 'requirements.txt'

check_convert_script 'convert.py'
for py in convert-*.py; do
check_convert_script "$py"
done

info "Done! No issues found."
Loading