From 89899bb9916a4b1a3629edc370ec1ac899c8b0d1 Mon Sep 17 00:00:00 2001 From: carlosgjs Date: Fri, 5 Jan 2024 15:29:16 -0800 Subject: [PATCH] Load models from huggingface instead of blob storage (#22) --- .github/actions/deps/action.yaml | 6 +++--- .github/pull_request_template.md | 8 +++---- .github/workflows/pre-commit-ci.yml | 6 +++--- .github/workflows/publish-to-pypi.yml | 1 - .github/workflows/smoke-test.yml | 2 +- .gitignore | 2 +- .mypy.ini | 2 +- .pre-commit-config.yaml | 22 +++++++++++++++----- README.md | 30 +++++++++++++++------------ azureml/conda.yml | 2 +- azureml/eval.yml | 16 +++++++------- azureml/generate.yml | 18 +++++++++------- docs/Makefile | 1 - pyproject.toml | 3 ++- src/.amlignore | 2 +- 15 files changed, 70 insertions(+), 51 deletions(-) diff --git a/.github/actions/deps/action.yaml b/.github/actions/deps/action.yaml index d38d141..04b8c5b 100644 --- a/.github/actions/deps/action.yaml +++ b/.github/actions/deps/action.yaml @@ -13,9 +13,9 @@ runs: python-version: ${{inputs.python-version}} - name: Setup pip shell: sh - run: | + run: | python3 -m ensurepip python3 -m pip install --upgrade pip - - name: Install project + - name: Install project shell: sh - run: pip install ".[dev,train]" \ No newline at end of file + run: pip install ".[dev,train]" diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 76e043c..2745f42 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,17 +1,17 @@ - ## Change Description - -This project was automatically generated using the LINCC-Frameworks -[python-project-template](https://github.com/lincc-frameworks/python-project-template). For more information about the project template see the +This project was automatically generated using the LINCC-Frameworks +[python-project-template](https://github.com/lincc-frameworks/python-project-template). For more information about the project template see the [documentation](https://lincc-ppt.readthedocs.io/en/latest/). ## Dev Guide - Getting Started @@ -31,16 +31,17 @@ Once you have created a new environment, you can install this project for local development using the following commands: ``` ->> pip install -e .'[dev]' +>> pip install -e .'[dev,train]' >> pre-commit install >> conda install pandoc ``` Notes: 1) The single quotes around `'[dev]'` may not be required for your operating system. +3) Look at `pyproject.toml` for other optional dependencies, e.g. you can do `pip install -e ."[dev,train,cuda]"` if you want to use CUDA. 2) `pre-commit install` will initialize pre-commit for this local repository, so that a set of tests will be run prior to completing a local commit. For more - information, see the Python Project Template documentation on + information, see the Python Project Template documentation on [pre-commit](https://lincc-ppt.readthedocs.io/en/latest/practices/precommit.html) 3) Install `pandoc` allows you to verify that automatic rendering of Jupyter notebooks into documentation for ReadTheDocs works as expected. For more information, see @@ -48,7 +49,7 @@ Notes: [Sphinx and Python Notebooks](https://lincc-ppt.readthedocs.io/en/latest/practices/sphinx.html#python-notebooks) -## Running AzureML pipelines +## Running AzureML pipelines This repo contains the evaluation and training pipelines for AutoDoc. @@ -69,21 +70,24 @@ az account set --subscription "" az configure --defaults workspace= group= location= ``` -### Uploading data - -Example: -```sh -az storage blob upload --account-name --container > --file data/data.jsonl -n data/sweetpea/data.jsonl -``` ### Running jobs Prediction ```sh -az ml job create -f azureml/eval.yml --set display_name="Test prediction job" --web +az ml job create -f azureml/eval.yml --set display_name="Test prediction job" --set environment_variables.HF_TOKEN= --web ``` Notes: - `--name` will set the mlflow run id - `--display_name` becomes the name in the experiment dashboard -- `--web` argument will pop-up a browser window for tracking the job. \ No newline at end of file +- `--web` argument will pop-up a browser window for tracking the job. +- The `HF_TOKEN` is required for gated repos, which need authentication + + +### Uploading data + +Example: +```sh +az storage blob upload --account-name --container > --file data/data.jsonl -n data/sweetpea/data.jsonl + ``` diff --git a/azureml/conda.yml b/azureml/conda.yml index f772397..fab3656 100644 --- a/azureml/conda.yml +++ b/azureml/conda.yml @@ -15,4 +15,4 @@ dependencies: - xformers - scipy # This works, while installing from pytorch and cuda from conda does not - - torch==2.0.1 \ No newline at end of file + - torch==2.0.1 diff --git a/azureml/eval.yml b/azureml/eval.yml index ea6953b..1f31ea4 100644 --- a/azureml/eval.yml +++ b/azureml/eval.yml @@ -1,8 +1,8 @@ $schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json command: > - python -m autora.doc.pipelines.main eval + python -m autora.doc.pipelines.main eval ${{inputs.data_dir}}/data.jsonl - --model-path ${{inputs.model_dir}}/llama-2-7b-chat-hf + --model-path ${{inputs.model_path}} --sys-id ${{inputs.sys_id}} --instruc-id ${{inputs.instruc_id}} --param temperature=${{inputs.temperature}} @@ -11,11 +11,13 @@ command: > code: ../src inputs: data_dir: - type: uri_folder + type: uri_folder path: azureml://datastores/workspaceblobstore/paths/data/sweetpea/ - model_dir: - type: uri_folder - path: azureml://datastores/workspaceblobstore/paths/base_models + # Currently models are loading faster directly from HuggingFace vs Azure Blob Storage + # model_dir: + # type: uri_folder + # path: azureml://datastores/workspaceblobstore/paths/base_models + model_path: meta-llama/Llama-2-7b-chat-hf temperature: 0.7 top_p: 0.95 top_k: 40 @@ -35,4 +37,4 @@ environment: # azureml://registries/azureml/environments/acpt-pytorch-2.0-cuda11 display_name: autodoc_prediction compute: azureml:t4cluster experiment_name: evaluation -description: | \ No newline at end of file +description: | diff --git a/azureml/generate.yml b/azureml/generate.yml index d849fcd..7e3f902 100644 --- a/azureml/generate.yml +++ b/azureml/generate.yml @@ -1,28 +1,30 @@ $schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json command: > - python -m autora.doc.pipelines.main generate - --model-path ${{inputs.model_dir}}/llama-2-7b-chat-hf + python -m autora.doc.pipelines.main generate + --model-path ${{inputs.model_path}} --output ./outputs/output.txt --sys-id ${{inputs.sys_id}} --instruc-id ${{inputs.instruc_id}} --param temperature=${{inputs.temperature}} --param top_k=${{inputs.top_k}} --param top_p=${{inputs.top_p}} - autora/doc/pipelines/main.py + autora/doc/pipelines/main.py code: ../src inputs: - model_dir: - type: uri_folder - path: azureml://datastores/workspaceblobstore/paths/base_models + # Currently models are loading faster directly from HuggingFace vs Azure Blob Storage + # model_dir: + # type: uri_folder + # path: azureml://datastores/workspaceblobstore/paths/base_models + model_path: meta-llama/Llama-2-7b-chat-hf temperature: 0.7 top_p: 0.95 top_k: 40 sys_id: SYS_1 instruc_id: INSTR_SWEETP_1 -environment: +environment: image: mcr.microsoft.com/azureml/curated/acpt-pytorch-2.0-cuda11.7:21 conda_file: conda.yml display_name: autodoc_prediction compute: azureml:t4cluster experiment_name: prediction -description: | \ No newline at end of file +description: | diff --git a/docs/Makefile b/docs/Makefile index a5622f1..70d22f1 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -28,4 +28,3 @@ clean: # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). %: Makefile @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) - diff --git a/pyproject.toml b/pyproject.toml index 422c8ff..e1c4382 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,6 +43,7 @@ dev = [ "ipython", # Also used in building notebooks into Sphinx "matplotlib", # Used in sample notebook intro_notebook.ipynb "ipykernel", + "hf_transfer", ] train = [ "jsonlines", @@ -100,4 +101,4 @@ include = ["src/autora"] packages = ["src/autora"] [project.scripts] -autodoc = "autora.doc.pipelines.main:app" \ No newline at end of file +autodoc = "autora.doc.pipelines.main:app" diff --git a/src/.amlignore b/src/.amlignore index f1ec22a..8e62855 100644 --- a/src/.amlignore +++ b/src/.amlignore @@ -1,3 +1,3 @@ mlruns/ .mypy_cache/ -__pycache__/ \ No newline at end of file +__pycache__/