From 565a2f320a2d226c0de921d84a4b6000eb5dfaa1 Mon Sep 17 00:00:00 2001 From: Michael Gschwind Date: Sat, 6 Apr 2024 22:36:33 -0700 Subject: [PATCH] fix minor issues, reduce runtime for macos12 runners --- .github/workflows/compile-macos12.yml | 61 +++++++++++++++++++++++++++ .github/workflows/compile.yml | 24 +++++------ .github/workflows/et.yml | 13 +++--- model_et.py | 2 +- 4 files changed, 81 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/compile-macos12.yml diff --git a/.github/workflows/compile-macos12.yml b/.github/workflows/compile-macos12.yml new file mode 100644 index 000000000..d23a48056 --- /dev/null +++ b/.github/workflows/compile-macos12.yml @@ -0,0 +1,61 @@ +name: Compile main + +on: + push: + branches: + - main + pull_request: + workflow_dispatch: + +jobs: + run-tinystories: + strategy: + matrix: + runner: [macos-12] + runs-on: ${{matrix.runner}} + steps: + - name: Checkout repo + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: 3.11 + - name: Print machine info + run: | + uname -a + if [ $(uname -s) == Darwin ]; then + sysctl machdep.cpu.brand_string + sysctl machdep.cpu.core_count + fi + - name: Install requirements + run: | + pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cpu + pip install -r requirements.txt + - name: Download checkpoints + run: | + mkdir -p checkpoints/stories15M + pushd checkpoints/stories15M + wget https://huggingface.co/karpathy/tinyllamas/resolve/main/stories15M.pt + wget https://github.com/karpathy/llama2.c/raw/master/tokenizer.model + popd + - name: Run inference + run: | + export MODEL_PATH=checkpoints/stories15M/stories15M.pt + export MODEL_NAME=stories15M + export MODEL_OUT=/tmp + python generate.py --checkpoint-path ${MODEL_PATH} --temperature 0 > ./output_eager + cat ./output_eager + python generate.py --compile --checkpoint-path ${MODEL_PATH} --temperature 0 > ./output_compiled + cat ./output_compiled + python export.py --checkpoint-path ${MODEL_PATH} --output-dso-path ${MODEL_OUT}/${MODEL_NAME}.so + python generate.py --checkpoint-path ${MODEL_PATH} --temperature 0 --dso-path ${MODEL_OUT}/${MODEL_NAME}.so > ./output_aoti + cat ./output_aoti + echo "tests complete" + echo "******************************************" + # echo "********* EAGER vs TORCH.COMPILE *********" + # echo "******************************************" + # diff output_eager output_compiled + # echo "******************************************" + # echo "********* EAGER vs AOT INDUCTOR *********" + # echo "******************************************" + # diff output_eager output_aoti diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index 88ae1949b..db77c001b 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -11,7 +11,7 @@ jobs: run-tinystories: strategy: matrix: - runner: [ubuntu-latest, macos-12, macos-14] + runner: [ubuntu-latest, macos-14] runs-on: ${{matrix.runner}} steps: - name: Checkout repo @@ -42,13 +42,13 @@ jobs: run: | export MODEL_PATH=checkpoints/stories15M/stories15M.pt export MODEL_NAME=stories15M - export MODEL_DIR=/tmp + export MODEL_OUT=/tmp python generate.py --checkpoint-path ${MODEL_PATH} --temperature 0 > ./output_eager cat ./output_eager python generate.py --compile --checkpoint-path ${MODEL_PATH} --temperature 0 > ./output_compiled cat ./output_compiled - python export.py --checkpoint-path ${MODEL_PATH} --output-dso-path ${MODEL_DIR}/${MODEL_NAME}.so - python generate.py --checkpoint-path ${MODEL_PATH} --temperature 0 --dso-path ${MODEL_DIR}/${MODEL_NAME}.so > ./output_aoti + python export.py --checkpoint-path ${MODEL_PATH} --output-dso-path ${MODEL_OUT}/${MODEL_NAME}.so + python generate.py --checkpoint-path ${MODEL_PATH} --temperature 0 --dso-path ${MODEL_OUT}/${MODEL_NAME}.so > ./output_aoti cat ./output_aoti echo "******************************************" @@ -58,8 +58,8 @@ jobs: cat ./output_eager python generate.py --compile --quant '{"embedding" : {"bitwidth": 8, "group_size": 0}}' --checkpoint-path ${MODEL_PATH} --temperature 0 > ./output_compiled cat ./output_compiled - python export.py --quant '{"embedding" : {"bitwidth": 8, "group_size": 0}}' --checkpoint-path ${MODEL_PATH} --output-dso-path ${MODEL_DIR}/${MODEL_NAME}.so - python generate.py --checkpoint-path ${MODEL_PATH} --temperature 0 --dso-path ${MODEL_DIR}/${MODEL_NAME}.so > ./output_aoti + python export.py --quant '{"embedding" : {"bitwidth": 8, "group_size": 0}}' --checkpoint-path ${MODEL_PATH} --output-dso-path ${MODEL_OUT}/${MODEL_NAME}.so + python generate.py --checkpoint-path ${MODEL_PATH} --temperature 0 --dso-path ${MODEL_OUT}/${MODEL_NAME}.so > ./output_aoti cat ./output_aoti echo "******************************************" @@ -69,8 +69,8 @@ jobs: cat ./output_eager python generate.py --compile --quant '{"embedding" : {"bitwidth": 8, "group_size": 8}}' --checkpoint-path ${MODEL_PATH} --temperature 0 > ./output_compiled cat ./output_compiled - python export.py --quant '{"embedding" : {"bitwidth": 8, "group_size": 8}}' --checkpoint-path ${MODEL_PATH} --output-dso-path ${MODEL_DIR}/${MODEL_NAME}.so - python generate.py --checkpoint-path ${MODEL_PATH} --temperature 0 --dso-path ${MODEL_DIR}/${MODEL_NAME}.so > ./output_aoti + python export.py --quant '{"embedding" : {"bitwidth": 8, "group_size": 8}}' --checkpoint-path ${MODEL_PATH} --output-dso-path ${MODEL_OUT}/${MODEL_NAME}.so + python generate.py --checkpoint-path ${MODEL_PATH} --temperature 0 --dso-path ${MODEL_OUT}/${MODEL_NAME}.so > ./output_aoti cat ./output_aoti echo "******************************************" @@ -80,8 +80,8 @@ jobs: cat ./output_eager python generate.py --compile --quant '{"linear:int8" : {"bitwidth": 8, "group_size": 0}}' --checkpoint-path ${MODEL_PATH} --temperature 0 > ./output_compiled cat ./output_compiled - python export.py --quant '{"linear:int8" : {"bitwidth": 8, "group_size": 0}}' --checkpoint-path ${MODEL_PATH} --output-dso-path ${MODEL_DIR}/${MODEL_NAME}.so - python generate.py --checkpoint-path ${MODEL_PATH} --temperature 0 --dso-path ${MODEL_DIR}/${MODEL_NAME}.so > ./output_aoti + python export.py --quant '{"linear:int8" : {"bitwidth": 8, "group_size": 0}}' --checkpoint-path ${MODEL_PATH} --output-dso-path ${MODEL_OUT}/${MODEL_NAME}.so + python generate.py --checkpoint-path ${MODEL_PATH} --temperature 0 --dso-path ${MODEL_OUT}/${MODEL_NAME}.so > ./output_aoti cat ./output_aoti echo "******************************************" @@ -91,8 +91,8 @@ jobs: cat ./output_eager python generate.py --compile --quant '{"linear:int8" : {"bitwidth": 8, "group_size": 8}}' --checkpoint-path ${MODEL_PATH} --temperature 0 > ./output_compiled cat ./output_compiled - python export.py --quant '{"linear:int8" : {"bitwidth": 8, "group_size": 8}}' --checkpoint-path ${MODEL_PATH} --output-dso-path ${MODEL_DIR}/${MODEL_NAME}.so - python generate.py --checkpoint-path ${MODEL_PATH} --temperature 0 --dso-path ${MODEL_DIR}/${MODEL_NAME}.so > ./output_aoti + python export.py --quant '{"linear:int8" : {"bitwidth": 8, "group_size": 8}}' --checkpoint-path ${MODEL_PATH} --output-dso-path ${MODEL_OUT}/${MODEL_NAME}.so + python generate.py --checkpoint-path ${MODEL_PATH} --temperature 0 --dso-path ${MODEL_OUT}/${MODEL_NAME}.so > ./output_aoti cat ./output_aoti echo "tests complete" diff --git a/.github/workflows/et.yml b/.github/workflows/et.yml index 378c6544e..f93cc26d2 100644 --- a/.github/workflows/et.yml +++ b/.github/workflows/et.yml @@ -64,12 +64,13 @@ jobs: run: | export MODEL_PATH=${PWD}/checkpoints/stories15M/stories15M.pt export MODEL_NAME=stories15M + export MODEL_OUT=/tmp + + python generate.py --checkpoint-path ${MODEL_PATH} --temperature 0 > ${MODEL_OUT}/output_eager + cat ${MODEL_OUT}/output_eager - python generate.py --checkpoint-path ${MODEL_PATH} --temperature 0 > ${PWD}/output_eager - cat ${PWD}/output_eager - - python export.py --checkpoint-path ${MODEL_PATH} --output-pte-path ${PWD}/${MODEL_NAME}.pte - python generate.py --checkpoint-path ${MODEL_PATH} --temperature 0 --pte-path ${PWD}/${MODEL_NAME}.pte > ${PWD}/output_et - cat ${PWD}/output_et + python export.py --checkpoint-path ${MODEL_PATH} --output-pte-path ${MODEL_OUT}/${MODEL_NAME}.pte + python generate.py --checkpoint-path ${MODEL_PATH} --temperature 0 --pte-path ${MODEL_OUT}/${MODEL_NAME}.pte > ${MODEL_OUT}/output_et + cat ${MODEL_OUT}/output_et echo "Tests complete." diff --git a/model_et.py b/model_et.py index a81fe5fcd..6dac4b3da 100644 --- a/model_et.py +++ b/model_et.py @@ -11,7 +11,7 @@ def __init__(self, config, path) -> None: self.config = config self.model_ = exec_lib._load_for_executorch(str(path)) - def forward(self, idxx, input_pos): + def forward(self, idx, input_pos): # model_.forward expects inputs to be wrapped in a tuple forward_inputs = (idx.to(torch.long), input_pos.to(torch.long)) logits = self.model_.forward(forward_inputs)