Compare commits

...
Author SHA1 Message Date
Rayan DasoriyaandCopybara-Service 44390cbd99 Add a no-op message to check_quota if it fails.
MG_DOCKER_CODES_PIPER_ORIGIN_REV_ID: 792654121
2025-08-08 09:32:08 -07:00
Vertex MG TeamandCopybara-Service 58dab0b1bb E5 notebook
PiperOrigin-RevId: 791999324
2025-08-06 22:48:50 -07:00
Vertex MG TeamandCopybara-Service 8d36834fcd Add GPT OSS models deployment notebook.
PiperOrigin-RevId: 791864273
2025-08-06 15:17:54 -07:00
Dustin LuongandCopybara-Service 31ca3e36f4 Add Qwen3-30B-A3B instruct and thinking 2507 variants to notebook.
PiperOrigin-RevId: 791746627
2025-08-06 10:27:39 -07:00
Vertex MG TeamandCopybara-Service a72d7dc49f Fix custom dataset input for axolotl notebooks.
PiperOrigin-RevId: 791627090
2025-08-06 04:16:45 -07:00
denisj3030andGitHub 9efbd48233 cl41 (#4193) 2025-08-05 17:02:14 +00:00
Vertex MG TeamandCopybara-Service 166f0f8ce7 Update the vLLM container image version.
PiperOrigin-RevId: 790903846
2025-08-04 14:56:59 -07:00
Vertex MG TeamandCopybara-Service bd9f9675cf Add us-south1 region
PiperOrigin-RevId: 790762290
2025-08-04 08:35:53 -07:00
dependabot[bot]GitHubdependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
42ec0e6ad9 Bump urllib3 (#4173)
Bumps [urllib3](https://github.com/urllib3/urllib3) from 2.0.7 to 2.5.0.
- [Release notes](https://github.com/urllib3/urllib3/releases)
- [Changelog](https://github.com/urllib3/urllib3/blob/main/CHANGES.rst)
- [Commits](https://github.com/urllib3/urllib3/compare/2.0.7...2.5.0)

---
updated-dependencies:
- dependency-name: urllib3
  dependency-version: 2.5.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-08-01 14:29:14 +00:00
dependabot[bot]GitHubdependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
fde3d98a2a Bump requests (#4174)
Bumps [requests](https://github.com/psf/requests) from 2.32.3 to 2.32.4.
- [Release notes](https://github.com/psf/requests/releases)
- [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md)
- [Commits](https://github.com/psf/requests/compare/v2.32.3...v2.32.4)

---
updated-dependencies:
- dependency-name: requests
  dependency-version: 2.32.4
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-08-01 14:28:53 +00:00
dependabot[bot]GitHubdependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
b83f869a44 Bump protobuf (#4175)
Bumps [protobuf](https://github.com/protocolbuffers/protobuf) from 3.20.3 to 4.25.8.
- [Release notes](https://github.com/protocolbuffers/protobuf/releases)
- [Changelog](https://github.com/protocolbuffers/protobuf/blob/main/protobuf_release.bzl)
- [Commits](https://github.com/protocolbuffers/protobuf/compare/v3.20.3...v4.25.8)

---
updated-dependencies:
- dependency-name: protobuf
  dependency-version: 4.25.8
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-08-01 14:28:28 +00:00
Vertex MG TeamandCopybara-Service b918768776 add batch prediction
PiperOrigin-RevId: 789643160
2025-08-01 00:21:30 -07:00
Eric DongandGitHub a22aceb10c refactor: Batch update icon links for notebooks/community (#4188) 2025-07-31 15:41:21 +00:00
Dustin LuongandCopybara-Service c8b53a614e Fix text in TEI notebook to change instances of nomic-ai/nomic-embed-text-v1 to Qwen/Qwen3-Embedding-8B.
PiperOrigin-RevId: 789204281
2025-07-30 23:26:39 -07:00
Eric DongandGitHub 7be7d5be44 refactor: Batch update icon links for notebooks/official (#4187) 2025-07-31 00:08:25 +00:00
Eric DongandGitHub 02a030d6f1 fix: Update the icon links (#4186) 2025-07-30 20:37:13 +00:00
Dustin LuongandCopybara-Service fc8e9e4483 Set Qwen/Qwen3-Embedding-8B as example model in TEI notebook.
PiperOrigin-RevId: 788960826
2025-07-30 10:48:47 -07:00
Eliot LaidlawandGitHub fa019e051a Add CSM intro notebook (#4178)
* notebook

* linting

* add codeowner

* Add cleanup

* fixes

* Update copyright year
2025-07-30 16:36:51 +00:00
Dustin LuongandCopybara-Service 01d513eea3 Update the deployment notebook for Qwen3 models to include Qwen3-235B-Thinking-2507 and Qwen3-235B-Thinking-2507-FP8.
PiperOrigin-RevId: 788636454
2025-07-29 15:45:43 -07:00
Vertex MG TeamandCopybara-Service 928822cc0c Remove 8-bit mode for Qwen 2.5 finetuning notebook.
PiperOrigin-RevId: 788499530
2025-07-29 10:02:42 -07:00
Vertex MG TeamandCopybara-Service 1dfb4091ea notebook reformatting
PiperOrigin-RevId: 788430948
2025-07-29 06:34:26 -07:00
Dustin LuongandCopybara-Service ffb5ea7e88 Update HF TEI serving image to use new, FEDRamp compliant container.
PiperOrigin-RevId: 788203719
2025-07-28 16:36:17 -07:00
Vertex MG TeamandCopybara-Service dd2028d76c add batch prediction
PiperOrigin-RevId: 787943651
2025-07-28 04:02:27 -07:00
Vertex MG TeamandCopybara-Service 70daf2e605 Add Qwen3-Coder notebook
PiperOrigin-RevId: 787286540
2025-07-25 16:57:44 -07:00
Vertex MG TeamandCopybara-Service 42db3643d0 Fix pad tokens for custom weights.
MG_DOCKER_CODES_PIPER_ORIGIN_REV_ID: 787196797
2025-07-25 12:14:37 -07:00
Erwin HuizengaandGitHub 66ce2fa5b7 feat: Add sample for Vertex distributed training (#4163)
* feat: Add sample for Vertex distributed training

* refactor: Move distributed training to community content and add job config

* fix: Address review comments and update files

* minor fixes in the script

* updated codeowners
2025-07-23 21:15:09 +02:00
Dustin LuongandCopybara-Service 44a63c8186 Add Qwen3-235B-A22B-Instruct-2507 models to Qwen3 deployment notebook.
PiperOrigin-RevId: 786375387
2025-07-23 12:12:28 -07:00
Vertex MG TeamandCopybara-Service a29f7a376b Wan Deployment Notebook
PiperOrigin-RevId: 786069875
2025-07-22 18:05:53 -07:00
kittyabsandGitHub 66667ea1db Update ray_cluster_management.ipynb (#4171)
Updated to the current version of Ray supported.
2025-07-22 21:40:52 +00:00
Vertex MG TeamandCopybara-Service 0588a7b62d dedicated endpoints enabled
PiperOrigin-RevId: 785721997
2025-07-21 23:25:34 -07:00
Vertex MG TeamandCopybara-Service ba74664aa4 Update the hf-pytorch-inference notebook using the newly built in-house container hf-inference-toolkit.
PiperOrigin-RevId: 785559005
2025-07-21 13:42:01 -07:00
Vertex MG TeamandCopybara-Service 26011283d2 Updates to Flux.1 Schnell and CogVideoX-2b notebook
PiperOrigin-RevId: 785477091
2025-07-21 10:02:34 -07:00
Vertex MG TeamandCopybara-Service 737c635a59 Update auto-scaling documentation link in Model Garden notebooks.
PiperOrigin-RevId: 785450104
2025-07-21 08:40:26 -07:00
Vertex MG TeamandCopybara-Service e998333f34 Update SGLang version in Qwen3 deployment notebook.
PiperOrigin-RevId: 784744196
2025-07-18 16:57:58 -07:00
Changyu ZhuandCopybara-Service 6ea2b5dd24 Update OpenCLIP and BiomedCLIP serving container URI
PiperOrigin-RevId: 784702984
2025-07-18 14:27:46 -07:00
Vertex MG TeamandCopybara-Service 48f9d563a4 No public description
MG_DOCKER_CODES_PIPER_ORIGIN_REV_ID: 784702418
2025-07-18 14:26:19 -07:00
Vertex MG TeamandCopybara-Service 9167c42cbc Fix Gemma3 vllm deployment for 1b model
PiperOrigin-RevId: 784520440
2025-07-18 03:31:48 -07:00
Vertex MG TeamandCopybara-Service 9bd261b2c0 Refactoring the notebook
PiperOrigin-RevId: 784450805
2025-07-17 22:54:34 -07:00
Vertex MG TeamandCopybara-Service 12657051bd No public description
MG_DOCKER_CODES_PIPER_ORIGIN_REV_ID: 784221303
2025-07-17 10:06:59 -07:00
Vertex MG TeamandCopybara-Service b9471efe45 Add DeepSeek-R1-Distill a4x-highgpu-4g GB200 sample notebook.
PiperOrigin-RevId: 784214583
2025-07-17 09:45:17 -07:00
Vertex MG TeamandCopybara-Service 01d8d165da Refactor axolotl notebook.
PiperOrigin-RevId: 784071376
2025-07-17 01:05:08 -07:00
Vertex MG TeamandCopybara-Service de28ab9241 Update nllb notebook to use new container that is FedRamp compliant.
PiperOrigin-RevId: 783613303
2025-07-15 22:52:50 -07:00
Vertex MG TeamandCopybara-Service 52b91234e9 Update owl-vit notebook to use new container that is FedRamp compliant.
PiperOrigin-RevId: 783524069
2025-07-15 17:03:32 -07:00
Aaron DietzGitHubgemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
eaa827959f Update notebook_template_review.py (#4158)
* Update notebook_template_review.py

Added icons to the "Open in" links in our generated list of notebook tutorials

* Update notebooks/notebook_template_review.py

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* Update notebooks/notebook_template_review.py

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* Update notebooks/notebook_template_review.py

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* Update notebooks/notebook_template_review.py

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* Update notebooks/notebook_template_review.py

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
2025-07-15 20:15:50 +00:00
Vertex MG TeamandCopybara-Service 489bdfc092 clean up section is added at the end of the every deployment section
PiperOrigin-RevId: 783221166
2025-07-15 01:00:01 -07:00
Vertex MG TeamandCopybara-Service 2631ce8f3b Refactoring the notebook
PiperOrigin-RevId: 783193023
2025-07-14 23:11:08 -07:00
Vertex MG TeamandCopybara-Service cb3fcaa27e Add support for multiple regions in Hex Deployment
PiperOrigin-RevId: 783168207
2025-07-14 21:26:30 -07:00
Vertex MG TeamandCopybara-Service 6a971663b3 Migrate pytorch-inference docker from 0.1 to 0.4 in notebooks
PiperOrigin-RevId: 783082929
2025-07-14 16:24:47 -07:00
Changyu ZhuandCopybara-Service e29e127d7b Migrate Blip and Blip2 notebooks to use the pytorch-inference container
PiperOrigin-RevId: 782961714
2025-07-14 10:41:52 -07:00
Dustin LuongandCopybara-Service 0ff91f926d Update SAM notebook to use new container that is FedRamp compliant.
PiperOrigin-RevId: 782652376
2025-07-13 14:06:26 -07:00
Vertex MG TeamandCopybara-Service ca19b8f8e7 In Hugging Face TEI notebook, add example to download hf model artifacts and upload to gcs.
PiperOrigin-RevId: 782119696
2025-07-11 14:58:51 -07:00
Rayan DasoriyaandCopybara-Service ad06948c12 Upgrade google-cloud-aiplatform to 1.103.0
PiperOrigin-RevId: 781812082
2025-07-10 21:15:40 -07:00
Dustin LuongandCopybara-Service 7ed8313d37 Add link to timesfm serving docker source code.
PiperOrigin-RevId: 781718474
2025-07-10 15:59:44 -07:00
Vertex MG TeamandCopybara-Service c559851f78 delete mediapipe training container source codes and notebooks.
PiperOrigin-RevId: 781618082
2025-07-10 11:41:52 -07:00
Yichen ZhouandCopybara-Service 7374698440 TimesFM 2.0 notebook demonstrating how to
1. manually deploy a 2.0 docker to an endpoint
2. query the endpoint

PiperOrigin-RevId: 781615204
2025-07-10 11:33:52 -07:00
Vertex MG TeamandCopybara-Service b77fb73ad0 request timeout set to 30 minutes
PiperOrigin-RevId: 781362956
2025-07-09 22:10:38 -07:00
Vertex MG TeamandCopybara-Service f5e9d7a9ed Remove TIMM notebook
PiperOrigin-RevId: 781186738
2025-07-09 13:28:23 -07:00
Vertex MG TeamandCopybara-Service e9c0a56b72 Create T5Gemma local inference notebook
PiperOrigin-RevId: 781066112
2025-07-09 08:32:54 -07:00
Vertex MG TeamandCopybara-Service d4545dbc61 update the training docker image
PiperOrigin-RevId: 780886915
2025-07-08 23:45:47 -07:00
Aaron DietzandGitHub d22db6d795 Update notebook_template_review.py (#4138)
Updates references to Vertex AI Prediction --> Vertex AI Inference (branding name change)
2025-07-07 18:00:41 +00:00
Vertex MG TeamandCopybara-Service 45af74953a delete eval and train job if the job was triggered
PiperOrigin-RevId: 779098485
2025-07-04 02:00:49 -07:00
Vertex MG TeamandCopybara-Service fd5574fa12 No public description
MG_DOCKER_CODES_PIPER_ORIGIN_REV_ID: 776672423
2025-07-02 19:34:48 -07:00
Vertex MG TeamandCopybara-Service 85fa955e6d Update vLLM container version in QwQ deployment notebook.
PiperOrigin-RevId: 778559325
2025-07-02 10:34:24 -07:00
Vertex MG TeamandCopybara-Service bbed90a494 Remove JAX Keras TPU train related contents from Gemma finetuning notebook. This path has been deprecated.
PiperOrigin-RevId: 778151963
2025-07-01 12:47:44 -07:00
denisj3030andGitHub a037d2bd78 marking opus 3 as deprecated (#4132) 2025-07-01 15:52:35 +00:00
Vertex MG TeamandCopybara-Service 5de7f31c07 Update SGLang container URI in Gemma 3n deployment notebook.
PiperOrigin-RevId: 776711854
2025-06-27 14:08:28 -07:00
Vertex MG TeamandCopybara-Service c8b50b4195 No public description
MG_DOCKER_CODES_PIPER_ORIGIN_REV_ID: 776379870
2025-06-27 10:07:48 -07:00
denisj3030andGitHub 4589293efc global endpoint opus4 (#4128) 2025-06-27 15:33:11 +00:00
Mend RenovateandGitHub bdf5745870 chore(deps): update dependency pyupgrade to v3.20.0 (#4071) 2025-06-26 18:29:58 +00:00
dependabot[bot]GitHubdependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
a4b5c22aa2 Bump torch (#4083)
Bumps [torch](https://github.com/pytorch/pytorch) from 2.2.0 to 2.7.0.
- [Release notes](https://github.com/pytorch/pytorch/releases)
- [Changelog](https://github.com/pytorch/pytorch/blob/main/RELEASE.md)
- [Commits](https://github.com/pytorch/pytorch/compare/v2.2.0...v2.7.0)

---
updated-dependencies:
- dependency-name: torch
  dependency-version: 2.7.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-06-26 18:29:07 +00:00
Mend RenovateandGitHub ecfddc0edc chore(deps): update dependency flake8 to v7.3.0 (#4117) 2025-06-26 18:28:08 +00:00
Vertex MG TeamandCopybara-Service 385a8ca2ea Add vLLM + TPU Llama 3.1 and Qwen3 deployment notebook.
PiperOrigin-RevId: 776200752
2025-06-26 10:51:55 -07:00
Vertex MG TeamandCopybara-Service 0e91687156 Add Gemma 3n deployment notebook.
PiperOrigin-RevId: 776158991
2025-06-26 08:59:35 -07:00
Vertex MG TeamandCopybara-Service d04c79b378 additional check for fast deploy option
PiperOrigin-RevId: 775677059
2025-06-25 07:20:11 -07:00
Harizo RajaonaandGitHub ff8a9b9ac5 (WIP) [Mistral] - Add dedicated OCR notebook (#4088)
* Add dedicated OCR notebook

* - Remove OCR mentions in initial notebook
- Clear outputs and variable names in OCR notebook

* Fix

* Fix
2025-06-24 19:42:48 +00:00
Vertex MG TeamandCopybara-Service 5676d07dbd Add Gemma3 axolotl notebook.
PiperOrigin-RevId: 775074649
2025-06-23 22:45:29 -07:00
denisj3030andGitHub be1f7aa631 adding 2nd anthropic notebook (#4118)
* adding 2nd anthropic notebook

* adding 2nd anthropic notebook, links

* adding 2nd anthropic notebook, links fixed
2025-06-23 15:15:35 +00:00
Rayan DasoriyaandCopybara-Service 630de0bea8 Fix title link for workbench.
PiperOrigin-RevId: 774135635
2025-06-21 09:15:34 -07:00
Vertex MG TeamandCopybara-Service e7da210369 Remove the colab notebook for model vit-gpt2-image-captioning. The model card of which was deleted.
PiperOrigin-RevId: 773761048
2025-06-20 10:44:44 -07:00
Vertex MG TeamandCopybara-Service c57dd78a86 Formatting and refactoring of Imagebind notebook
PiperOrigin-RevId: 773680664
2025-06-20 06:45:30 -07:00
Rayan DasoriyaandCopybara-Service 4b5fe2c3cc Upgrade google-cloud-aiplatform version
PiperOrigin-RevId: 773655271
2025-06-20 05:15:21 -07:00
Vertex MG TeamandCopybara-Service 92e0c1b1c7 Formatting and refactoring of Detectron2 Notebook notebook
PiperOrigin-RevId: 772946944
2025-06-18 09:18:11 -07:00
e563a66114 Add support for tpu v6e quota check (#4111)
Co-authored-by: Rayan Dasoriya <dasoriya@google.com>
2025-06-17 13:01:19 +00:00
Vertex MG TeamandCopybara-Service de13d8c65c Llama 4 notebook fixes
PiperOrigin-RevId: 772098038
2025-06-16 11:09:45 -07:00
Vertex MG TeamandCopybara-Service a72b7bc9b0 The main changes:
- `get_deployment_pod_name` now extract the app selector to query the pods
- remove dependency to service, using instead pod port instead
- adds a `POD_PORT` as template variable to allow to pass the port from the UI

PiperOrigin-RevId: 771205143
2025-06-13 13:28:12 -07:00
Rayan DasoriyaandCopybara-Service e1cd3ce080 Fix broken github logo
PiperOrigin-RevId: 771161276
2025-06-13 11:23:05 -07:00
Rayan DasoriyaandCopybara-Service c18f3754e1 Update github logo link
PiperOrigin-RevId: 770866301
2025-06-12 18:00:09 -07:00
Rayan DasoriyaandCopybara-Service 844bfbd2d6 Fix notebook issues for kerasnlp to vertex ai
PiperOrigin-RevId: 770865678
2025-06-12 17:57:46 -07:00
Vertex MG TeamandCopybara-Service a9a512cdc4 Dedicated Endpoint Support for SDXL Dreambooth LoRA Finetuning
PiperOrigin-RevId: 770624167
2025-06-12 06:21:39 -07:00
Vertex MG TeamandCopybara-Service 51b2be8ab4 Formatting and refactoring of Falcon Instruct notebook
PiperOrigin-RevId: 770611011
2025-06-12 05:38:21 -07:00
Vertex MG TeamandCopybara-Service ca52e70dcf E5 Notebook to support dedicated endpoint
PiperOrigin-RevId: 770609921
2025-06-12 05:34:23 -07:00
Vertex MG TeamandCopybara-Service 2fe032efcb Updating Llama 4 Notebook
PiperOrigin-RevId: 770307483
2025-06-11 13:57:45 -07:00
Vertex MG TeamandCopybara-Service 1f3a7418f4 chore: Remove preview in import path
PiperOrigin-RevId: 770211946
2025-06-11 10:27:15 -07:00
Vertex MG TeamandCopybara-Service afacbe8ba6 Remove the usage of Service Account and support VPC-SC and refactoring
PiperOrigin-RevId: 769558936
2025-06-10 04:03:34 -07:00
Vertex MG TeamandCopybara-Service 74376f2787 Refactor qwen3 axolotl notebook.
PiperOrigin-RevId: 769218301
2025-06-09 11:12:47 -07:00
Vertex MG TeamandCopybara-Service abc0e9dec4 Formatting and refactoring
PiperOrigin-RevId: 769180142
2025-06-09 09:40:16 -07:00
d0fb60fb7d Add optional support for global quota check (#4096)
Co-authored-by: Rayan Dasoriya <dasoriya@google.com>
2025-06-06 12:20:26 +00:00
Vertex MG TeamandCopybara-Service 7d4fb0ff8d Formatting and refactoring
PiperOrigin-RevId: 767152796
2025-06-04 08:18:32 -07:00
Vertex MG TeamandCopybara-Service a6e69a4561 Formatting and refactoring of llama3_1 deployment
PiperOrigin-RevId: 767043085
2025-06-04 02:05:07 -07:00
Vertex MG TeamandCopybara-Service fdaa5a6b90 Formatting and refactoring of Qwen2 deployment notebook
PiperOrigin-RevId: 767042986
2025-06-04 02:03:46 -07:00
Vertex MG TeamandCopybara-Service 5ba56dfc71 Formatting and refactoring
PiperOrigin-RevId: 766516226
2025-06-03 00:05:09 -07:00
Vertex MG TeamandCopybara-Service 4c04abe724 Formatting and refactoring
PiperOrigin-RevId: 766506385
2025-06-02 23:31:56 -07:00
Genquan DuanandCopybara-Service 67a2f84f6e Add deployment examples of gemma3 to the agent notebook.
PiperOrigin-RevId: 766375463
2025-06-02 15:54:32 -07:00
Vertex MG TeamandCopybara-Service 53d58f16a4 Update deepseek deployment notebook to include DeepSeek-R1-0528.
PiperOrigin-RevId: 766335072
2025-06-02 14:06:15 -07:00
Genquan DuanandCopybara-Service f27aec1295 Add deployment examples of llama3/llama4/deepseek-r1 to the agent notebook.
PiperOrigin-RevId: 766321906
2025-06-02 13:33:37 -07:00
Rayan DasoriyaandCopybara-Service 559e476170 Add location specific param to trtllm deployment
PiperOrigin-RevId: 766116147
2025-06-02 03:24:41 -07:00
Vertex MG TeamandCopybara-Service cea8a8dfd9 Add failure check to local inference and local merge command.
PiperOrigin-RevId: 765481008
2025-05-30 23:27:06 -07:00
Vertex MG TeamandCopybara-Service 931ddb5fc0 Modify llama3.3 finetuning notebook to support DeepSeek-R1-Distill-Llama-70B.
PiperOrigin-RevId: 765450688
2025-05-30 21:08:58 -07:00
Vertex MG TeamandCopybara-Service 53d5932a63 Add deepseek-ai/DeepSeek-R1-0528-Qwen3-8B as a supported variant to the qwen3 tuning notebook.
PiperOrigin-RevId: 765286156
2025-05-30 12:11:36 -07:00
Vertex MG TeamandCopybara-Service adc0882b53 Add VPC SC feature and minor reformatting
PiperOrigin-RevId: 764996423
2025-05-29 20:19:46 -07:00
Vertex MG TeamandCopybara-Service daeb35986e Update working dir for qwen3 axolotl notebook.
PiperOrigin-RevId: 764995079
2025-05-29 20:15:10 -07:00
Vertex MG TeamandCopybara-Service 75a70e31c6 Add cli inference option to Axolotl qwen3 notebook.
PiperOrigin-RevId: 764993668
2025-05-29 20:10:12 -07:00
Vertex MG TeamandCopybara-Service f869a657d3 Formatting and refactoring
PiperOrigin-RevId: 764616237
2025-05-29 01:14:25 -07:00
Vertex MG TeamandCopybara-Service fcbb01480b Update axolotl notebook with latest successful configs.
PiperOrigin-RevId: 764071402
2025-05-27 20:51:00 -07:00
Vertex MG TeamandCopybara-Service 655634c236 [FIX] Minor fixes for the Cosmos 1.0 notebook
PiperOrigin-RevId: 764037909
2025-05-27 18:59:55 -07:00
Rayan DasoriyaandCopybara-Service b21fbe8b7e Use trtllm_region for trtllm deployment
PiperOrigin-RevId: 764029854
2025-05-27 18:26:35 -07:00
Genquan DuanandCopybara-Service 21bb972b85 rename notebook name as model_garden_integration_with_agent, which provides examples for adk/agent engine etc.
PiperOrigin-RevId: 763954229
2025-05-27 14:42:51 -07:00
Genquan DuanandCopybara-Service 0fcf2fb285 This notebook shows how to deploy OSS models and integrate with Agent Engine.
PiperOrigin-RevId: 763875104
2025-05-27 11:22:38 -07:00
denisj3030andGitHub 9ce448e0a4 Ocr small fix (#4070)
* adding mistral ocr

* adding mistral ocr

* fix missing ]

* fix codestral ver

* small fixed
2025-05-23 17:45:43 +00:00
denisj3030andGitHub ca8cb4480a adding mistral ocr (#4069)
* adding mistral ocr

* adding mistral ocr

* fix missing ]

* fix codestral ver
2025-05-23 16:03:27 +00:00
Rayan DasoriyaandCopybara-Service 5e4bdf4a2c Add different variable name for trtllm accelerator type
PiperOrigin-RevId: 762039341
2025-05-22 11:04:55 -07:00
denisj3030andGitHub 011422636f adding Anthropic v4 (#4065)
* adding v4

* adding v4 lint fix

* adding v4 lint fix

* adding v4 lint fix
2025-05-22 17:43:28 +00:00
Vertex MG TeamandCopybara-Service dace15a300 Publish Qwen3 Axolotl Notebook.
PiperOrigin-RevId: 761753984
2025-05-21 18:51:56 -07:00
Changyu ZhuandCopybara-Service f3134943a4 Update SGLang docker version in Mode Garden DeepSeek deployment notebook.
PiperOrigin-RevId: 761742957
2025-05-21 18:06:23 -07:00
skarukasandGitHub 5eb0a7e114 Update embedding notebooks to reference gemini-embedding-001 (#4058)
* Update embedding notebooks to reference gemini-embedding-001

* Update embedding notebooks to reference gemini-embedding-001
2025-05-21 12:52:44 +00:00
Rayan DasoriyaandCopybara-Service 48ead2727f Fix llama notebooks
PiperOrigin-RevId: 761112151
2025-05-20 09:22:11 -07:00
Vertex MG TeamandCopybara-Service dbb226a7a4 Update the vllm demo notebook to use the vanilla container image.
PiperOrigin-RevId: 760757673
2025-05-19 13:53:14 -07:00
Changyu ZhuandCopybara-Service 04352e92cc Add TensorRT-LLM deployment sample to Deepseek and Llama3.3 notebooks.
PiperOrigin-RevId: 759818622
2025-05-16 17:44:44 -07:00
Genquan DuanandCopybara-Service 23975591bc Add notebook examples for smooth integration of vmg oss llms + adk.
PiperOrigin-RevId: 759741078
2025-05-16 13:46:02 -07:00
Vertex MG TeamandCopybara-Service 9027adebc2 [VMG Tutorial] Create serving notebook tutorial for hexLLM Llama 3 deep dive.
PiperOrigin-RevId: 759632399
2025-05-16 08:52:42 -07:00
Vertex MG TeamandCopybara-Service ce05c8af80 Fix indentation error in the Fast deploy Chat Completion
PiperOrigin-RevId: 759431771
2025-05-15 21:18:07 -07:00
Vertex MG TeamandCopybara-Service cfb870a323 Updated Llama 4 notebook
PiperOrigin-RevId: 759146983
2025-05-15 07:53:14 -07:00
22709379dd feat: Add prediction dedicated endpoint colab sample (#3942)
* feat: Add prediction dedicated endpoint colab sample

* Update get_started_with_dedicated_endpoint.ipynb

---------

Co-authored-by: TJ(Tianjiao) Liu <tianjiaoliu@google.com>
2025-05-15 01:14:40 +00:00
Vertex MG TeamandCopybara-Service 4aafcfb40f Add qwen3 specific instruction to runtime creation.
PiperOrigin-RevId: 758737197
2025-05-14 10:21:56 -07:00
Rayan DasoriyaandCopybara-Service d53aa0c816 Fix gemma2 notebook
PiperOrigin-RevId: 758283299
2025-05-13 10:43:57 -07:00
Rayan DasoriyaandCopybara-Service 21976bf94f Clarify the HF token requirement
PiperOrigin-RevId: 758277776
2025-05-13 10:33:15 -07:00
Vertex MG TeamandCopybara-Service 434e8ac8fc [Fix] Add NVIDIA_A100_80GB option to vertex finetuning.
PiperOrigin-RevId: 757854822
2025-05-12 11:55:28 -07:00
Vertex MG TeamandCopybara-Service 2376532e3d Fix A100_80GB machine type.
PiperOrigin-RevId: 757734855
2025-05-12 06:17:50 -07:00
Vertex MG TeamandCopybara-Service 8b2fbe3f34 Make runtime connection instructions clearer for axolotl notebook.
PiperOrigin-RevId: 757720267
2025-05-12 05:29:51 -07:00
Vertex MG TeamandCopybara-Service f991ae44ab Fix local finetuning for axolotl.
PiperOrigin-RevId: 757655772
2025-05-12 02:01:51 -07:00
Dustin LuongandCopybara-Service 7eb8b76d19 Remove reference server deployment and inference from llama3.2 notebook.
PiperOrigin-RevId: 757455670
2025-05-11 11:01:47 -07:00
Vertex MG TeamandCopybara-Service 7da9c0b644 Remove a3-ultragpu from Axolotl notebook.
PiperOrigin-RevId: 756910136
2025-05-09 14:35:55 -07:00
Genquan DuanandCopybara-Service 46a75498d2 Update notebook to add more machine type suggestions, and support allowlisted real-time forecasting for graph_operational model.
PiperOrigin-RevId: 756860759
2025-05-09 12:17:35 -07:00
Vertex MG TeamandCopybara-Service c2208eb454 Fix hf cache dir for local finetuning and use gcsfuse for local training and merging of model.
PiperOrigin-RevId: 756772796
2025-05-09 08:15:32 -07:00
Vertex MG TeamandCopybara-Service f9c43d4a8a Add a3-ultragpu with dws to Axolotl notebook.
PiperOrigin-RevId: 756625405
2025-05-08 23:39:48 -07:00
Vertex MG TeamandCopybara-Service 32ae5b4af0 Add gpu type check in axolotl local run.
PiperOrigin-RevId: 756598801
2025-05-08 22:04:50 -07:00
Vertex MG TeamandCopybara-Service 2345f89625 Refactoring and minor fixes
PiperOrigin-RevId: 756570419
2025-05-08 20:25:13 -07:00
Vertex MG TeamandCopybara-Service 46a80b731b Add Dia-1.6B serving notebook
PiperOrigin-RevId: 756499377
2025-05-08 16:13:17 -07:00
Vertex MG TeamandCopybara-Service 2781808a96 Add n1+T4 as one deployment option for e5 model.
PiperOrigin-RevId: 756479268
2025-05-08 15:16:27 -07:00
Vertex MG TeamandCopybara-Service 5af1bc523d Fix Axolotl installation.
PiperOrigin-RevId: 756401696
2025-05-08 11:54:00 -07:00
Rayan DasoriyaandCopybara-Service 9742d29e51 Add eval harness support for Qwen2.5 finetuning notebook
PiperOrigin-RevId: 756350741
2025-05-08 09:50:30 -07:00
Vertex MG TeamandCopybara-Service 30fda48397 change default gpu type as empty to avoid unintended gpu runtime creation
PiperOrigin-RevId: 756199290
2025-05-08 01:17:09 -07:00
Vertex MG TeamandCopybara-Service 6888728be5 Fix dataset vars definition issue and make runtime creation session optional in Axolotl notebook.
PiperOrigin-RevId: 756138907
2025-05-07 21:40:57 -07:00
Vertex MG TeamandCopybara-Service 8c7fbc6210 Phi-4 reasoning variants
PiperOrigin-RevId: 756047269
2025-05-07 16:17:35 -07:00
Dustin LuongandCopybara-Service 4c4e224d31 Update Qwen3 deployment notebook with FP8 support.
PiperOrigin-RevId: 756041267
2025-05-07 15:59:11 -07:00
Vertex MG TeamandCopybara-Service ac98f72005 Fix runtime creation codes in Axolotl notebook to disallow L4x16 combination.
PiperOrigin-RevId: 755968781
2025-05-07 12:51:45 -07:00
Vertex MG TeamandCopybara-Service ddebceb70c Support Workbench in Gemma 2 tuning notebook
PiperOrigin-RevId: 755884581
2025-05-07 09:24:14 -07:00
Vertex MG TeamandCopybara-Service d8e5c3b461 Update Axolotl finetuning notebook to support Qwen3.
PiperOrigin-RevId: 755577906
2025-05-06 16:52:10 -07:00
Eric DongandGitHub 0bfe70afcd refactor: remove runtime reboot (#4026)
* refactor: remove runtime reboot

* Remove spaces

* Use %pip instead

* Update model path

* Update BQ path

* Downgrade numpy for backfoward compability
2025-05-05 21:12:55 +00:00
Ravi DalalandGitHub 7488a5dc27 upgraded spark on ray on vertex ai notebook to 2.42.0 version (#4027)
* upgraded spark on ray on vertex ai notebook to 2.42.0 version

* upgraded spark on ray on vertex ai notebook to 2.42.0 version

* upgraded spark on ray on vertex ai notebook to 2.42.0 version

* upgraded spark on ray on vertex ai notebook to 2.42.0 version
2025-05-05 19:05:30 +00:00
Vertex MG TeamandCopybara-Service 4914987998 Update Axolotl docker version for the finetuning notebook
PiperOrigin-RevId: 754984828
2025-05-05 10:20:32 -07:00
Vertex MG TeamandCopybara-Service abd30065d0 Add support for dedicated endpoint in paligemma finetuning
PiperOrigin-RevId: 753860258
2025-05-01 22:26:25 -07:00
Dustin LuongandCopybara-Service 68960f1221 Add SDK deploy option to Qwen3 deployment notebook.
PiperOrigin-RevId: 753636431
2025-05-01 10:17:08 -07:00
Vertex MG TeamandCopybara-Service 836d1ebbd1 No public description
PiperOrigin-RevId: 753635866
2025-05-01 10:15:36 -07:00
Vertex MG TeamandCopybara-Service f96c830a66 chore: Add back faster_deploy_enabled in deploy SDK.
PiperOrigin-RevId: 753454732
2025-04-30 23:17:36 -07:00
Dustin LuongandCopybara-Service ecd1fc28d2 Set model id to GCS bucket for Qwen3 235B model for better stability.
PiperOrigin-RevId: 753430192
2025-04-30 21:33:20 -07:00
Vertex MG TeamandCopybara-Service da0874682f Set dedicate endpoint as default for model_garden_finetuning_tutorial
PiperOrigin-RevId: 753294164
2025-04-30 13:38:52 -07:00
Dustin LuongandCopybara-Service e851c1ad99 Upload Qwen3 deployment notebook.
PiperOrigin-RevId: 753265446
2025-04-30 12:19:21 -07:00
Vertex MG TeamandCopybara-Service 93fd7088ba Add deployment options for the smaller Qwen 2.5 model versions too in the finetuning notebook.
PiperOrigin-RevId: 753246638
2025-04-30 11:30:02 -07:00
Vertex MG TeamandCopybara-Service cab440a05b Fixes for Llama Prompt Guard variant to deployment notebook.
PiperOrigin-RevId: 752852958
2025-04-29 13:08:40 -07:00
Vertex MG TeamandCopybara-Service f03f88a0f7 Add Llama Prompt Guard variant to deployment notebook.
PiperOrigin-RevId: 752802325
2025-04-29 10:58:25 -07:00
Vertex MG TeamandCopybara-Service 841fbf9f53 Add Llama Guard variant to deployment notebook.
PiperOrigin-RevId: 752801901
2025-04-29 10:56:47 -07:00
Vertex MG TeamandCopybara-Service bed0c09ad9 Add Model Garden deploy SDK
PiperOrigin-RevId: 752589085
2025-04-28 22:43:24 -07:00
Vertex MG TeamandCopybara-Service 2497476009 Remove 0.5B and 1.5B Qwen 2.5 models from the notebook
PiperOrigin-RevId: 752453505
2025-04-28 14:42:09 -07:00
Eric DongandGitHub 5e2841384f refactor: Use raw string in regex (#4016)
* refactor: Use raw string in regex

* np.NaN was removed in the NumPy 2.0

* Move default python version to 3.10

* Move back default python version to 3.9

* Remove version mistmatched tes notebooks
2025-04-28 19:54:44 +00:00
49de587b2c Add optional support for dedicated endpoint (#4014)
Co-authored-by: Rayan Dasoriya <dasoriya@google.com>
2025-04-28 12:03:33 +00:00
Vertex MG TeamandCopybara-Service feea47a206 Enable the use of dedicated Endpoints in instructpix2pix notebook
PiperOrigin-RevId: 751641417
2025-04-25 19:45:08 -07:00
Vertex MG TeamandCopybara-Service f4b1b277cf Add HiDream-I1 serving notebook
PiperOrigin-RevId: 751521086
2025-04-25 12:38:34 -07:00
Vertex MG TeamandCopybara-Service e4608c983b chore: Clean up endpoint resource names.
PiperOrigin-RevId: 751415593
2025-04-25 07:58:12 -07:00
Vertex MG TeamandCopybara-Service f147b50332 Support VPC-SC.
PiperOrigin-RevId: 751028021
2025-04-24 09:45:20 -07:00
Changyu ZhuandCopybara-Service b1b16f718b Fix missing positional argument in DeepSeek deployment notebook
PiperOrigin-RevId: 750742323
2025-04-23 15:19:37 -07:00
Vertex MG TeamandCopybara-Service 871eb25dc3 Deprecate the colab notebooks for a few models.
PiperOrigin-RevId: 750692428
2025-04-23 12:54:53 -07:00
denisj3030andGitHub 793515bac2 Launchpad qodo (#3994)
* launchpad notebooks

* Update ai21labs_intro.ipynb

* Update ai21labs_intro.ipynb

* launchpad

* audio play

* lint fixes

* Update ai21labs_intro.ipynb

* Update cambai_intro.ipynb

* Update cambai_intro.ipynb

* Update cambai_intro.ipynb

* qodo lint
2025-04-22 15:25:46 +00:00
Vertex MG TeamandCopybara-Service 4496842a86 Support VPC-SC. Add Model Garden deploy SDK
PiperOrigin-RevId: 750197006
2025-04-22 08:12:30 -07:00
Vertex MG TeamandCopybara-Service 0687238a97 Refactoring
PiperOrigin-RevId: 750127462
2025-04-22 03:47:19 -07:00
Vertex MG TeamandCopybara-Service cd9120bc15 Support VPC-SC. Add Model Garden deploy SDK
PiperOrigin-RevId: 749803092
2025-04-21 08:20:30 -07:00
Vertex MG TeamandCopybara-Service 77388979d7 Add Qwen 2.5 PEFT finetuning notebook
PiperOrigin-RevId: 748978717
2025-04-18 02:28:04 -07:00
Vertex MG TeamandCopybara-Service d9198306a8 Support dedicated endpoints
PiperOrigin-RevId: 748922184
2025-04-17 21:48:54 -07:00
Vertex MG TeamandCopybara-Service 093e32658b Fix check_quota fn for eval in finetuning notebooks
PiperOrigin-RevId: 748701270
2025-04-17 09:09:24 -07:00
Vertex MG TeamandCopybara-Service e6821c94c9 Add a link to file bugs
PiperOrigin-RevId: 748650287
2025-04-17 05:41:07 -07:00
Vertex MG TeamandCopybara-Service 2fbf8c4379 Workbench support and refactoring
PiperOrigin-RevId: 748167158
2025-04-15 23:09:41 -07:00
Vertex MG TeamandCopybara-Service 257c478ef3 Support VPC-SC. Add Model Garden deploy SDK
PiperOrigin-RevId: 748076170
2025-04-15 17:06:01 -07:00
Vertex MG TeamandCopybara-Service 9ce7e61434 Support VPC-SC. Add Model Garden deploy SDK
PiperOrigin-RevId: 748075941
2025-04-15 17:04:26 -07:00
denisj3030andGitHub 42fa7ac1a3 lint fixed (#3993)
* launchpad notebooks

* Update ai21labs_intro.ipynb

* Update ai21labs_intro.ipynb

* launchpad

* audio play

* lint fixes

* Update ai21labs_intro.ipynb

* Update cambai_intro.ipynb

* Update cambai_intro.ipynb

* Update cambai_intro.ipynb
2025-04-15 17:15:08 +00:00
85d43c76ca Add metadata filtering to image warehouse SDK notebook (#3959)
* Add metadata filtering to image warehouse SDK notebook.

* Add metadata filtering to image warehouse SDK notebook and installing dependencies

* linter fix

* Linter fix

* Fix formatting in image_warehouse_sdk notebook

* Fix formatting in image_warehouse_sdk notebook

---------

Co-authored-by: Yehia Elshater <elshater@google.com>
2025-04-15 12:31:27 +00:00
9f4d837e54 Update peft code for stable_20250409 (#3991)
Co-authored-by: Rayan Dasoriya <dasoriya@google.com>
2025-04-15 12:29:40 +00:00
Minwoo ParkandCopybara-Service 27db486275 Improve paligemma notebook documentation.
PiperOrigin-RevId: 747492281
2025-04-14 11:09:52 -07:00
Vertex MG TeamandCopybara-Service 2df60d7862 Fix dedicated endpoint codellama
PiperOrigin-RevId: 747448256
2025-04-14 09:22:18 -07:00
Vertex MG TeamandCopybara-Service 7850587517 Support VPC-SC and workbench
PiperOrigin-RevId: 747376863
2025-04-14 05:41:22 -07:00
Vertex MG TeamandCopybara-Service b924278b03 Add lm eval harness to the finetuning notebook
PiperOrigin-RevId: 747343434
2025-04-14 03:44:40 -07:00
Vertex MG TeamandCopybara-Service adb16ca8b4 Update cell ordering in Llama 4 MaaS notebook.
PiperOrigin-RevId: 746284188
2025-04-10 20:47:06 -07:00
Vertex MG TeamandCopybara-Service 42383514ff Add linter change for Llama 4 MaaS notebook.
PiperOrigin-RevId: 746223674
2025-04-10 16:48:23 -07:00
Vertex MG TeamandCopybara-Service 2609db529e Add Llama 4 MaaS Notebook
PiperOrigin-RevId: 746217133
2025-04-10 16:27:22 -07:00
Vertex MG TeamandCopybara-Service 632385c6bc Support VPC-SC and workbench
PiperOrigin-RevId: 746058497
2025-04-10 09:21:44 -07:00
Vertex MG TeamandCopybara-Service 4c4519f679 Support VPC-SC. Add Model Garden deploy SDK
PiperOrigin-RevId: 746057566
2025-04-10 09:18:53 -07:00
Vertex MG TeamandCopybara-Service 98cded3a79 Fix chat completion in model_garden_pytorch_llama3_2_deployment.ipynb
PiperOrigin-RevId: 745642276
2025-04-09 10:26:41 -07:00
Vertex MG TeamandCopybara-Service 8c37e3995b Set dedicate endpoint as default for some model garden samples
PiperOrigin-RevId: 745421163
2025-04-08 21:47:01 -07:00
Vertex MG TeamandCopybara-Service 1281bce438 see b/380317852 for details
PiperOrigin-RevId: 745345688
2025-04-08 17:02:32 -07:00
talshefandGitHub aaf0fd2ea8 Qodo intro notebook (#3968)
* update qodo notebook

* update qodo notebook

* update qodo notebook

* update qodo notebook

* update qodo notebook

* update qodo notebook

* update qodo notebook
2025-04-08 21:18:10 +00:00
Vertex MG TeamandCopybara-Service 8e249b61d9 Update Hugging Face vLLM deploy notebook title and documents.
PiperOrigin-RevId: 745208445
2025-04-08 10:48:41 -07:00
Vertex MG TeamandCopybara-Service 250418bab9 Set dedicate endpoint as default for some model garden samples
PiperOrigin-RevId: 745192594
2025-04-08 10:10:59 -07:00
Vertex MG TeamandCopybara-Service 70ec8b4ae2 Support VPC-SC. Add Model Garden deploy SDK
PiperOrigin-RevId: 745132382
2025-04-08 07:18:19 -07:00
Vertex MG TeamandCopybara-Service e48f3f05be Fix gemma3 finetuning.
PiperOrigin-RevId: 744956022
2025-04-07 20:45:44 -07:00
denisj3030andGitHub a60c0376c4 launchpad notebooks (#3964)
* launchpad notebooks

* Update ai21labs_intro.ipynb

* Update ai21labs_intro.ipynb

* launchpad

* audio play
2025-04-07 19:23:47 +00:00
denisj3030andGitHub 4bb5ffa1ec Update CODEOWNERS (#3970) 2025-04-07 18:53:44 +00:00
Vertex MG TeamandCopybara-Service 215491b24c Update polling time
PiperOrigin-RevId: 744731980
2025-04-07 08:32:12 -07:00
Vertex MG TeamandCopybara-Service e90c6925cb Update Llama 4 deployment notebook.
PiperOrigin-RevId: 744318800
2025-04-05 15:36:47 -07:00
Vertex MG TeamandCopybara-Service 8967e7301b Add Llama 4 deployment notebook
PiperOrigin-RevId: 744291525
2025-04-05 12:10:48 -07:00
Genquan DuanandCopybara-Service 0977d875ea Add forecasting with multi steps with animated visualization.
PiperOrigin-RevId: 744016523
2025-04-04 11:40:59 -07:00
Vertex MG TeamandCopybara-Service 2fec95e8c9 Support auto-scaling while deploying endpoints
PiperOrigin-RevId: 744004928
2025-04-04 11:06:36 -07:00
Vertex MG TeamandCopybara-Service 7665ae6d96 Support VPC-SC. Add Model Garden deploy SDK
PiperOrigin-RevId: 744004419
2025-04-04 11:04:41 -07:00
b58f02d5bf Add polling fn to common util (#3960)
Co-authored-by: Rayan Dasoriya <dasoriya@google.com>
2025-04-04 17:00:55 +00:00
Vertex MG TeamandCopybara-Service e09d6f40e5 reformatting of biomedclip
PiperOrigin-RevId: 743846093
2025-04-04 00:56:25 -07:00
Vertex MG TeamandCopybara-Service c45f6a4f4d Support VPC-SC and workbench
PiperOrigin-RevId: 743818321
2025-04-03 22:42:41 -07:00
Mend RenovateandGitHub ffaa5c114e chore(deps): update dependency flake8 to v7.2.0 (#3840) 2025-04-04 00:04:38 +00:00
Vertex MG TeamandCopybara-Service 62d8bbddba Workbench support
PiperOrigin-RevId: 743576188
2025-04-03 08:37:45 -07:00
Vertex MG TeamandCopybara-Service fe8ab55890 Add merge_model_precision_mode to the gemma2 finetuning.
PiperOrigin-RevId: 743487949
2025-04-03 03:19:17 -07:00
Vertex MG TeamandCopybara-Service 68e31b5407 Workbench support
PiperOrigin-RevId: 743436475
2025-04-03 00:08:55 -07:00
Vertex MG TeamandCopybara-Service 1640f568ea Fix lint issues
PiperOrigin-RevId: 743350440
2025-04-02 18:15:41 -07:00
Vertex MG TeamandCopybara-Service 15f058d9a2 chore: Remove deploy SDK due to timeout. Will add back when fixed.
PiperOrigin-RevId: 743199063
2025-04-02 10:49:11 -07:00
Vertex MG TeamandCopybara-Service e9c222737d chore: Remove faster_deploy_enabled in deploy SDK.
PiperOrigin-RevId: 743178007
2025-04-02 09:57:17 -07:00
Vertex MG TeamandCopybara-Service 4b48806393 Add workbench support
PiperOrigin-RevId: 743147221
2025-04-02 08:25:56 -07:00
Vertex MG TeamandCopybara-Service 2a2ab113c3 Mention the use of GCS path for autogluon train
PiperOrigin-RevId: 743128957
2025-04-02 07:30:38 -07:00
Vertex MG TeamandCopybara-Service db0f633415 Refactor the SD Inpainting notebook
PiperOrigin-RevId: 743108958
2025-04-02 06:22:17 -07:00
Vertex MG TeamandCopybara-Service b7f04de30d see design doc for more details: go/gke-model-ui-notebook-design
PiperOrigin-RevId: 742985852
2025-04-01 22:57:47 -07:00
Vertex MG TeamandCopybara-Service a89eadf7e8 chore: Update EULA comments.
PiperOrigin-RevId: 742890889
2025-04-01 16:58:26 -07:00
Changyu ZhuandCopybara-Service d10db455ea Enable speculative decoding draft model for DeepSeek-V3-0324 with SGLang
PiperOrigin-RevId: 742832025
2025-04-01 14:03:03 -07:00
Vertex MG TeamandCopybara-Service 1605c6884c Remove system_labels from OpenModel.deploy
PiperOrigin-RevId: 742760690
2025-04-01 10:49:29 -07:00
Vertex MG TeamandCopybara-Service b2661f9f69 Create Hugging Face vLLM deploy notebook
PiperOrigin-RevId: 742747326
2025-04-01 10:14:36 -07:00
Vertex MG TeamandCopybara-Service 8ad841b0f2 chore: Update SDK deploy timeout to 3 hours.
PiperOrigin-RevId: 742731078
2025-04-01 09:33:22 -07:00
Vertex MG TeamandCopybara-Service 3202f7602b Support VPC-SC. Add Model Garden deploy SDK
PiperOrigin-RevId: 742708341
2025-04-01 08:23:18 -07:00
Vertex MG TeamandCopybara-Service 6f8d986dc3 Add Model Garden deploy SDK
PiperOrigin-RevId: 742698763
2025-04-01 07:57:15 -07:00
Vertex MG TeamandCopybara-Service b5ce88df10 Add Model Garden deploy SDK
PiperOrigin-RevId: 742471878
2025-03-31 18:08:07 -07:00
Vertex MG TeamandCopybara-Service abdf3d73d6 Add Model Garden deploy SDK.
PiperOrigin-RevId: 742471204
2025-03-31 18:05:20 -07:00
Vertex MG TeamandCopybara-Service 0255d172f5 One template notebook for GKE Model UI
see design doc for more details: go/gke-model-ui-notebook-design

PiperOrigin-RevId: 742301507
2025-03-31 10:00:22 -07:00
Vertex MG TeamandCopybara-Service 8cebcbb984 Support VPC-SC. Add Model Garden deploy SDK
PiperOrigin-RevId: 742261473
2025-03-31 07:42:43 -07:00
Changyu ZhuandCopybara-Service 8eb680d0e9 Remove model_garden_source_model_name from Movinet VCN / VAR notebooks
PiperOrigin-RevId: 741586177
2025-03-28 11:14:10 -07:00
Genquan DuanandCopybara-Service 73c312e81a update weather next notebook of GenCast/GraphCast models
PiperOrigin-RevId: 741582377
2025-03-28 11:04:37 -07:00
Vertex MG TeamandCopybara-Service 0ba19214e1 Add Model Garden deploy SDK
PiperOrigin-RevId: 741371959
2025-03-27 20:13:50 -07:00
Vertex MG TeamandCopybara-Service 0568dc979a Add option for enable_llama_tool_parser
PiperOrigin-RevId: 741352395
2025-03-27 18:44:53 -07:00
Vertex MG TeamandCopybara-Service 0fda02c859 Add deploy source to the finetuning notebooks
PiperOrigin-RevId: 741207333
2025-03-27 10:46:00 -07:00
Vertex MG TeamandCopybara-Service 8411f656d0 Add Model Garden deploy SDK.
PiperOrigin-RevId: 741192166
2025-03-27 10:04:19 -07:00
Genquan DuanandCopybara-Service cc4a6675f9 update weather next notebook of GenCast/GraphCast models
PiperOrigin-RevId: 741186602
2025-03-27 09:47:24 -07:00
Vertex MG TeamandCopybara-Service 4e4bc7abe0 Fix minor lint issues
PiperOrigin-RevId: 740751344
2025-03-26 07:00:59 -07:00
Vertex MG TeamandCopybara-Service 95d06a3995 Update notebook with axolotl config suggestions.
PiperOrigin-RevId: 740418242
2025-03-25 11:18:36 -07:00
Vertex MG TeamandCopybara-Service 04b4d0ccd1 Add DeepSeek-V3-0324 for vLLM deployment in DeepSeek notebook.
PiperOrigin-RevId: 740405791
2025-03-25 10:47:12 -07:00
Vertex MG TeamandCopybara-Service f3c440359b chore: Update EULA comments.
PiperOrigin-RevId: 740400897
2025-03-25 10:34:02 -07:00
Changyu ZhuandCopybara-Service bacf337b4e Update #ModelGarden DeepSeek deployment notebook for SGLang 0.4.4.post1 and Deepseek-V3-0324 support
PiperOrigin-RevId: 740392018
2025-03-25 10:11:41 -07:00
Vertex MG TeamandCopybara-Service f5f5bc6a3c chore: Default accept EULA to True in notebooks.
PiperOrigin-RevId: 740116491
2025-03-24 16:43:16 -07:00
Vertex MG TeamandCopybara-Service da1a5fd6be Support VPC-SC.
PiperOrigin-RevId: 740043502
2025-03-24 13:06:13 -07:00
Vertex MG TeamandCopybara-Service fb6f778c6e Support VPC-SC.
PiperOrigin-RevId: 740042813
2025-03-24 13:03:56 -07:00
Dustin LuongandCopybara-Service c4b3f39bfe Remove raw_response field from request. Also fix chat completions format.
PiperOrigin-RevId: 740023921
2025-03-24 12:04:56 -07:00
Minwoo ParkandCopybara-Service 2b76b2618f Update llama3.3 finetuning notebook to use newer docker images.
PiperOrigin-RevId: 739987083
2025-03-24 10:23:03 -07:00
Vertex MG TeamandCopybara-Service c77125131c Support VPC-SC. Add Model Garden deploy SDK
PiperOrigin-RevId: 739555057
2025-03-22 17:07:10 -07:00
Vertex MG TeamandCopybara-Service a88aea1c2c Add system label notebook environment
PiperOrigin-RevId: 739481405
2025-03-22 07:54:19 -07:00
Vertex MG TeamandCopybara-Service 5066381dcc Fix paligemma2 notebook system label
PiperOrigin-RevId: 739380947
2025-03-21 20:38:50 -07:00
Changyu ZhuandCopybara-Service 5c54f6c5e9 Upgrade transformers version in ShieldGemma 2 local inference notebook
PiperOrigin-RevId: 739335379
2025-03-21 16:37:40 -07:00
Dustin LuongandCopybara-Service dc59488638 Add YaRN scaling to QwQ deployment notebook for 128k context length. Fix chatCompletions format.
PiperOrigin-RevId: 738871259
2025-03-20 11:09:46 -07:00
Vertex MG TeamandCopybara-Service 8ea6932dc2 Add local config support for axolotl.
PiperOrigin-RevId: 738854213
2025-03-20 10:27:22 -07:00
Vertex MG TeamandCopybara-Service 617d68a894 Update workbench link and region support for a3-highgpu-8g
PiperOrigin-RevId: 738724173
2025-03-20 02:34:17 -07:00
Vertex MG TeamandCopybara-Service 5845b12fba Fix SD XL notebook dataset
PiperOrigin-RevId: 738722681
2025-03-20 02:28:06 -07:00
Vertex MG TeamandCopybara-Service 1c87625014 Reformat the Pytorch Flux notebook
PiperOrigin-RevId: 738661642
2025-03-19 21:48:36 -07:00
Vertex MG TeamandCopybara-Service 2ba399778b Remove us east5 region for H100 MG deployment from notebooks.
PiperOrigin-RevId: 738464989
2025-03-19 11:02:11 -07:00
Changyu ZhuandCopybara-Service ddff8605c0 Add CSM-1B deployment notebook
PiperOrigin-RevId: 738459214
2025-03-19 10:46:59 -07:00
Vertex MG TeamandCopybara-Service 15ab7be0d8 fix deploy_source fn
PiperOrigin-RevId: 738438140
2025-03-19 09:55:52 -07:00
Vertex MG TeamandCopybara-Service 55f8adc328 Add Model Garden deploy SDK
PiperOrigin-RevId: 738434532
2025-03-19 09:45:53 -07:00
Vertex MG TeamandCopybara-Service 2ef0652cca Update DeepSeek notebook with new vLLM version, configs and H200 support.
PiperOrigin-RevId: 738408599
2025-03-19 08:29:00 -07:00
Dustin LuongandCopybara-Service 57f3cc3094 Add QwQ deployment notebook
PiperOrigin-RevId: 738183275
2025-03-18 16:29:26 -07:00
Vertex MG TeamandCopybara-Service 333ad532cb Add Model Garden deploy SDK
PiperOrigin-RevId: 738171512
2025-03-18 15:51:27 -07:00
Vertex MG TeamandCopybara-Service 1d55f3bf03 Fix minor lint issues
PiperOrigin-RevId: 738056173
2025-03-18 10:25:06 -07:00
Vertex MG TeamandCopybara-Service 5d3a71bd66 Add Model Garden deploy SDK
PiperOrigin-RevId: 737996111
2025-03-18 07:25:00 -07:00
Vertex MG TeamandCopybara-Service d7918ad939 Add Model Garden deploy SDK
PiperOrigin-RevId: 737989958
2025-03-18 07:02:36 -07:00
Vertex MG TeamandCopybara-Service cd468bc7a6 Add Model Garden deploy SDK.
PiperOrigin-RevId: 737988228
2025-03-18 06:56:17 -07:00
Vertex MG TeamandCopybara-Service 35f6daa68a Add support for L4 gpus with default quota and A100_40GB gpu with DWS.
PiperOrigin-RevId: 737865712
2025-03-17 22:10:21 -07:00
Vertex MG TeamandCopybara-Service a4d9e8c38e Support VPC-SC for the BiomedCLIP notebook.
PiperOrigin-RevId: 737819849
2025-03-17 18:22:59 -07:00
Vertex MG TeamandCopybara-Service 2e5c8082ab Add a reliable method for handling long-running (>10) prediction tasks using CURL (CLI) in Colab for enhanced stability.
PiperOrigin-RevId: 737809564
2025-03-17 17:36:10 -07:00
Vertex MG TeamandCopybara-Service f36b154181 Reduce the num_inference_steps from 30 to 25, which does not lose the generated video quality. There is a bug that the notebook does not support well if the total inference go beyond 10min.
PiperOrigin-RevId: 737808074
2025-03-17 17:28:58 -07:00
Vertex MG TeamandCopybara-Service 5f00f0713f Update deployment template to offload text encoder for 14B models.
PiperOrigin-RevId: 737777189
2025-03-17 15:40:35 -07:00
Vertex MG TeamandCopybara-Service f56007d36f Support Workbench in TGI and llama 3.3 serving notebooks
PiperOrigin-RevId: 737749714
2025-03-17 14:20:16 -07:00
Vertex MG TeamandCopybara-Service a165c2eece Create a colab notebook for nvidia cosmos model deployment on vertex.
PiperOrigin-RevId: 737740514
2025-03-17 13:54:55 -07:00
Vertex MG TeamandCopybara-Service 5b72950133 Add SpotVM and Reservations in-depth notebook with vLLM Llama-3.1 deployment tutorial notebook for model garden.
PiperOrigin-RevId: 737705120
2025-03-17 12:11:21 -07:00
8b2ffbad1e mistral small name update (#3886)
Co-authored-by: denisj3030 <denisj@google.com>
2025-03-17 16:31:18 +00:00
Genquan DuanandCopybara-Service b3b3d9294b demo notebook of GenCast/GraphCast models
PiperOrigin-RevId: 737641814
2025-03-17 09:26:01 -07:00
ec08071608 Mistral Small addition (#3885)
Co-authored-by: denisj3030 <denisj@google.com>
2025-03-17 16:18:50 +00:00
Vertex MG TeamandCopybara-Service 01e8b7e242 Fix pretrained model IDs in Gemma 3 deployment notebook.
PiperOrigin-RevId: 736740585
2025-03-13 21:37:49 -07:00
Changyu ZhuandCopybara-Service 1fdb83b791 Add (streaming) chat completion with SGLang to the DeepSeek deployment notebook
PiperOrigin-RevId: 736555836
2025-03-13 10:30:59 -07:00
Vertex MG TeamandCopybara-Service e1794a48a6 Support VPC-SC.
PiperOrigin-RevId: 736496220
2025-03-13 07:23:50 -07:00
Vertex MG TeamandCopybara-Service b5e105ae01 Update owlvit notebook to support Vertex Workbench.
PiperOrigin-RevId: 736335449
2025-03-12 18:35:05 -07:00
Vertex MG TeamandCopybara-Service ed1cd7e6bd Fixed gemma3 model name.
PiperOrigin-RevId: 736145845
2025-03-12 08:42:53 -07:00
Changyu ZhuandCopybara-Service e128823a12 Add ShieldGemma 2 local inference notebook
PiperOrigin-RevId: 736034669
2025-03-12 00:56:08 -07:00
Vertex MG TeamandCopybara-Service c7cbbf369a Fix context length in Gemma 3 deployment notebook.
PiperOrigin-RevId: 736033252
2025-03-12 00:49:02 -07:00
Vertex MG TeamandCopybara-Service 787c34d11f Add Gemma 3 finetuning notebook.
PiperOrigin-RevId: 736020252
2025-03-11 23:44:56 -07:00
Vertex MG TeamandCopybara-Service 841cfc3d09 Add Gemma 3 deployment notebook.
PiperOrigin-RevId: 736017148
2025-03-11 23:29:15 -07:00
040fc424fe Update common util (#3868)
Co-authored-by: Rayan Dasoriya <dasoriya@google.com>
2025-03-11 12:33:53 +00:00
Vertex MG TeamandCopybara-Service 69fab881a9 Ollama notebook for deepseek-r1-671b and deepseek-r1-1.5b
PiperOrigin-RevId: 735613073
2025-03-10 21:09:10 -07:00
Mend RenovateandGitHub f2ab60464a chore(deps): update dependency isort to v6.0.1 (#3854) 2025-03-08 01:51:13 +00:00
Franklin WhaiteandGitHub b5f634dd19 Update pandas version on xgboost_training component in kfp2_pipeline.ipynb (#3866)
The current version was causing a the below error when executing on xgboost_training component on vertex.

```
numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
```

Updating the pandas version as shown [here](https://github.com/numpy/numpy/issues/26710) resolved the issue
2025-03-08 01:49:52 +00:00
Vertex MG TeamandCopybara-Service 582a4542ae Colab notebook for CogVideoX-2b
PiperOrigin-RevId: 734587293
2025-03-07 09:35:56 -08:00
Vertex MG TeamandCopybara-Service 5e069e28eb Flux.1 Schnell config change
PiperOrigin-RevId: 734587136
2025-03-07 09:34:28 -08:00
22d27fafe7 chore: prediction psc private endpoint, add service attachment best practises (#3863)
Co-authored-by: TJ(Tianjiao) Liu <tianjiaoliu@google.com>
2025-03-07 14:20:42 +00:00
Changyu ZhuandCopybara-Service 4078d9449a Enable non-spot VM deployment in DeepSeek deploy notebooks
PiperOrigin-RevId: 734322869
2025-03-06 16:04:45 -08:00
Shawn YangandCopybara-Service 6703ad5d89 chore: Update AgentEngine notebooks.
PiperOrigin-RevId: 734200652
2025-03-06 10:37:06 -08:00
b2d0a04114 Update source code for stable_20250213 peft docker image (#3864)
Co-authored-by: Rayan Dasoriya <dasoriya@google.com>
2025-03-06 13:56:56 +00:00
Vertex MG TeamandCopybara-Service 4f866ccc89 Fix minor lint issues
PiperOrigin-RevId: 734055195
2025-03-06 02:25:35 -08:00
Vertex MG TeamandCopybara-Service 2bcd07214a updated with latest docker image.
PiperOrigin-RevId: 734037362
2025-03-06 01:22:32 -08:00
Changyu ZhuandCopybara-Service 429513816d Add SGLang section to deepseek deployment templated notebook
PiperOrigin-RevId: 733553038
2025-03-04 19:52:21 -08:00
Vertex MG TeamandCopybara-Service 4c96a1462e Update train image tag for tutorial notebook
PiperOrigin-RevId: 733546380
2025-03-04 19:15:53 -08:00
Vertex MG TeamandCopybara-Service 10ea4f8a4c Update DeepSeek notebook to support vLLM v0.7.2, and improve instructions and code samples.
PiperOrigin-RevId: 733511350
2025-03-04 16:46:17 -08:00
Vertex MG TeamandCopybara-Service 6dcd8cad37 Add Model Garden finetuning notebook for Llama3 using workbench.
PiperOrigin-RevId: 731363986
2025-02-26 10:14:32 -08:00
Vertex MG TeamandCopybara-Service 56b06420df Update server args in DeepSeek deployment notebook.
PiperOrigin-RevId: 730964887
2025-02-25 11:31:28 -08:00
2ee16893c4 update for satin (#3850)
Co-authored-by: denisj3030 <denisj@google.com>
2025-02-24 18:48:56 +00:00
Vertex MG TeamandCopybara-Service 0cf6d0235e Add vllm llama3.2 multimodal deep dive deployment tutorial notebook for model garden.
PiperOrigin-RevId: 729574413
2025-02-21 10:23:23 -08:00
Vertex MG TeamandCopybara-Service 495dd6a9a7 Add vllm llama3.1 text-only deep dive deployment tutorial notebook for model garden
devsite.

PiperOrigin-RevId: 729520321
2025-02-21 07:18:44 -08:00
Vertex MG TeamandCopybara-Service 0c7b9b96f1 Update DeepSeek notebook to use Spot VMs.
PiperOrigin-RevId: 729332283
2025-02-20 18:51:20 -08:00
Vertex MG TeamandCopybara-Service c8048bf7b9 Support VPC-SC.
PiperOrigin-RevId: 729238423
2025-02-20 13:49:34 -08:00
Vertex MG TeamandCopybara-Service cfd51e6c2b Add Model Garden finetuning notebook for Axolotl.
PiperOrigin-RevId: 729181397
2025-02-20 11:15:37 -08:00
Vertex MG TeamandCopybara-Service 7df853e17e Support VPC-SC.
PiperOrigin-RevId: 729181240
2025-02-20 11:14:09 -08:00
Vertex MG TeamandCopybara-Service b653153e2e Fix typo in PaliGemma2 notebook.
PiperOrigin-RevId: 729121693
2025-02-20 08:27:11 -08:00
Minwoo ParkandCopybara-Service 06d023f120 Update Vertex Model Garden Llama 3.1 and Gemma 2 finetuning notebooks with new training docker image.
PiperOrigin-RevId: 728801185
2025-02-19 14:29:14 -08:00
Vertex MG TeamandCopybara-Service d1f54aa2c8 Update PaliGemma 2 notebook.
PiperOrigin-RevId: 728699666
2025-02-19 09:16:44 -08:00
Minwoo ParkandCopybara-Service b0046bae76 Add Model Garden finetuning tutorial notebook.
PiperOrigin-RevId: 728675586
2025-02-19 08:03:38 -08:00
069d709edd update mistral sdk (#3836)
Co-authored-by: denisj3030 <denisj@google.com>
2025-02-13 19:19:47 +00:00
Vertex MG TeamandCopybara-Service a33a103c05 Fix service account setting with DeepSeek deployment notebook.
PiperOrigin-RevId: 726118186
2025-02-12 10:57:01 -08:00
Vertex MG TeamandCopybara-Service 44c29899e7 Add DeepSeek-V3/R1 multi-host deployment notebook.
PiperOrigin-RevId: 725810376
2025-02-11 16:14:48 -08:00
700 changed files with 58931 additions and 14099 deletions
@@ -238,7 +238,7 @@ def _get_notebook_python_version(notebook_path: str) -> str:
# Look for the python version specification pattern
re_match = re.search(
"python version = (\d+\.\d+)", markdown, flags=re.IGNORECASE
r"python version = (\d+\.\d+)", markdown, flags=re.IGNORECASE
)
if re_match:
# get the version number
-2
View File
@@ -1,5 +1,3 @@
notebooks/official/vizier/gapic-vizier-multi-objective-optimization.ipynb
notebooks/official/pipelines/lightweight_functions_component_io_kfp.ipynb
notebooks/official/ml_metadata/sdk-metric-parameter-tracking-for-locally-trained-models.ipynb
notebooks/official/custom/custom-tabular-bq-managed-dataset.ipynb
.cloud-build/tests/python_version_test.ipynb
+3 -3
View File
@@ -3,8 +3,8 @@ ipython
jupyter
nbconvert
black==25.1.0
pyupgrade==3.19.1
isort==6.0.0
flake8==7.1.1
pyupgrade==3.20.0
isort==6.0.1
flake8==7.3.0
nbqa==1.9.1
+1
View File
@@ -29,4 +29,5 @@
/vertex_model_garden/model_oss/vllm @kathyyu-google
/vertex_model_garden/benchmarking_reports @lavraicse
/vertex_model_garden/model_oss/autogluon @lavraicse
/vertex_distributed_training/a3mega/llama-3-8b-nemo-pretraining @mstyer-google @erwinh85 @mchrestkha
@@ -1,3 +1,3 @@
torch==2.2.0
torch==2.7.0
torchvision==0.9.1
tensorboard==2.5.0
@@ -0,0 +1,126 @@
# Vertex AI Training: Llama 3.1 8B pre-training using Nvidia A3 Mega VMs (H100)
This document provides a step-by-step guide for pre-training a Llama 3.1 8B model on the `en-wiki` dataset using multiple [Vertex AI Custom Training](https://cloud.google.com/vertex-ai/docs/training/overview) `a3-megagpu-8g` nodes.
We will use a custom container based on NVIDIA's [NeMo Framework](https://docs.nvidia.com/nemo-framework/user-guide/24.07/overview.html) to demonstrate a scalable, multi-node training workflow. All required artifacts and commands are included.
## 1. Prerequisites
### 1.1. Google Cloud Project setup
- **Enable APIs:** Ensure the Vertex AI API is [enabled for your project](http://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com).
- **H100 Mega Quota:** A3 Mega VMs are powered by H100 GPUs. Request quota for `custom_model_training_nvidia_h100_mega_gpus` in one of the [supported regions](https://cloud.google.com/vertex-ai/docs/general/locations#accelerator_support). If using Spot VMs, request `custom_model_training_preemptible_nvidia_h100_mega_gpus` quota instead.
- **Reservations (Optional but recommended):** For guaranteed capacity, [create a reservation](https://cloud.google.com/compute/docs/instances/reservations-shared) and ensure the reservation is shared with the Vertex AI service account. This guide requires a minimum of **16 H100 GPUs** (2 full A3 Mega nodes).
### 1.2. GCS bucket
Create a [Cloud Storage bucket](https://cloud.google.com/storage/docs/creating-buckets) in the same region where you have quota. If you're using Hierarchical Namespace for your bucket, you may need to update permissions of the Vertex AI Custom Code Service Agent .
This bucket is used for:
- Staging the training application.
- Storing model checkpoints and logs.
- Storing data if you use your own data.
## 2. Setup & configuration
### 2.1. Clone the repo
First clone the repo into your development environment.
```bash
git clone https://github.com/GoogleCloudPlatform/vertex-ai-samples.git
```
Navigate to the root folder for this sample.
### 2.2. Environment Setup
First, configure your local environment. These variables are used in subsequent commands.
```bash
# Required: Update with your values
export PROJECT_ID="<your-project-id>"
export REPOSITORY="<your-artifact-registry-repo-name>" # e.g., "my-containers"
export BUCKET="<your-gcs-bucket-name>"
# Optional: Change if needed
export REGION="us-central1"
# --- Do not change the lines below ---
export ARTIFACT_REGISTRY="${REGION}-docker.pkg.dev/${PROJECT_ID}/${REPOSITORY}"
export REPO_ROOT=$(git rev-parse --show-toplevel)
```
## 3. Build and push a docker container image to Artifact Registry
Normally, you can use any custom training container on Vertex AI Training. In this example you build a NeMo Docker image that is based on the [Nvidia’s NeMo 24.09](https://catalog.ngc.nvidia.com/orgs/nvidia/containers/nemo/tags) image. Use Cloud Build to build and push the container image.
This document picked NeMo as the demonstrating container since it’s a widely adopted GPU LLM training framework providing high performance and versatile training functionalities.
In addition to the base image, some customizations are included to form the final prebuilt image:
- Some dependencies are installed to integrate with Vertex AI Training.
- An entrypoint script that sets up required environments and calls the training job.
- Some patches are applied to the NeMo code to let it load the dataset from a GCS bucket.
Run this command to build the container and push the container into the Google Artifact Registry.
```bash
cd "${REPO_ROOT}/community-content/vertex-distributed-training/a3mega/llama-3-8b-nemo-pretraining"
export IMAGE_NAME="vertex-nemo-llama"
gcloud builds submit . \
--project="${PROJECT_ID}" \
--region="${REGION}" \
--config=docker/cloudbuild.yml \
--substitutions="_ARTIFACT_REGISTRY=${ARTIFACT_REGISTRY},_IMAGE_NAME=${IMAGE_NAME}" \
--timeout="2h" \
--machine-type="e2-highcpu-32"
```
## 4. Launch the Training Job
### 4.1. Job Configuration File
Once the container is built, update the job_config.json to set up the training job.
File: job_config.json
```json
{
"project_id": "<project-id>",
"region": "<region>",
"zone": "<zone if using reservation>",
"bucket": "<bucket>",
"dataset_bucket": "github-repo/data/third-party/enwiki-latest-pages-articles",
"image_uri": "<docker image uri from artifact registry>",
"strategy": "spot",
"nodes": "2",
"machine_type": "a3-megagpu-8g",
"gpu_type": "NVIDIA_H100_MEGA_80GB",
"gpus_per_node": "8",
"recipe_name": "llama3_1_8b_pretrain_a3mega",
"job_prefix": "vertex-spot-",
"reservation_name": ""
}
```
### 4.2 Launch the Training Job
First, create a Python virtual environment using your tool of choice, then install
the requirements specified in `requirements.txt`. Using `pip`, the command would be:
```bash
pip install -r requirements.txt
```
Now launch the Vertex AI training job using the provided Python script.
```bash
python3 scripts/launch.py --config_file=job_config.json
```
This script reads job_config.json, defines the cluster specification (2 nodes, 8 GPUs each), and submits the custom training job to Vertex AI.
## 5. Monitor and Clean Up
### 5.1. Monitoring
Vertex AI Console: Track the job's status in the Google Cloud Console under Vertex AI > Training > Custom Jobs.
Logs: View detailed logs in Cloud Logging by filtering for your job name.
Checkpoints: Model checkpoints are saved to your GCS bucket at the path specified in your training script's configuration.
### 5.2. Cleaning Up
To avoid ongoing charges, delete the resources you created:
- The Artifact Registry image.
- The contents of the GCS bucket (checkpoints, logs).
- The Vertex AI Custom Job will eventually complete or fail, incurring no further cost.
@@ -0,0 +1,265 @@
# Reference:
# https://github.com/NVIDIA/NeMo-Framework-Launcher/blob/24.07/launcher_scripts/conf/training/llama/llama3_1_8b.yaml
name: llama3_1_8b_pretrain_a3mega
restore_from_path: null # used when starting from a .nemo file
trainer:
devices: 8
num_nodes: 1
accelerator: gpu
precision: bf16
logger: false # logger provided by exp_manager
enable_checkpointing: false
use_distributed_sampler: false
max_epochs: -1 # PTL default. In practice, max_steps will be reached first.
max_steps: 30 # consumed_samples = global_step * micro_batch_size * data_parallel_size * accumulate_grad_batches
log_every_n_steps: 1
val_check_interval: null
limit_val_batches: 1
limit_test_batches: 1
accumulate_grad_batches: 1 # do not modify, grad acc is automatic for training megatron models
gradient_clip_val: 1.0
benchmark: false
enable_model_summary: false # default PTL callback for this does not support model parallelism, instead we log manually
exp_manager:
explicit_log_dir: null
exp_dir: /data
name: ${name}
create_dllogger_logger: true
dllogger_logger_kwargs:
verbose: true
stdout: true
json_file: "/data/dllogger.json"
create_wandb_logger: false
wandb_logger_kwargs:
project: null
name: null
resume_if_exists: true
resume_ignore_no_checkpoint: true
create_checkpoint_callback: false
checkpoint_callback_params:
monitor: val_loss
save_top_k: 3
mode: min
always_save_nemo: false # saves nemo file during validation, not implemented for model parallel
save_nemo_on_train_end: false # not recommended when training large models on clusters with short time limits
filename: 'megatron_gpt--{val_loss:.2f}-{step}-{consumed_samples}'
model_parallel_size: ${multiply:${model.tensor_model_parallel_size}, ${model.pipeline_model_parallel_size}}
seconds_to_sleep: 5 # Allows node_rank!=0 to sleep and let node0 to init, like preparing data
model:
mcore_gpt: true
# specify micro_batch_size, global_batch_size, and model parallelism
# gradient accumulation will be done automatically based on data_parallel_size
micro_batch_size: 1 # limited by GPU memory
global_batch_size: 1024 # will use more micro batches to reach global batch size
tensor_model_parallel_size: 1 # intra-layer model parallelism
pipeline_model_parallel_size: 2 # inter-layer model parallelism
context_parallel_size: 1
virtual_pipeline_model_parallel_size: null # interleaved pipeline
## Sequence Parallelism
# Makes tensor parallelism more memory efficient for LLMs (20B+) by parallelizing layer norms and dropout sequentially
# See Reducing Activation Recomputation in Large Transformer Models: https://arxiv.org/abs/2205.05198 for more details.
sequence_parallel: false
fsdp: false
fsdp_cpu_offload: true
fsdp_sharding_strategy: "full" # Method to shard model states. Available options are 'full', 'hybrid', and 'grad'.
fsdp_grad_reduce_dtype: "16" # Gradient reduction data type.
fsdp_sharded_checkpoint: false # Store and load FSDP shared checkpoint.
fsdp_use_orig_params: false # Set to True to use FSDP for specific peft scheme.
# Distributed checkpoint setup
dist_ckpt_format: "torch_dist" # Set to 'torch_dist' to use PyTorch distributed checkpoint format.
dist_ckpt_load_on_device: true # whether to load checkpoint weights directly on GPU or to CPU
dist_ckpt_parallel_save: true # if true, each worker will write its own part of the dist checkpoint
dist_ckpt_parallel_save_within_dp: false # if true, save will be parallelized only within a DP group (whole world otherwise), which might slightly reduce the save overhead
dist_ckpt_parallel_load: false # if true, each worker will load part of the dist checkpoint and exchange with NCCL. Might use some extra GPU memory
dist_ckpt_torch_dist_multiproc: 2 # number of extra processes per rank used during ckpt save with PyTorch distributed format
dist_ckpt_assume_constant_structure: false # set to True only if the state dict structure doesn't change within a single job. Allows caching some computation across checkpoint saves.
dist_ckpt_parallel_dist_opt: true # parallel save/load of a DistributedOptimizer. 'True' allows performant save and reshardable checkpoints. Set to 'False' only in order to minimize the number of checkpoint files.
dist_ckpt_load_strictness: null # defines checkpoint keys mismatch behavior (only during dist-ckpt load). Choices: assume_ok_unexpected (default - try loading without any check), log_all (log mismatches), raise_all (raise mismatches)
# model architecture
encoder_seq_length: 8192
max_position_embeddings: ${.encoder_seq_length}
num_layers: 32 # 8b: 32 | 70b: 80 | 405b: 126
hidden_size: 4096 # 8b: 4096 | 70b: 8192 | 405b: 16384
ffn_hidden_size: 14336 # 8b: 14336 | 70b: 28672 | 405b: 53248
num_attention_heads: 32 # 8b: 32 | 70b: 64 | 405b: 128
num_query_groups: 8 # Number of query groups for group query attention. If None, normal attention is used. 8b: 8 | 70b: 8 | 405b: 16
init_method_std: 0.01 # Standard deviation of the zero mean normal distribution used for weight initialization. 8b: 0.01 | 70b: 0.008944 | 405b: 0.02
use_scaled_init_method: true # use scaled residuals initialization
hidden_dropout: 0.0 # Dropout probability for hidden state transformer.
attention_dropout: 0.0 # Dropout probability for attention
ffn_dropout: 0.0 # Dropout probability in the feed-forward layer.
kv_channels: null # Projection weights dimension in multi-head attention. Set to hidden_size // num_attention_heads if null
apply_query_key_layer_scaling: true # scale Q * K^T by 1 / layer-number.
normalization: 'rmsnorm' # Normalization layer to use. Options are 'layernorm', 'rmsnorm'
layernorm_epsilon: 1e-5
do_layer_norm_weight_decay: false # True means weight decay on all params
make_vocab_size_divisible_by: 128 # Pad the vocab size to be divisible by this value for computation efficiency.
pre_process: true # add embedding
post_process: true # add pooler
persist_layer_norm: true # Use of persistent fused layer norm kernel.
bias: false # Whether to use bias terms in all weight matrices.
activation: 'fast-swiglu' # Options ['gelu', 'geglu', 'swiglu', 'reglu', 'squared-relu', 'fast-geglu', 'fast-swiglu', 'fast-reglu']
headscale: false # Whether to learn extra parameters that scale the output of the each self-attention head.
transformer_block_type: 'pre_ln' # Options ['pre_ln', 'post_ln', 'normformer']
openai_gelu: false # Use OpenAI's GELU instead of the default GeLU
normalize_attention_scores: true # Whether to scale the output Q * K^T by 1 / sqrt(hidden_size_per_head). This arg is provided as a configuration option mostly for compatibility with models that have been weight-converted from HF. You almost always want to se this to True.
position_embedding_type: 'rope' # Position embedding type. Options ['learned_absolute', 'rope']
rotary_percentage: 1.0 # If using position_embedding_type=rope, then the per head dim is multiplied by this.
attention_type: 'multihead' # Attention type. Options ['multihead']
share_embeddings_and_output_weights: false # Share embedding and output layer weights.
scale_positional_embedding: true # This is false for llama3 models. Only used for >= llama3.1.
# Use GPT2BPETokenizer for test, because the testing dataset is tokenized by this tokenizer.
# https://docs.nvidia.com/nemo-framework/user-guide/24.07/playbooks/singlenodepretrain.html#data-download-and-pre-processing
tokenizer:
library: megatron
type: GPT2BPETokenizer
model: null # /path/to/tokenizer.model
vocab_file: null
merge_file: null
delimiter: null # only used for tabular tokenizer
sentencepiece_legacy: false # Legacy=True allows you to add special tokens to sentencepiece tokenizers.
# Mixed precision
native_amp_init_scale: 4294967296 # 2 ** 32
native_amp_growth_interval: 1000
hysteresis: 2 # Gradient scale hysteresis
fp32_residual_connection: false # Move residual connections to fp32
fp16_lm_cross_entropy: false # Move the cross entropy unreduced loss calculation for lm head to fp16
# Megatron O2-style half-precision
megatron_amp_O2: true # Enable O2-level automatic mixed precision using main parameters
grad_allreduce_chunk_size_mb: 125
# Fusion
grad_div_ar_fusion: true # Fuse grad division into torch.distributed.all_reduce. Only used with O2 and no pipeline parallelism..
gradient_accumulation_fusion: true # Fuse weight gradient accumulation to GEMMs. Only used with pipeline parallelism and O2.
bias_activation_fusion: true # Use a kernel that fuses the bias addition from weight matrices with the subsequent activation function.
bias_dropout_add_fusion: true # Use a kernel that fuses the bias addition, dropout and residual connection addition.
masked_softmax_fusion: true # Use a kernel that fuses the attention softmax with it's mask.
apply_rope_fusion: true # Use a kernel to add rotary positional embeddings. Only used if position_embedding_type=rope
cross_entropy_loss_fusion: true
# Miscellaneous
seed: 1234
resume_from_checkpoint: null # manually set the checkpoint file to load from
use_cpu_initialization: false # Init weights on the CPU (slow for large models)
onnx_safe: false # Use work-arounds for known problems with Torch ONNX exporter.
apex_transformer_log_level: 30 # Python logging level displays logs with severity greater than or equal to this
gradient_as_bucket_view: true # PyTorch DDP argument. Allocate gradients in a contiguous bucket to save memory (less fragmentation and buffer memory)
sync_batch_comm: false # Enable stream synchronization after each p2p communication between pipeline stages
## Activation Checkpointing
# NeMo Megatron supports 'selective' activation checkpointing where only the memory intensive part of attention is checkpointed.
# These memory intensive activations are also less compute intensive which makes activation checkpointing more efficient for LLMs (20B+).
# See Reducing Activation Recomputation in Large Transformer Models: https://arxiv.org/abs/2205.05198 for more details.
# 'full' will checkpoint the entire transformer layer.
activations_checkpoint_granularity: null # 'selective' or 'full'
activations_checkpoint_method: null # 'uniform', 'block'
# 'uniform' divides the total number of transformer layers and checkpoints the input activation
# of each chunk at the specified granularity. When used with 'selective', 'uniform' checkpoints all attention blocks in the model.
# 'block' checkpoints the specified number of layers per pipeline stage at the specified granularity
activations_checkpoint_num_layers: null
# when using 'uniform' this creates groups of transformer layers to checkpoint. Usually set to 1. Increase to save more memory.
# when using 'block' this this will checkpoint the first activations_checkpoint_num_layers per pipeline stage.
num_micro_batches_with_partial_activation_checkpoints: null
# This feature is valid only when used with pipeline-model-parallelism.
# When an integer value is provided, it sets the number of micro-batches where only a partial number of Transformer layers get checkpointed
# and recomputed within a window of micro-batches. The rest of micro-batches in the window checkpoint all Transformer layers. The size of window is
# set by the maximum outstanding micro-batch backpropagations, which varies at different pipeline stages. The number of partial layers to checkpoint
# per micro-batch is set by 'activations_checkpoint_num_layers' with 'activations_checkpoint_method' of 'block'.
# This feature enables using activation checkpoint at a fraction of micro-batches up to the point of full GPU memory usage.
activations_checkpoint_layers_per_pipeline: null
# This feature is valid only when used with pipeline-model-parallelism.
# When an integer value (rounded down when float is given) is provided, it sets the number of Transformer layers to skip checkpointing at later
# pipeline stages. For example, 'activations_checkpoint_layers_per_pipeline' of 3 makes pipeline stage 1 to checkpoint 3 layers less than
# stage 0 and stage 2 to checkpoint 6 layers less stage 0, and so on. This is possible because later pipeline stage
# uses less GPU memory with fewer outstanding micro-batch backpropagations. Used with 'num_micro_batches_with_partial_activation_checkpoints',
# this feature removes most of activation checkpoints at the last pipeline stage, which is the critical execution path.
## Transformer Engine
transformer_engine: true
fp8: false # enables fp8 in TransformerLayer forward
fp8_e4m3: false # sets fp8_format = recipe.Format.E4M3
fp8_hybrid: false # sets fp8_format = recipe.Format.HYBRID
fp8_margin: 0 # scaling margin
fp8_interval: 1 # scaling update interval
fp8_amax_history_len: 1024 # Number of steps for which amax history is recorded per tensor
fp8_amax_compute_algo: 'max' # 'most_recent' or 'max'. Algorithm for computing amax from history
ub_tp_comm_overlap: false # do not turn on because of b/397797926
use_flash_attention: true
gc_interval: 100
## Offloading Activations/Weights to CPU
cpu_offloading: false
cpu_offloading_num_layers: ${sum:${.num_layers},-1} # This value should be between [1,num_layers-1] as we don't want to offload the final layer's activations and expose any offloading duration for the final layer
cpu_offloading_activations: true
cpu_offloading_weights: true
data:
# Path to data must be specified by the user.
# Supports List, String and Dictionary
# List : can override from the CLI: "model.data.data_prefix=[.5,/raid/data/pile/my-gpt3_00_text_document,.5,/raid/data/pile/my-gpt3_01_text_document]",
# Or see example below:
# data_prefix:
# - .5
# - /raid/data/pile/my-gpt3_00_text_document
# - .5
# - /raid/data/pile/my-gpt3_01_text_document
# Dictionary: can override from CLI "model.data.data_prefix"={"train":[1.0, /path/to/data], "validation":/path/to/data, "test":/path/to/test}
# Or see example below:
# "model.data.data_prefix: {train:[1.0,/path/to/data], validation:[/path/to/data], test:[/path/to/test]}"
data_prefix: [1.0, /data/hfbpe_gpt_training_data_text_document]
index_mapping_dir: null # path to save index mapping .npy files, by default will save in the same location as data_prefix
data_impl: mmap
splits_string: 900,50,50
seq_length: ${model.encoder_seq_length}
skip_warmup: true
num_workers: 2
dataloader_type: single # cyclic
reset_position_ids: false # Reset position ids after end-of-document token
reset_attention_mask: false # Reset attention mask after end-of-document token
eod_mask_loss: false # Mask loss for the end of document tokens
validation_drop_last: true # Set to false if the last partial validation samples is to be consumed
no_seqlen_plus_one_input_tokens: false # Set to True to disable fetching (sequence length + 1) input tokens, instead get (sequence length) input tokens and mask the last token
pad_samples_to_global_batch_size: false # Set to True if you want to pad the last partial batch with -1's to equal global batch size
shuffle_documents: true # Set to False to disable documents shuffling. Sample index will still be shuffled
# Nsys profiling options
nsys_profile:
enabled: false
start_step: 0 # Global batch to start profiling
end_step: 1 # Global batch to end profiling
ranks: [0] # Global rank IDs to profile
gen_shape: false # Generate model and kernel details including input shapes
memory_profile:
enabled: false
start_step: 0
end_step: 1
ranks: [0]
output_path: /data # Must be a dir
optim:
name: distributed_fused_adam # E.g., fused_adam or set _target_: torch.optim.AdamW field
lr: 2e-5
weight_decay: 0.01
betas:
- 0.9
- 0.98
bucket_cap_mb: 125
overlap_grad_sync: true
overlap_param_sync: true
contiguous_grad_buffer: true
contiguous_param_buffer: true
sched:
name: CosineAnnealing
warmup_steps: 400
constant_steps: 0
min_lr: 2e-6
@@ -0,0 +1,26 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
steps:
- name: 'gcr.io/cloud-builders/docker'
args:
- 'build'
- '--tag=${_ARTIFACT_REGISTRY}/${_IMAGE_NAME}'
- '--file=docker/vertex-dist-recipes.Dockerfile'
- '.'
automapSubstitutions: true
env:
- 'DOCKER_BUILDKIT=1'
images:
- '${_ARTIFACT_REGISTRY}/${_IMAGE_NAME}'
@@ -0,0 +1,41 @@
diff --git a/nemo/collections/nlp/parts/megatron_trainer_builder.py b/nemo/collections/nlp/parts/megatron_trainer_builder.py
index b2c85cde4..a3a9670c3 100644
--- a/nemo/collections/nlp/parts/megatron_trainer_builder.py
+++ b/nemo/collections/nlp/parts/megatron_trainer_builder.py
@@ -19,6 +19,7 @@ from lightning_fabric.utilities.exceptions import MisconfigurationException
from omegaconf import DictConfig
from pytorch_lightning import Trainer
from pytorch_lightning.callbacks import ModelSummary
+from pytorch_lightning.callbacks import Callback
from pytorch_lightning.plugins.environments import TorchElasticEnvironment
from nemo.collections.common.metrics.perf_metrics import FLOPsMeasurementCallback
@@ -38,6 +39,23 @@ from nemo.utils.callbacks.dist_ckpt_io import (
AsyncFinalizerCallback,
DistributedCheckpointIO,
)
+from vmg.util.device_stats import gpu_stats_str
+
+class GpuStatsMon(Callback):
+ def on_train_start(self, trainer, pl_module) -> None:
+ rank=pl_module.global_rank
+ print(f'train_start: {rank=} {gpu_stats_str()}', flush=True)
+
+ def on_train_batch_start(self, trainer, pl_module, batch, batch_idx) -> None:
+ rank=pl_module.global_rank
+ print(f'batch_start: {rank=} {gpu_stats_str()}', flush=True)
+
+ def on_train_batch_end(self, trainer, pl_module, outputs, batch, batch_idx) -> None:
+ rank=pl_module.global_rank
+ print(f'batch_end: {rank=} {gpu_stats_str()}', flush=True)
class MegatronTrainerBuilder:
@@ -178,6 +196,7 @@ class MegatronTrainerBuilder:
if self.cfg.get('exp_manager', {}).get('log_tflops_per_sec_per_gpu', True):
callbacks.append(FLOPsMeasurementCallback(self.cfg))
+ callbacks.append(GpuStatsMon())
return callbacks
def create_trainer(self, callbacks=None) -> Trainer:
@@ -0,0 +1,41 @@
diff -ruN old-datasets/blended_megatron_dataset_builder.py datasets/blended_megatron_dataset_builder.py
--- old-datasets/blended_megatron_dataset_builder.py 2025-05-02 04:08:45.369199665 +0000
+++ datasets/blended_megatron_dataset_builder.py 2025-05-02 04:10:47.369119891 +0000
@@ -2,6 +2,7 @@
import logging
import math
+import os
from concurrent.futures import ThreadPoolExecutor
from typing import Any, Callable, Iterable, List, Optional, Type, Union
@@ -353,7 +354,7 @@
num_dataset_builder_threads = self.config.num_dataset_builder_threads
if torch.distributed.is_initialized():
- rank = torch.distributed.get_rank()
+ rank = int(os.getenv("LOCAL_RANK", "0"))
# First, build on rank 0
if rank == 0:
num_workers = num_dataset_builder_threads
@@ -475,7 +476,7 @@
Optional[Union[DistributedDataset, Iterable]]: The DistributedDataset instantion, the Iterable instantiation, or None
"""
if torch.distributed.is_initialized():
- rank = torch.distributed.get_rank()
+ rank = int(os.getenv("LOCAL_RANK", "0"))
dataset = None
diff -ruN old-datasets/gpt_dataset.py datasets/gpt_dataset.py
--- old-datasets/gpt_dataset.py 2025-05-02 04:08:45.369199665 +0000
+++ datasets/gpt_dataset.py 2025-05-02 04:09:30.309170278 +0000
@@ -351,7 +351,7 @@
if not path_to_cache or (
not cache_hit
- and (not torch.distributed.is_initialized() or torch.distributed.get_rank() == 0)
+ and (not torch.distributed.is_initialized() or int(os.getenv("LOCAL_RANK", "0")) == 0)
):
log_single_rank(
@@ -0,0 +1,13 @@
diff --git a/scripts/checkpoint_converters/convert_llama_nemo_to_hf.py b/scripts/checkpoint_converters/convert_llama_nemo_to_hf.py
index 8da15148d..005cae6c9 100644
--- a/scripts/checkpoint_converters/convert_llama_nemo_to_hf.py
+++ b/scripts/checkpoint_converters/convert_llama_nemo_to_hf.py
@@ -104,6 +104,8 @@ def convert(input_nemo_file, output_hf_file, precision=None, cpu_only=False) ->
dummy_trainer = Trainer(devices=1, accelerator='cpu', strategy=NLPDDPStrategy())
model_config = MegatronGPTModel.restore_from(input_nemo_file, trainer=dummy_trainer, return_config=True)
model_config.tensor_model_parallel_size = 1
+ model_config.virtual_pipeline_model_parallel_size = None
+ model_config.sequence_parallel = False
model_config.pipeline_model_parallel_size = 1
if cpu_only:
map_location = torch.device('cpu')
@@ -0,0 +1,24 @@
diff --git a/examples/nlp/language_modeling/tuning/megatron_gpt_finetuning.py b/examples/nlp/language_modeling/tuning/megatron_gpt_finetuning.py
index bfe8ea359..dfeaf93b5 100644
--- a/examples/nlp/language_modeling/tuning/megatron_gpt_finetuning.py
+++ b/examples/nlp/language_modeling/tuning/megatron_gpt_finetuning.py
@@ -13,6 +13,8 @@
# limitations under the License.
import torch.multiprocessing as mp
+import torch.distributed as dist
+
from omegaconf.omegaconf import OmegaConf
from nemo.collections.nlp.models.language_modeling.megatron_gpt_sft_model import MegatronGPTSFTModel
@@ -76,6 +78,10 @@ def main(cfg) -> None:
trainer.fit(model)
+ if dist.is_available() and dist.is_initialized():
+ dist.barrier()
+ dist.destroy_process_group()
+
if __name__ == '__main__':
main()
@@ -0,0 +1,13 @@
diff --git a/src/utils/training_metrics/process_training_results.py b/src/utils/training_metrics/process_training_results.py
index 3e82a66..e61e1d8 100644
--- a/src/utils/training_metrics/process_training_results.py
+++ b/src/utils/training_metrics/process_training_results.py
@@ -134,7 +134,7 @@ def get_average_step_time(file: str, start_step: int, end_step: int) -> float:
for line in datajson:
if line.get("step") != "PARAMETER":
step = line.get("step")
- if step >= start_step and step <= end_step:
+ if step >= start_step and step <= end_step and "train_step_timing in s" in line["data"]:
time_step_accumulator += line["data"].get("train_step_timing in s")
num_steps += 1
if num_steps == 0:
@@ -0,0 +1,10 @@
dllogger@git+https://github.com/NVIDIA/dllogger@v1.0.0
# Fixing these libraries versions to avoid conflicting or broken packages.
immutabledict==4.2.1
protobuf==4.25.8
opencv-python-headless==4.11.0.86
docutils==0.16
urllib3==2.5.0
google-cloud-storage==3.0.0
retrying
@@ -0,0 +1,18 @@
# cuml-cu12==24.8.0 was installed in nemo:24.09
# Removing cuml=24.4.0 to avoid conflicting packages.
cudf==24.4.0
cugraph==24.4.0
cugraph-service-server==24.4.0
cuml==24.4.0
dask-cudf==24.4.0
raft-dask==24.4.0
cugraph-dgl==24.4.0
cugraph-pyg==24.4.0
# The following packages are removed temporarily to avoid conflicting packages
# and can be brought back if needed.
tensorrt-llm==0.12.0
img2dataset==1.45.0
Sphinx==8.1.3
sphinxcontrib-bibtex==2.6.3
torchx==0.7.0
nemo-run
@@ -0,0 +1,66 @@
# Dockerfile wrapping NeMo.
#
# To workaround base nemo docker image using too many layers, we use Multi-stage
# build to first collect the additional files we'll need.
FROM alpine:latest AS prep_files
WORKDIR /workspace
RUN mkdir -p configs vdt vdt/util
COPY scripts/*.py vdt/
COPY scripts/util/*.py vdt/util/
COPY configs/* configs/
COPY docker/patches/24.09/* vdt/patches/
RUN chmod a+rwX -R vdt
# Copy license.
RUN wget https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/LICENSE
# Available tags
# https://catalog.ngc.nvidia.com/orgs/nvidia/containers/nemo/tags
# It installs NeMo source code in /opt/NeMo folder, with tag=r2.0.0
FROM nvcr.io/nvidia/nemo:24.09
RUN apt-get update && apt-get install -y sudo zsh tmux && \
rm -rf /var/lib/apt/lists*
RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | \
tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && \
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | \
apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - && \
apt-get update -y && apt-get install google-cloud-sdk -y && \
rm -rf /var/lib/apt/lists*
# Install libraries with pip
ENV PIP_ROOT_USER_ACTION=ignore
# We expect this will be run in the root directory of the vertex-dist-recipes repo
ARG HOST_SRC_DIR="."
# The pre-installed NeMo introduces a lot of deps conflicts.
# We uninstall the confilicting libs and reinstall some of them as needed.
COPY ${HOST_SRC_DIR}/docker/uninstall.txt /tmp/uninstall.txt
RUN cat /tmp/uninstall.txt | grep -v '#' | xargs pip uninstall -y
COPY ${HOST_SRC_DIR}/docker/requirements.txt /tmp/requirements.txt
RUN pip install -r /tmp/requirements.txt
# Make sure there's no inconsistent pip libraries.
RUN pip check
WORKDIR /workspace
# Copy configs
COPY ${HOST_SRC_DIR}/configs/* /opt/NeMo/examples/nlp/language_modeling/conf/
# Copy all additional files we need from `prep_files` image.
COPY --from=prep_files /workspace/ .
# Install for `src/utils/training_metrics/process_training_results.py` to report
# throughput and MFU numbers.
RUN git clone https://github.com/AI-Hypercomputer/gpu-recipes.git
# This hack is needed for multi-node training while not using a sharing file system.
RUN patch --verbose -l -d /opt/megatron-lm/megatron/core/datasets -p1 -i /workspace/vdt/patches/local_rank.patch; \
git -C /workspace/gpu-recipes apply /workspace/vdt/patches/throughput_calc.patch; \
git -C /opt/NeMo apply /workspace/vdt/patches/nemo2hf.patch; \
git -C /opt/NeMo apply /workspace/vdt/patches/sigabort.patch;
# git -C /opt/NeMo apply /workspace/vdt/patches/gpu_stats.patch;
# Do not put an entrypoint here. Specify the entrypoint in the docker run script.
@@ -0,0 +1,16 @@
{
"project_id": "<your_project_id>",
"region": "us-central1",
"zone": "us-central1-c",
"bucket": "<your_bucket",
"dataset_bucket": "github-repo/data/third-party/enwiki-latest-pages-articles",
"image_uri": "<your_image_uri>",
"strategy": "spot",
"nodes": "2",
"machine_type": "a3-megagpu-8g",
"gpu_type": "NVIDIA_H100_MEGA_80GB",
"gpus_per_node": "8",
"recipe_name": "llama3_1_8b_pretrain_a3mega",
"job_prefix": "vertex-ai",
"reservation_name": ""
}
@@ -0,0 +1,49 @@
absl-py==2.2.2
annotated-types==0.7.0
anyio==4.9.0
black==25.1.0
cachetools==5.5.2
certifi==2025.4.26
charset-normalizer==3.4.2
click==8.1.8
docstring_parser==0.16
google-api-core==2.24.2
google-auth==2.40.1
google-cloud-aiplatform==1.92.0
google-cloud-bigquery==3.31.0
google-cloud-core==2.4.3
google-cloud-resource-manager==1.14.2
google-cloud-storage==2.19.0
google-crc32c==1.7.1
google-genai==1.14.0
google-resumable-media==2.7.2
googleapis-common-protos==1.70.0
grpc-google-iam-v1==0.14.2
grpcio==1.71.0
grpcio-status==1.71.0
h11==0.16.0
httpcore==1.0.9
httpx==0.28.1
idna==3.10
mypy_extensions==1.1.0
numpy==2.2.5
packaging==25.0
pathspec==0.12.1
platformdirs==4.3.8
proto-plus==1.26.1
protobuf==5.29.4
pyasn1==0.6.1
pyasn1_modules==0.4.2
pydantic==2.11.4
pydantic_core==2.33.2
python-dateutil==2.9.0.post0
pytz==2025.2
requests==2.32.4
rsa==4.9.1
shapely==2.1.0
six==1.17.0
sniffio==1.3.1
typing-inspection==0.4.0
typing_extensions==4.13.2
urllib3==2.4.0
websockets==15.0.1
@@ -0,0 +1,173 @@
"""Launch script for Vertex distributed training"""
# Copy the sample_job_config.json file to job_config.json
# to define the job parameters.
#
# Run like this:
#
# python3 vertex_dist_train/launch.py --config_file=job_config.json
#
import datetime
import json
import os
import pprint
from collections.abc import Sequence
from typing import Any, List
from absl import app, flags
from google.cloud import aiplatform
from google.cloud.aiplatform_v1.types.custom_job import Scheduling
from pytz import timezone
FLAGS = flags.FLAGS
flags.DEFINE_string("config_file", None, "Path to JSON config file")
flags.DEFINE_boolean(
"debug", False, "Debug mode: just print the command, don't run it."
)
def launch_job(
job_name: str,
project: str,
region: str,
gcs_bucket: str,
image_uri: str,
entrypoint_cmd: List[str],
trainer_args: List[Any],
num_nodes: int,
machine_type: str,
num_gpus_per_node: int,
gpu_type: str,
strategy: str,
reservation_name: str = "",
):
assert strategy in ("dws", "spot", "reservation")
aiplatform.init(
project=project, location=region, staging_bucket=gcs_bucket
)
train_job = aiplatform.CustomContainerTrainingJob(
display_name=job_name,
container_uri=image_uri,
command=entrypoint_cmd,
)
job_args = dict(
args=trainer_args,
enable_web_access=True,
replica_count=num_nodes,
machine_type=machine_type,
accelerator_type=gpu_type,
accelerator_count=num_gpus_per_node,
boot_disk_size_gb=1000,
restart_job_on_worker_restart=True,
#restart_job_on_worker_restart=False,
)
if strategy == "spot":
job_args.update({"scheduling_strategy": Scheduling.Strategy.SPOT.name})
elif strategy == "dws":
job_args.update(
{"scheduling_strategy": Scheduling.Strategy.FLEX_START.name}
)
elif strategy == "reservation":
assert reservation_name != "", (
"If using a reservation, provide the reservation_name in the "
"format `projects/{project_id_or_number}/zones/{zone}/"
"reservations/{reservation_name}`"
)
job_args.update(
{
"reservation_affinity_type": "SPECIFIC_RESERVATION",
"reservation_affinity_key": "compute.googleapis.com/reservation-name",
"reservation_affinity_values": [reservation_name],
}
)
pprint.pprint(job_args)
if not FLAGS.debug:
train_job.submit(**job_args)
def main(argv: Sequence[str]) -> None:
config_file_path = FLAGS.config_file
print(f"Reading job config from {config_file_path}")
with open(config_file_path, encoding="utf-8") as config_file:
config = json.load(config_file)
project_id = config["project_id"]
region = config["region"]
zone = config["zone"]
bucket = config["bucket"]
dataset_bucket = config["dataset_bucket"]
n_nodes = int(config["nodes"])
machine_type = config["machine_type"]
num_gpus_per_node = int(config["gpus_per_node"])
gpu_type = config["gpu_type"]
reservation_name = config.get("reservation_name")
reservation_full_name = (
f"projects/{project_id}/zones/{zone}/reservations/{reservation_name}"
if "reservation_name" in config
else ""
)
strategy = config["strategy"]
recipe_name = config["recipe_name"]
job_prefix = config["job_prefix"]
image_uri = config["image_uri"]
# Job name
timestamp = (
datetime.datetime.now()
.astimezone(timezone("US/Pacific"))
.strftime("%Y%m%d_%H%M%S")
)
job_name = f"{recipe_name}-{timestamp}"
if job_prefix:
job_name = f"{job_prefix}-{job_name}"
base_output_dir = os.path.join("/gcs", bucket, job_name)
# Training command and args
entrypoint_cmd = ["python3", "vdt/run.py"]
dataset_bucket = f"gs://{config['dataset_bucket']}"
trainer_args = [
f"--train_data_gcs={dataset_bucket}",
"/opt/NeMo/examples/nlp/language_modeling/megatron_gpt_pretraining.py",
"--config-path=conf/",
f"--config-name={recipe_name}.yaml",
f"exp_manager.explicit_log_dir={base_output_dir}",
f"exp_manager.dllogger_logger_kwargs.json_file={base_output_dir}/dllogger.json",
"+exp_manager.create_tensorboard_logger=true",
"exp_manager.create_checkpoint_callback=false",
f"trainer.num_nodes={n_nodes}",
f"trainer.devices={num_gpus_per_node}",
"trainer.max_steps=10",
"trainer.log_every_n_steps=1",
"model.tokenizer.vocab_file=/data/gpt2-vocab.json",
"model.tokenizer.merge_file=/data/gpt2-merges.txt",
"model.data.data_prefix=[1.0,/data/hfbpe_gpt_training_data_text_document]",
]
launch_job(
job_name=job_name,
project=project_id,
region=region,
gcs_bucket=bucket,
image_uri=image_uri,
entrypoint_cmd=entrypoint_cmd,
trainer_args=trainer_args,
num_nodes=n_nodes,
machine_type=machine_type,
num_gpus_per_node=num_gpus_per_node,
gpu_type=gpu_type,
strategy=strategy,
reservation_name=reservation_full_name,
)
if __name__ == "__main__":
app.run(main)
@@ -0,0 +1,85 @@
"""Entrypoint for Vertex Distributed Training container."""
import argparse
import os
import sys
from collections.abc import Sequence
from subprocess import STDOUT, check_output, run
from absl import app, flags, logging
from util import cluster_spec
from retrying import retry
# PyTorch barrier call which synchronizes all of the nodes before launching the training process.
# This makes sure that processes will block until all processes are ready.
# Improves the reliability of spot VM usage for multi-node training jobs
@retry(stop_max_attempt_number=100, wait_exponential_multiplier=1000)
def barrier_with_retry() -> None:
import torch
logging.info("Starting barrier on RANK {}".format(os.environ["RANK"]))
torch.distributed.init_process_group()
torch.distributed.barrier()
torch.distributed.destroy_process_group()
logging.info("Finished barrier on RANK {}".format(os.environ["RANK"]))
def main(unused_argv: Sequence[str]) -> None:
parser = argparse.ArgumentParser()
parser.add_argument(
"--train_data_gcs",
type=str,
help="Download training data from gcs path",
)
args, unknown = parser.parse_known_args()
for key, val in os.environ.items():
logging.info("ENV %s=%s", key, val)
if args.train_data_gcs:
local_dir = "/data"
if not os.path.exists(local_dir):
os.mkdir(local_dir)
logging.info("downloading %s to %s...", args.train_data_gcs, local_dir)
check_output(
[
"gcloud",
"storage",
"cp",
"-r",
f"{args.train_data_gcs}/*",
local_dir,
],
stderr=STDOUT,
)
logging.info("%s downloaded.", args.train_data_gcs)
primary_node_addr, primary_node_port, node_rank, num_nodes = (
cluster_spec.get_cluster_spec()
)
cmd = [
"torchrun",
"--nproc-per-node=8",
f"--nnodes={num_nodes}",
f"--node_rank={node_rank}",
]
if num_nodes > 1:
cmd += [
"--max-restarts=3",
"--rdzv-backend=static",
f'--rdzv_id={os.getenv("CLOUD_ML_JOB_ID", primary_node_port)}',
f"--rdzv-endpoint={primary_node_addr}:{primary_node_port}",
]
cmd += unknown
logging.info("launching with cmd: \n%s", " \\\n".join(cmd))
barrier_with_retry()
run(cmd, stdout=sys.stdout, stderr=sys.stdout, check=True)
if __name__ == "__main__":
logging.get_absl_handler().python_handler.stream = sys.stdout
app.run(
main, flags_parser=lambda _args: flags.FLAGS(_args, known_only=True)
)
@@ -0,0 +1,81 @@
"""Get cluster info from environment variables."""
import dataclasses
import json
import os
from absl import logging
@dataclasses.dataclass
class ClusterInfo:
"""Contains information about the cluster.
Attributes:
primary_node_addr: The address of the primary node.
primary_node_port: The port of the primary node.
node_rank: The rank of the node.
num_nodes: The number of nodes in the cluster.
"""
primary_node_addr: str | None = None
primary_node_port: str | None = None
node_rank: int = 0
num_nodes: int = 1
# Allows unpacking operation like
# primary_node_addr, primary_node_port, _, _ = ClusterInfo()
# See https://stackoverflow.com/a/70753113
def __iter__(self):
return iter(dataclasses.astuple(self))
def get_cluster_spec() -> ClusterInfo:
"""Parses CLUSTER_SPEC environment variable and returns the cluster info.
Returns:
A ClusterInfo object.
"""
cluster_spec = os.getenv("CLUSTER_SPEC", None)
# If CLUSTER_SPEC is not set, use individual vars to construct cluster info.
if not cluster_spec:
cluster_info = ClusterInfo(
primary_node_addr=os.getenv("MASTER_ADDR", None),
primary_node_port=os.getenv("MASTER_PORT", None),
node_rank=int(os.getenv("RANK", "0")),
num_nodes=int(os.getenv("NNODES", "1")),
)
return cluster_info
cluster_data = json.loads(cluster_spec)
# Get primary node info
primary_node = cluster_data["cluster"]["workerpool0"][0]
logging.info("primary node: %s", primary_node)
primary_node_addr, primary_node_port = primary_node.split(":")
logging.info("primary node address: %s", primary_node_addr)
logging.info("primary node port: %s", primary_node_port)
# Determine node rank of this machine
workerpool = cluster_data["task"]["type"]
if workerpool == "workerpool0":
node_rank = 0
elif workerpool == "workerpool1":
# Add 1 for the primary node, since `index` is the index of workerpool1.
node_rank = cluster_data["task"]["index"] + 1
else:
raise ValueError(
"Only workerpool0 and workerpool1 are supported. Unknown workerpool:"
f" {workerpool}"
)
logging.info("node rank: %s", node_rank)
# Calculate total nodes.
num_nodes = 1 # For the primary node.
if "workerpool1" in cluster_data["cluster"]:
num_nodes += len(cluster_data["cluster"]["workerpool1"])
logging.info("num nodes: %s", num_nodes)
return ClusterInfo(
primary_node_addr, primary_node_port, node_rank, num_nodes
)
@@ -0,0 +1,59 @@
"""Add tests for cluster_spec.py."""
import os
from . import cluster_spec
# TODO(styer): Use pytest instead
class ClusterSpecTest(googletest.TestCase):
def setUp(self):
super().setUp()
self.curr_env_var = os.environ.copy()
def tearDown(self):
super().tearDown()
os.environ = self.curr_env_var
def test_get_cluster_spec_from_env_vars(self):
os.environ["CLUSTER_SPEC"] = ""
os.environ["MASTER_ADDR"] = "127.0.0.1"
os.environ["MASTER_PORT"] = "8080"
os.environ["RANK"] = "0"
os.environ["NNODES"] = "2"
cluster_info = cluster_spec.get_cluster_spec()
self.assertEqual(cluster_info.primary_node_addr, "127.0.0.1")
self.assertEqual(cluster_info.primary_node_port, "8080")
self.assertEqual(cluster_info.node_rank, 0)
self.assertEqual(cluster_info.num_nodes, 2)
def test_get_cluster_spec_from_cluster_spec(self):
os.environ[
"CLUSTER_SPEC"
] = """
{
"cluster": {
"workerpool0": [
"127.0.0.1:8080"
],
"workerpool1": [
"127.0.0.2:8080",
"127.0.0.3:8080"
]
},
"task": {
"type": "workerpool1",
"index": 0
}
}
"""
cluster_info = cluster_spec.get_cluster_spec()
self.assertEqual(cluster_info.primary_node_addr, "127.0.0.1")
self.assertEqual(cluster_info.primary_node_port, "8080")
self.assertEqual(cluster_info.node_rank, 1)
self.assertEqual(cluster_info.num_nodes, 3)
if __name__ == "__main__":
googletest.main()
@@ -1,13 +1,16 @@
"""Common util functions for notebook."""
import base64
from collections.abc import Sequence
import datetime
import io
import json
import os
import subprocess
from typing import Any, Dict, Sequence
import time
from typing import Any
from google import auth
from google.cloud import storage
import matplotlib.pyplot as plt
import numpy as np
@@ -281,7 +284,7 @@ def decode_image(
return image
def get_label_map(label_map_yaml_filepath: str) -> Dict[int, str]:
def get_label_map(label_map_yaml_filepath: str) -> dict[int, str]:
"""Returns class id to label mapping given a filepath to the label map.
Args:
@@ -331,6 +334,7 @@ def vqa_predict(
image: Any,
language_code: str = "en",
new_width: int = 1000,
use_dedicated_endpoint: bool = False,
) -> Sequence[str]:
"""Predicts the answer to a question about an image using an Endpoint."""
# Resize and convert image to base64 string.
@@ -354,7 +358,9 @@ def vqa_predict(
"image": resized_image_base64,
})
response = endpoint.predict(instances=instances)
response = endpoint.predict(
instances=instances, use_dedicated_endpoint=use_dedicated_endpoint
)
return [pred.get("response") for pred in response.predictions]
@@ -364,6 +370,7 @@ def caption_predict(
image: Any,
caption_prompt: bool = False,
new_width: int = 1000,
use_dedicated_endpoint: bool = False,
) -> str:
"""Predicts a caption for a given image using an Endpoint."""
# Resize and convert image to base64 string.
@@ -378,7 +385,9 @@ def caption_predict(
instance["prompt"] = caption_prompt_format.format(language_code)
instances = [instance]
response = endpoint.predict(instances=instances)
response = endpoint.predict(
instances=instances, use_dedicated_endpoint=use_dedicated_endpoint
)
return response.predictions[0].get("response")
@@ -387,6 +396,7 @@ def ocr_predict(
ocr_prompt: str,
image: Any,
new_width: int = 1000,
use_dedicated_endpoint: bool = False,
) -> str:
"""Extracts text from a given image using an Endpoint."""
# Resize and convert image to base64 string.
@@ -398,7 +408,9 @@ def ocr_predict(
instance["prompt"] = ocr_prompt
instances = [instance]
response = endpoint.predict(instances=instances)
response = endpoint.predict(
instances=instances, use_dedicated_endpoint=use_dedicated_endpoint
)
return response.predictions[0].get("response")
@@ -407,6 +419,7 @@ def detect_predict(
detect_prompt: str,
image: Any,
new_width: int = 1000,
use_dedicated_endpoint: bool = False,
) -> str:
"""Predicts the answer to a question about an image using an Endpoint."""
# Resize and convert image to base64 string.
@@ -418,7 +431,9 @@ def detect_predict(
instance["prompt"] = detect_prompt
instances = [instance]
response = endpoint.predict(instances=instances)
response = endpoint.predict(
instances=instances, use_dedicated_endpoint=use_dedicated_endpoint
)
return response.predictions[0].get("response")
@@ -495,6 +510,17 @@ def get_quota(project_id: str, region: str, resource_id: str) -> int:
):
return -1
all_regions_data = quota_data[0]["consumerQuotaLimits"][0]["quotaBuckets"]
# If the quota data does not have dimensions, it is global quota. However,
# global quota may be overridden by regional quota. So we need to check the
# global quota first.
global_quota = -1
if (
all_regions_data
and "dimensions" not in all_regions_data[0]
and "effectiveLimit" in all_regions_data[0]
):
global_quota = int(all_regions_data[0]["effectiveLimit"])
for region_data in all_regions_data:
if (
region_data.get("dimensions")
@@ -504,12 +530,13 @@ def get_quota(project_id: str, region: str, resource_id: str) -> int:
return int(region_data["effectiveLimit"])
else:
return 0
return -1
return global_quota
def get_resource_id(
accelerator_type: str,
is_for_training: bool,
is_spot: bool = False,
is_restricted_image: bool = False,
is_dynamic_workload_scheduler: bool = False,
) -> str:
@@ -519,6 +546,7 @@ def get_resource_id(
accelerator_type: The accelerator type.
is_for_training: Whether the resource is used for training. Set false for
serving use case.
is_spot: Whether the resource is used with Spot.
is_restricted_image: Whether the image is hosted in `vertex-ai-restricted`.
is_dynamic_workload_scheduler: Whether the resource is used with Dynamic
Workload Scheduler.
@@ -533,7 +561,10 @@ def get_resource_id(
"NVIDIA_TESLA_A100": "nvidia_a100_gpus",
"NVIDIA_A100_80GB": "nvidia_a100_80gb_gpus",
"NVIDIA_H100_80GB": "nvidia_h100_gpus",
"NVIDIA_H100_MEGA_80GB": "nvidia_h100_mega_gpus",
"NVIDIA_H200_141GB": "nvidia_h200_gpus",
"NVIDIA_TESLA_T4": "nvidia_t4_gpus",
"TPU_V6e": "tpu_v6e",
"TPU_V5e": "tpu_v5e",
"TPU_V3": "tpu_v3",
}
@@ -548,6 +579,10 @@ def get_resource_id(
restricted_image_training_accelerator_map = {
"NVIDIA_A100_80GB": "restricted_image_training_nvidia_a100_80gb_gpus",
}
spot_serving_accelerator_map = {
key: f"custom_model_serving_preemptible_{accelerator_suffix_map[key]}"
for key in accelerator_suffix_map
}
serving_accelerator_map = {
key: f"custom_model_serving_{accelerator_suffix_map[key]}"
for key in accelerator_suffix_map
@@ -576,8 +611,11 @@ def get_resource_id(
else:
if is_dynamic_workload_scheduler:
raise ValueError("Dynamic Workload Scheduler does not work for serving.")
if accelerator_type in serving_accelerator_map:
return serving_accelerator_map[accelerator_type]
accelerator_map = (
spot_serving_accelerator_map if is_spot else serving_accelerator_map
)
if accelerator_type in accelerator_map:
return accelerator_map[accelerator_type]
else:
raise ValueError(
f"Could not find accelerator type: {accelerator_type} for serving."
@@ -590,13 +628,28 @@ def check_quota(
accelerator_type: str,
accelerator_count: int,
is_for_training: bool,
is_spot: bool = False,
is_restricted_image: bool = False,
is_dynamic_workload_scheduler: bool = False,
):
"""Checks if the project and the region has the required quota."""
) -> None:
"""Checks if the project and the region has the required quota.
Args:
project_id: The project id.
region: The region.
accelerator_type: The accelerator type.
accelerator_count: The number of accelerators to check quota for.
is_for_training: Whether the resource is used for training. Set false for
serving use case.
is_spot: Whether the resource is used with Spot.
is_restricted_image: Whether the image is hosted in `vertex-ai-restricted`.
is_dynamic_workload_scheduler: Whether the resource is used with Dynamic
Workload Scheduler.
"""
resource_id = get_resource_id(
accelerator_type,
is_for_training=is_for_training,
is_spot=is_spot,
is_restricted_image=is_restricted_image,
is_dynamic_workload_scheduler=is_dynamic_workload_scheduler,
)
@@ -620,3 +673,75 @@ def check_quota(
f" {accelerator_count}. {quota_request_instruction}"
)
def get_deploy_source() -> str:
"""Gets deploy_source string based on running environment."""
vertex_product = os.environ.get("VERTEX_PRODUCT", "")
match vertex_product:
case "COLAB_ENTERPRISE":
return "notebook_colab_enterprise"
case "WORKBENCH_INSTANCE":
return "notebook_workbench"
case _:
# Legacy workbench, legacy colab, or other custom environments.
return "notebook_environment_unspecified"
def _is_operation_done(op_name: str, region: str) -> bool:
"""Checks if the operation is done.
Args:
op_name: The name of the operation to poll.
region: The region of the operation.
Returns:
True if the operation is done, False otherwise.
Raises:
ValueError: If the operation failed.
"""
creds, _ = auth.default()
auth_req = auth.transport.requests.Request()
creds.refresh(auth_req)
headers = {
"Authorization": f"Bearer {creds.token}",
}
url = f"https://{region}-aiplatform.googleapis.com/ui/{op_name}"
response = requests.get(url, headers=headers)
operation_data = response.json()
if "error" in operation_data:
raise ValueError(f"Operation failed: {operation_data['error']}")
return operation_data.get("done", False)
def poll_and_wait(
op_name: str, region: str, total_wait: int, interval: int = 60
) -> None:
"""Polls the operation and waits for it to complete.
Args:
op_name: The name of the operation to poll.
region: The region of the operation.
total_wait: The total wait time in seconds.
interval: The interval between each poll in seconds.
Raises:
TimeoutError: If the operation times out.
"""
start_time = time.time()
while True:
if _is_operation_done(op_name, region):
break
time_elapsed = time.time() - start_time
if time_elapsed > total_wait:
raise TimeoutError(
f"Operation timed out after {int(time_elapsed)} seconds."
)
print(
"\rStill waiting for operation... Elapsed time in seconds:"
f" {int(time_elapsed):<6}",
end="",
flush=True,
)
time.sleep(interval)
@@ -7,7 +7,7 @@ import json
import multiprocessing
import os
import subprocess
from typing import Any, Callable, Dict, Union
from typing import Any, Callable, Dict, Tuple, Union
from absl import logging
import accelerate
import datasets
@@ -70,7 +70,9 @@ def force_gcs_fuse_path(gcs_uri: str) -> str:
def download_gcs_uri_to_local(
gcs_uri: str, destination_dir: str = LOCAL_BASE_MODEL_DIR
gcs_uri: str,
destination_dir: str = LOCAL_BASE_MODEL_DIR,
check_path_exists: bool = True,
) -> str:
"""Downloads GCS URI to local.
@@ -81,6 +83,7 @@ def download_gcs_uri_to_local(
Args:
gcs_uri: GCS URI to download.
destination_dir: Local directory directory.
check_path_exists: Whether to check if the path exists.
Returns:
Local path to target folder/file.
@@ -89,7 +92,7 @@ def download_gcs_uri_to_local(
destination_dir,
os.path.basename(os.path.normpath(gcs_uri)),
)
if os.path.exists(target):
if check_path_exists and os.path.exists(target):
logging.info("File %s already exists.", target)
return target
if accelerate.PartialState().is_local_main_process:
@@ -415,13 +418,42 @@ def get_filtered_dataset(
return filtered_dataset
def format_dataset(
dataset: datasets.Dataset,
input_column: str,
template: str = None,
tokenizer: transformers.PreTrainedTokenizer | None = None,
) -> datasets.Dataset:
"""Takes a raw dataset and formats it using a template and tokenizer.
Args:
dataset: The raw (unprocessed) dataset to format.
input_column: The input column in the dataset to be used or updaded by the
template. If it does not exist, the template's `prompt_no_input` will be
used, and the input_column will be created.
template: Name of the JSON template file under `templates/` or GCS path to
the template file.
tokenizer: The tokenizer to use for chat_template templates.
Returns:
A dataset compatible with the template.
"""
return dataset.map(
_format_template_fn(
template,
input_column=input_column,
tokenizer=tokenizer,
)
)
def load_dataset_with_template(
dataset_name: str,
split: str,
input_column: str,
template: str = None,
tokenizer: transformers.PreTrainedTokenizer | None = None,
) -> Any:
) -> Tuple[Any, Any]:
"""Loads dataset with templates.
Args:
@@ -435,19 +467,15 @@ def load_dataset_with_template(
tokenizer: The tokenizer to use for chat_template templates.
Returns:
A dataset compatible with the template.
The raw dataset and the dataset compatible with the template.
"""
dataset = _get_dataset(dataset_name, split=split)
raw = _get_dataset(dataset_name, split=split)
if template:
dataset = dataset.map(
_format_template_fn(
template,
input_column=input_column,
tokenizer=tokenizer,
)
)
templated = format_dataset(raw, input_column, template, tokenizer)
else:
templated = None
return dataset
return raw, templated
def validate_dataset_with_template(
@@ -521,12 +549,11 @@ def validate_dataset_with_template(
f" https://github.com/GoogleCloudPlatform/{_VERTEX_AI_SAMPLES_GITHUB_REPO_NAME}/tree/main/{_VERTEX_AI_SAMPLES_GITHUB_TEMPLATE_DIR}."
)
dataset = _get_dataset(dataset_name, split, num_proc).map(
_format_template_fn(
template_path,
input_column=input_column,
tokenizer=tokenizer,
)
dataset = format_dataset(
_get_dataset(dataset_name, split, num_proc),
input_column,
template_path,
tokenizer,
)
if tokenizer is not None:
@@ -541,4 +568,3 @@ def validate_dataset_with_template(
os.path.basename(dataset_name), os.path.basename(template)
)
)
@@ -0,0 +1,95 @@
"""Class that bundles docker related flags."""
import getpass
import os
import pwd
class CommandBuilder:
"""Base class for building commands."""
def __init__(self):
self._defaults = []
self._env_vars = {}
def add_env_var(self, var: str, val: str) -> None:
"""Add environment variable to the command.
Args:
var: environment variable name.
val: environment variable value.
"""
self._env_vars[var] = val
def add_mount_map(self, host_path, docker_path):
pass
class DockerCommandBuilder(CommandBuilder):
"""Bundle docker related flags."""
def __init__(self, docker_uri: str, shm_size: str = '128gb'):
super().__init__()
self._docker_uri = [docker_uri]
self.privilege_mode = []
self.entrypoint = []
self._defaults = [
'docker',
'run',
'--gpus=all',
'--net=host',
'--rm',
f'--shm-size={shm_size}',
]
self._mount_maps = []
user = getpass.getuser()
# username ends with `_google_com` is managed by ldap and does not have a
# corresponding entry in /etc/passwd or /etc/group file. We cannot enable
# non-root docker user with below method.
if not user.endswith('_google_com'):
uid = os.getuid()
gid = pwd.getpwuid(uid).pw_gid
self._defaults += [
f'--user={uid}:{gid}',
'--volume=/etc/group:/etc/group:ro',
'--volume=/etc/passwd:/etc/passwd:ro',
]
def add_mount_map(self, host_path, docker_path):
self._mount_maps.append(f'--volume={host_path}:{docker_path}')
def add_privilege_mode(self):
self.privilege_mode = ['--privileged']
def add_entrypoint(self, entrypoint: list[str]):
self.entrypoint = entrypoint
def build_cmd(self) -> str:
return (
self._defaults
+ [f'--env={var}={val}' for var, val in self._env_vars.items()]
+ self._mount_maps
+ self.privilege_mode
+ self._docker_uri
+ self.entrypoint
)
class PythonCommandBuilder(CommandBuilder):
"""Bundle Python test command related flags."""
def __init__(self):
super().__init__()
self._defaults = [
'python3',
'./vertex_vision_model_garden_peft/train/vmg/train_entrypoint.py',
]
def build_cmd(self) -> str:
os.environ.update(self._env_vars)
return self._defaults
def add_entrypoint(self, entrypoint: list[str]):
self._defaults = entrypoint
@@ -0,0 +1,471 @@
"""Test util class."""
import copy
import dataclasses
import datetime
import inspect
import os
import signal
import subprocess
import sys
from absl import flags
from absl import logging
from absl.testing import parameterized
import command_builder
import immutabledict
import torch
_DOCKER_URI = flags.DEFINE_string('docker_uri', None, 'docker image uri')
_DRY_RUN = flags.DEFINE_bool('dry_run', False, 'dry-run the commands')
_LOCAL_INPUT_DIR = flags.DEFINE_string(
'local_input_dir',
os.path.expanduser('~/test_input'),
'local directory for storing input data.',
)
_LOCAL_OUTPUT_DIR = flags.DEFINE_string(
'local_output_dir',
'/tmp',
'local directory for storing test output.',
)
_GCS_INPUT_DIR = flags.DEFINE_string(
'gcs_input_dir',
'gs://vmg-tuning-docker-test',
'GCS directory that stores model checkpoint, dataset and etc.',
)
_GCS_OUTPUT_DIR = flags.DEFINE_string(
'gcs_output_dir',
'gs://vmg-tuning-docker-test/output',
'GCS directory that stores test output.',
)
_GCS_TESTDATA_DIR = 'peft-train-image-test'
_THROUGHPUT_TEST_EXCEPTIONS = immutabledict.immutabledict({
('bm_deepspeed_zero3_8gpu_gemma-2-9b-it_4bit.txt', '12.0'): float('inf'),
('bm_fsdp_8gpu_llama3.1-70b-hf_4bit.txt', '20.0'): float('inf'),
('bm_deepspeed_zero2_8gpu_gemma-2-2b-it_bfloat16.txt', '12.0'): 20.0,
('bm_deepspeed_zero3_8gpu_gemma-2-2b-it_4bit.txt', '4.0'): 20.0,
('bm_deepspeed_zero3_8gpu_gemma-2-27b-it_4bit.txt', '4.0'): 20.0,
})
@dataclasses.dataclass
class BenchmarkStats:
"""Class to store the benchmark result.
Attributes:
peak_mem: peak memory in GB.
throughput: throughput in tokens/sec.
"""
peak_mem: float
throughput: float
class TestBase(parameterized.TestCase):
"""Test base class that defines how to run commands."""
def setUp(self):
super().setUp()
# Create a copy of the environment variables
self.old_env_var = copy.deepcopy(os.environ)
if _DOCKER_URI.value:
self.command_builder = command_builder.DockerCommandBuilder(
_DOCKER_URI.value
)
else:
self.command_builder = command_builder.PythonCommandBuilder()
self.command_builder.add_mount_map(
os.path.expanduser('~'), os.path.expanduser('~')
)
self.command_builder.add_mount_map(
self.local_input_dir(), self.local_input_dir()
)
self.task_cmd_builder = None
def tearDown(self):
super().tearDown()
# Restore the original environment variables
os.environ.clear()
os.environ.update(self.old_env_var)
def cmd(self):
return self.command_builder.build_cmd() + self.task_cmd_builder.build_cmd()
def run_cmd(self) -> int:
return run_cmd(self.cmd(), output_file=None)
def gcs_output_dir(self):
return _GCS_OUTPUT_DIR.value
def local_input_dir(self):
"""Returns local input dir in host/docker."""
return _LOCAL_INPUT_DIR.value
def local_output_dir(self):
"""Returns local output dir in host/docker."""
return _LOCAL_OUTPUT_DIR.value
def get_testcase_name(self):
"""Returns the function name at the calling site."""
# https://docs.python.org/3/library/inspect.html#inspect.FrameInfo
cur_frame = inspect.currentframe()
# https://stackoverflow.com/a/17366561
return cur_frame.f_back.f_code.co_name
def get_timestamp():
return datetime.datetime.now(datetime.timezone.utc).strftime(
'%Y%m%d_%H%M%S%Z'
)
def download_from_gcs(gcs_uri: str, local_dir: str):
if not os.path.exists(local_dir):
os.mkdir(local_dir)
subprocess.check_output([
'gcloud',
'storage',
'cp',
'-r',
gcs_uri,
local_dir,
])
def get_test_data_path(name: str, download: bool = True) -> str:
"""Gets test data path.
Args:
name: name of the test data
download: if True, then download data from GCS and returns its local path.
Returns:
test data path.
"""
if not download:
return os.path.join(_GCS_INPUT_DIR.value, name)
local_data = os.path.join(_LOCAL_INPUT_DIR.value, name)
if not os.path.exists(local_data):
# If `name` is a file in sub-folders, then create the sub-folders under
# `_LOCAL_INPUT_DIR`.
local_data_dir = os.path.dirname(local_data)
if not os.path.exists(local_data_dir):
os.makedirs(local_data_dir)
download_from_gcs(os.path.join(_GCS_INPUT_DIR.value, name), local_data_dir)
return local_data
def run_cmd(cmd: list[str], output_file: str = None) -> int:
"""Runs the command and returns the return code.
Args:
cmd: The command to run.
output_file: The file to write the output to.
Returns:
The return code of the command.
"""
logging.info('running command: \n%s', ' \\\n'.join(cmd))
if _DRY_RUN.value:
return 0
stdout = sys.stdout if output_file is None else open(output_file, 'w')
p = subprocess.Popen(cmd, stdout=stdout, stderr=sys.stderr)
try:
unused_output, unused_error = p.communicate()
return_code = p.returncode
except KeyboardInterrupt:
p.send_signal(signal.SIGINT)
return_code = 0
finally:
if output_file is not None:
stdout.close()
return return_code
def get_pretrained_model_name_or_path(model_id: str) -> str:
# If `model_id` contains `/`, it is assumed to be HF model or model from GCS.
if '/' in model_id:
return model_id
return get_test_data_path(model_id, download=True)
def is_gpu_h100():
"""Checks if the GPU is H100."""
return 'H100' in torch.cuda.get_device_name()
def is_gpu_a100():
"""Checks if the GPU is A100."""
return 'A100' in torch.cuda.get_device_name()
def _get_formatted_string(max_seq_length: int) -> str:
"""Returns the formatted string for max_seq_length.
Args:
max_seq_length: max sequence length to get the formatted string.
Returns:
formatted string for max_seq_length.
"""
return f'{max_seq_length/1024.0:.1f}'
def get_benchmark_results(
benchmark_file_path: str, max_seq_length: int
) -> BenchmarkStats:
"""Gets benchmark results from the benchmark file.
Args:
benchmark_file_path: path to the benchmark file.
max_seq_length: max sequence length to get the benchmark results.
Returns:
peak_mem: peak memory in GB.
throughput: throughput in tokens/sec.
"""
formatted_max_seq_length = _get_formatted_string(max_seq_length)
peak_mem, throughput = None, None
with open(benchmark_file_path, 'r') as f:
for line in f:
if line.startswith(formatted_max_seq_length):
metrics = line.split('|')
try:
peak_mem = float(metrics[1].strip())
except ValueError:
pass
try:
throughput = float(metrics[2].strip())
except ValueError:
pass
break
else:
logging.error(
'No metrics found for max_seq_length %s in %s',
formatted_max_seq_length,
benchmark_file_path,
)
return BenchmarkStats(peak_mem, throughput)
def print_benchmark_file(file_path: str) -> None:
"""Prints the contents of the file.
Args:
file_path: path to the file.
"""
with open(file_path, 'r') as f:
for line in f:
logging.info(line.strip())
def print_benchmark_results(
benchmark_file_path: str, benchmark_type: str
) -> None:
"""Prints the benchmark results.
Args:
benchmark_file_path: path to the benchmark file.
benchmark_type: type of the benchmark.
"""
benchmark_filename = os.path.basename(benchmark_file_path)
logging.info('--------------------------------------------------------------')
logging.info('%s benchmark for %s', benchmark_type, benchmark_filename)
logging.info('--------------------------------------------------------------')
print_benchmark_file(benchmark_file_path)
def _calculate_percent_change(
actual_value: float, expected_value: float
) -> float:
"""Calculates the percent change between the actual and expected values.
Args:
actual_value: actual value to compare.
expected_value: expected value to compare.
Returns:
percent change between the actual and expected values.
"""
return ((actual_value - expected_value) / expected_value) * 100.0
def compare_benchmark_results(
expected_benchmark_file_path: str,
actual_benchmark_file_path: str,
allowed_threshold: float,
max_seq_length: int,
) -> bool:
"""Compares if the benchmark results are the similar.
Args:
expected_benchmark_file_path: path to the expected benchmark file.
actual_benchmark_file_path: path to the actual benchmark file.
allowed_threshold: allowed percent range of the benchmark results.
max_seq_length: max sequence length to get the benchmark results.
Returns:
True if the benchmark results are the similar, False otherwise.
"""
benchmark_filename = os.path.basename(expected_benchmark_file_path)
expected_results = get_benchmark_results(
expected_benchmark_file_path, max_seq_length
)
expected_peak_mem, expected_throughput = (
expected_results.peak_mem,
expected_results.throughput,
)
actual_results = get_benchmark_results(
actual_benchmark_file_path, max_seq_length
)
actual_peak_mem, actual_throughput = (
actual_results.peak_mem,
actual_results.throughput,
)
formatted_max_seq_length = _get_formatted_string(max_seq_length)
# Case 1: both peak mem and throughput are None(ideally due to OOM)
if expected_peak_mem is None and actual_peak_mem is None:
logging.info(
'Both peak mem and throughput are None for max_seq_length %d.',
max_seq_length,
)
return True
check_oom_exception = _THROUGHPUT_TEST_EXCEPTIONS.get(
(benchmark_filename, formatted_max_seq_length), 0.0
) == float('inf')
# Case 2: When something strated to fail recently, or something which failed
# before but is working now.
if expected_peak_mem is None and actual_peak_mem is not None:
if check_oom_exception:
return True
logging.error(
'One of the failing benchmarks in %s is passing now for max_seq_length'
' %d. The expected peak mem and throughput are None, but the actual'
' peak mem is %f and actual throughput is %f',
benchmark_filename,
max_seq_length,
actual_peak_mem,
actual_throughput,
)
return False
if actual_peak_mem is None and expected_peak_mem is not None:
if check_oom_exception:
return True
logging.error(
'One of the passing benchmarks in %s is failing now for max_seq_length'
' %d. The actual peak mem and throughput are None, but the expected'
' peak mem is %f and expected throughput is %f',
benchmark_filename,
max_seq_length,
expected_peak_mem,
expected_throughput,
)
return False
# Case 3: When both actual peak mem and throughput lies within the range
# of their respective expected values.
mem_percent_change = _calculate_percent_change(
actual_peak_mem, expected_peak_mem
)
throughput_percent_change = _calculate_percent_change(
actual_throughput, expected_throughput
)
allowed_threshold = _THROUGHPUT_TEST_EXCEPTIONS.get(
(benchmark_filename, formatted_max_seq_length), allowed_threshold
)
if abs(mem_percent_change) > allowed_threshold:
logging.error(
'The peak memory is changing by more than %f%% for max_seq_length %d.'
' Expected: %f, Actual: %f',
allowed_threshold,
max_seq_length,
expected_peak_mem,
actual_peak_mem,
)
return False
if abs(throughput_percent_change) > allowed_threshold:
logging.error(
'The throughput is changing by more than %f%% for max_seq_length %d.'
' Expected throughput: %f, Actual throughput: %f',
allowed_threshold,
max_seq_length,
expected_throughput,
actual_throughput,
)
return False
return True
def check_benchmark_results(
actual_benchmark_file_path: str,
model_family: str,
allowed_threshold: float,
max_seq_length: int,
) -> bool:
"""Checks the benchmark result between the actual and expected benchmark files.
Args:
actual_benchmark_file_path: path to the actual benchmark file.
model_family: family of the model.
allowed_threshold: allowed range of the benchmark results in percent.
max_seq_length: max sequence length to get the benchmark results.
Returns:
True if the benchmark results are the similar, False otherwise.
"""
benchmark_filename = os.path.basename(actual_benchmark_file_path)
get_test_data_path(_GCS_TESTDATA_DIR)
expected_benchmark_file_path = os.path.join(
_LOCAL_INPUT_DIR.value,
_GCS_TESTDATA_DIR,
model_family,
benchmark_filename,
)
print_benchmark_results(expected_benchmark_file_path, 'Expected')
print_benchmark_results(actual_benchmark_file_path, 'Actual')
return compare_benchmark_results(
expected_benchmark_file_path,
actual_benchmark_file_path,
allowed_threshold,
max_seq_length,
)
def list_gcs_directories(bucket: str, directory: str) -> list[str]:
"""Lists GCS files."""
output = subprocess.check_output([
'gcloud',
'storage',
'ls',
f'gs://{bucket}/{directory}',
])
return output.decode('utf-8').splitlines()
def delete_gcs_object(gcs_directory: str):
"""Deletes GCS object."""
subprocess.check_output([
'gcloud',
'storage',
'rm',
'-r',
f'{gcs_directory}',
])
@@ -1,45 +0,0 @@
"""Class that bundles docker related flags."""
import getpass
import os
import pwd
class DockerCommandBuilder:
"""Bundle docker related flags."""
def __init__(self, docker_uri, shm_size='128gb'):
self._docker_uri = [docker_uri]
self._defaults = [
'docker',
'run',
'--gpus=all',
'--net=host',
'--rm',
f'--shm-size={shm_size}',
]
user = getpass.getuser()
# username ends with `_google_com` is managed by ldap and does not have a
# corresponding entry in /etc/passwd or /etc/group file. We cannot enable
# non-root docker user with below method.
if not user.endswith('_google_com'):
uid = os.getuid()
gid = pwd.getpwuid(uid).pw_gid
self._defaults += [
f'--user={uid}:{gid}',
'--volume=/etc/group:/etc/group:ro',
'--volume=/etc/passwd:/etc/passwd:ro',
]
self._env_vars = []
self._mount_maps = []
def add_env_var(self, var, val):
self._env_vars.append(f'--env={var}={val}')
def add_mount_map(self, host_path, docker_path):
self._mount_maps.append(f'--volume={host_path}:{docker_path}')
def build_cmd(self) -> str:
return self._defaults + self._env_vars + self._mount_maps + self._docker_uri
@@ -1,152 +0,0 @@
# pylint: disable=missing-function-docstring
# pylint: disable=missing-class-docstring
"""Tests to make sure trained model achieves decent quality.
Right now, the metric is loss decreasing and we'll eyeball the TB graphs.
"""
import os
from absl.testing import absltest
from absl.testing import parameterized
import instruct_lora_command_builder as task_cmd_builder
import test_util
class TrainedModelQualityTest(test_util.TestBase):
_TEST_OUTPUT_DIR = os.path.expanduser('~/output')
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.test_suite_output_dir = os.path.join(
cls._TEST_OUTPUT_DIR,
os.path.splitext(os.path.basename(__file__))[0],
cls.__class__.__name__,
)
def setUp(self):
super().setUp()
self.task_cmd_builder = task_cmd_builder.InstructLoraCommandBuilder()
self.task_cmd_builder.task = 'instruct-lora'
self.task_cmd_builder.eval_tasks = 'builtin_eval'
self.task_cmd_builder.eval_metric_name = 'loss'
self.task_cmd_builder.per_device_batch_size = 1
self.task_cmd_builder.gradient_accumulation_steps = 8
self.task_cmd_builder.lora_rank = 16
self.task_cmd_builder.lora_alpha = 32
self.task_cmd_builder.lora_dropout = 0.05
self.task_cmd_builder.learning_rate = 5e-5
self.task_cmd_builder.num_epochs = 2.0
self.task_cmd_builder.warmup_ratio = 0.01
self.task_cmd_builder.max_steps = -1
self.task_cmd_builder.save_steps = 10
self.task_cmd_builder.eval_steps = 10
self.task_cmd_builder.max_seq_length = 4096
self.task_cmd_builder.load_precision = '4bit'
self.task_cmd_builder.gradient_checkpointing = True
self.task_cmd_builder.completion_only = True
self.task_cmd_builder.attn_implementation = 'flash_attention_2'
self.task_cmd_builder.report_to = 'tensorboard'
def setup_output_dir(self, testcase_name: str):
testcase_output_dir = os.path.join(
self.test_suite_output_dir, testcase_name
)
self.task_cmd_builder.ckpt_dir = os.path.join(
testcase_output_dir, 'adapter'
)
self.task_cmd_builder.logging_dir = os.path.join(
testcase_output_dir, 'logs'
)
self.task_cmd_builder.merged_model_dir = os.path.join(
testcase_output_dir, 'merged'
)
@parameterized.named_parameters(
('llama3-8b', 'llama3-8b-hf'),
('llama3.1-8b', 'llama3.1-8b-hf'),
)
def test_8b_model_deepspeed(self, model_name):
self.setup_output_dir(f'test_deepspeed_{model_name}')
self.task_cmd_builder.pretrained_model_id = (
test_util.get_pretrained_model_id(model_name)
)
self.task_cmd_builder.train_dataset = test_util.get_test_data_path(
'peft_train_sample.jsonl'
)
self.task_cmd_builder.train_split_name = 'train'
self.task_cmd_builder.instruct_column = 'input_text'
self.task_cmd_builder.template = 'llama3-text-bison'
self.task_cmd_builder.eval_dataset = test_util.get_test_data_path(
'peft_eval_sample.jsonl'
)
self.task_cmd_builder.eval_split_name = 'train'
self.task_cmd_builder.eval_instruct_column = (
self.task_cmd_builder.instruct_column
)
self.task_cmd_builder.eval_template = self.task_cmd_builder.template
self.docker_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0')
self.assertEqual(self.run_cmd(), 0)
@parameterized.named_parameters(
('llama3-70b', 'llama3-70b-hf'),
('llama3.1-70b', 'llama3.1-70b-hf'),
)
def test_70b_model_deepspeed(self, model_name):
self.setup_output_dir(f'test_deepspeed_{model_name}')
self.task_cmd_builder.pretrained_model_id = (
test_util.get_pretrained_model_id(model_name)
)
self.task_cmd_builder.config_file = (
'vertex_vision_model_garden_peft/deepspeed_zero2_8gpu.yaml'
)
self.task_cmd_builder.train_dataset = 'timdettmers/openassistant-guanaco'
self.task_cmd_builder.train_split_name = 'train'
self.task_cmd_builder.instruct_column = 'text'
self.task_cmd_builder.template = 'openassistant-guanaco'
self.task_cmd_builder.eval_dataset = self.task_cmd_builder.train_dataset
self.task_cmd_builder.eval_split_name = 'test'
self.task_cmd_builder.eval_instruct_column = (
self.task_cmd_builder.instruct_column
)
self.task_cmd_builder.eval_template = self.task_cmd_builder.template
self.docker_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0,1,2,3,4,5,6,7')
self.assertEqual(self.run_cmd(), 0)
@parameterized.named_parameters(
('llama3-70b', 'llama3-70b-hf'),
('llama3.1-70b', 'llama3.1-70b-hf'),
)
def test_70b_model_fsdp(self, model_name):
self.setup_output_dir(f'test_fsdp_{model_name}')
self.task_cmd_builder.pretrained_model_id = (
test_util.get_pretrained_model_id(model_name)
)
self.task_cmd_builder.config_file = (
'vertex_vision_model_garden_peft/llama_fsdp_8gpu.yaml'
)
self.task_cmd_builder.train_dataset = 'timdettmers/openassistant-guanaco'
self.task_cmd_builder.train_split_name = 'train'
self.task_cmd_builder.instruct_column = 'text'
self.task_cmd_builder.template = 'openassistant-guanaco'
self.task_cmd_builder.eval_dataset = self.task_cmd_builder.train_dataset
self.task_cmd_builder.eval_split_name = 'test'
self.task_cmd_builder.eval_instruct_column = (
self.task_cmd_builder.instruct_column
)
self.task_cmd_builder.eval_template = self.task_cmd_builder.template
self.docker_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0,1,2,3,4,5,6,7')
self.assertEqual(self.run_cmd(), 0)
if __name__ == '__main__':
absltest.main()
@@ -1,49 +0,0 @@
# pylint: disable=missing-function-docstring
# pylint: disable=missing-class-docstring
"""Tests quantize model task in PEFT docker."""
import os
import time
from absl.testing import absltest
import quantize_model_command_builder as task_cmd_builder
import test_util
class QuantizeModelTest(test_util.TestBase):
def setUp(self):
super().setUp()
self.docker_builder.add_env_var('CUDA_VISIBLE_DEVICES', '')
self.docker_builder.add_mount_map(
os.path.expanduser('~'), os.path.expanduser('~')
)
self.task_cmd_builder = task_cmd_builder.QuantizeModelCommandBuilder()
self.task_cmd_builder.task = 'quantize-model'
self.task_cmd_builder.pretrained_model_id = (
'gs://vertex-model-garden-public-us/llama3/llama3-8b-hf'
)
self.task_cmd_builder.quantization_method = 'awq'
self.task_cmd_builder.quantization_precision_mode = '4bit'
self.task_cmd_builder.quantization_dataset_name = 'pileval'
self.task_cmd_builder.text_column_in_quantization_dataset = 'text'
self.task_cmd_builder.quantization_output_dir = '~/llama3-8b-hf-quantized'
self.task_cmd_builder.device_map = None
self.task_cmd_builder.max_memory = None
self.task_cmd_builder.group_size = 128
self.task_cmd_builder.desc_act = False
self.task_cmd_builder.damp_percent = 0.1
self.task_cmd_builder.cache_examples_on_gpu = False
self.task_cmd_builder.awq_version = 'GEMM'
def test_llama3_8b_model_awq_quantization(self):
start_time = time.time()
self.assertEqual(self.run_cmd(), 0)
end_time = time.time()
self.assertLess(end_time - start_time, 1.5 * 60 * 60)
if __name__ == '__main__':
absltest.main()
@@ -1,134 +0,0 @@
"""Test util class."""
import datetime
import os
import signal
import subprocess
import sys
from absl import flags
from absl import logging
from absl.testing import parameterized
import docker_command_builder as docker_cmd_builder
_DOCKER_URI = flags.DEFINE_string(
'docker_uri', None, 'docker image uri', required=True
)
_DRY_RUN = flags.DEFINE_bool('dry_run', False, 'dry-run the commands')
_LOCAL_INPUT_DIR = flags.DEFINE_string(
'local_input_dir',
os.path.expanduser('~/test_input'),
'local directory for storing input data.',
)
_LOCAL_OUTPUT_DIR = flags.DEFINE_string(
'local_output_dir',
'/tmp',
'local directory for storing test output.',
)
_GCS_INPUT_DIR = flags.DEFINE_string(
'gcs_input_dir',
'gs://peft-docker-test',
'GCS directory that stores model checkpoint, dataset and etc.',
)
_GCS_OUTPUT_DIR = flags.DEFINE_string(
'gcs_output_dir',
'gs://peft-docker-test/output',
'GCS directory that stores test output.',
)
class TestBase(parameterized.TestCase):
"""Test base class that defines how to run commands."""
def setUp(self):
super().setUp()
self.docker_builder = docker_cmd_builder.DockerCommandBuilder(
_DOCKER_URI.value
)
self.docker_builder.add_mount_map(
os.path.expanduser('~'), os.path.expanduser('~')
)
self.docker_builder.add_mount_map(
self.local_input_dir(), self.local_input_dir()
)
self.task_cmd_builder = None
def cmd(self):
return self.docker_builder.build_cmd() + self.task_cmd_builder.build_cmd()
def run_cmd(self) -> int:
logging.info('running command: \n%s', ' \\\n'.join(self.cmd()))
if _DRY_RUN.value:
return 0
p = subprocess.Popen(self.cmd(), stdout=sys.stdout, stderr=sys.stderr)
try:
unused_output, unused_error = p.communicate()
return p.returncode
except KeyboardInterrupt:
p.send_signal(signal.SIGINT)
return 0
def gcs_output_dir(self):
return _GCS_OUTPUT_DIR.value
def local_output_dir(self):
return _LOCAL_OUTPUT_DIR.value
def local_input_dir(self):
return _LOCAL_INPUT_DIR.value
def get_timestamp():
return datetime.datetime.now(datetime.timezone.utc).strftime(
'%Y%m%d_%H%M%S%Z'
)
def get_test_data_path(name: str, download: bool = True) -> str:
"""Gets test data path.
Args:
name: name of the test data
download: if True, then download data from GCS and returns its local path.
Returns:
test data path.
"""
def _download_from_gcs(name):
if not os.path.exists(_LOCAL_INPUT_DIR.value):
os.mkdir(_LOCAL_INPUT_DIR.value)
subprocess.check_output([
'gsutil',
'-m',
'cp',
'-r',
os.path.join(_GCS_INPUT_DIR.value, name),
_LOCAL_INPUT_DIR.value,
])
if not download:
return os.path.join(_GCS_INPUT_DIR.value, name)
local_data = os.path.join(_LOCAL_INPUT_DIR.value, name)
if not os.path.exists(local_data):
_download_from_gcs(name)
return local_data
def get_pretrained_model_id(model_id: str) -> str:
# If `model_id` contains `/`, it is assumed to be HF model or model from GCS.
if '/' in model_id:
return model_id
return get_test_data_path(model_id, download=True)
@@ -1,109 +0,0 @@
"""Tools to generate CommandBuilder class.
See go/vmg-oss-peft-tests#commandbuilder-class-generation for details.
"""
import argparse
import dataclasses
from typing import List
_DO_NOT_MODIFY_WARNING = """
# DO NOT MODIFY: this file is auto-generated
# See go/vmg-oss-peft-tests#command-builder-genpy
"""
_GETTER_TMPL = """
@property
def {}(self):
return self._{}
"""
_SETTER_TMPL = """
@{}.setter
def {}(self, val: {}):
self._{} = val
"""
_INIT_NAME = """
def __init__(self):"""
_INIT_FIELDS = """
self._{} = None"""
_BUILD_CMD = r"""
def build_cmd(self) -> str:
cmd = []
for k, v in self.__dict__.items():
if v is not None:
cmd.append(f'--{k[1:]}={v}')
return cmd
"""
@dataclasses.dataclass
class FlagInfo:
api_name: str
impl_name: str
arg_type: str
def get_flag_info(line: str) -> FlagInfo:
api_name, impl_name, arg_type = [x.strip() for x in line.split(',')]
return FlagInfo(api_name, impl_name, arg_type)
def gen_getter(info: FlagInfo) -> str:
return _GETTER_TMPL.format(info.api_name, info.impl_name)
def gen_setter(info: FlagInfo) -> str:
return _SETTER_TMPL.format(
info.api_name, info.api_name, info.arg_type, info.impl_name
)
def gen_init(infos: List[FlagInfo]) -> str:
fields = [_INIT_FIELDS.format(i.impl_name) for i in infos]
return ''.join([_INIT_NAME] + fields)
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
'--flags_def', required=True, help='file path contain flags definition.'
)
parser.add_argument(
'--generated_file',
required=True,
help='file path to the generated command builder.',
)
parser.add_argument(
'--class_name',
required=True,
help='class name for command build',
)
args = parser.parse_args()
flags_info = []
with open(args.flags_def, 'r') as flags_f:
for line in flags_f:
if not line.startswith('#'):
flags_info.append(get_flag_info(line))
with open(args.generated_file, 'w') as gen_f:
# Disables pylint messages.
# See https://stackoverflow.com/a/43510297
print('# pylint: disable=W,C,R', file=gen_f)
print(_DO_NOT_MODIFY_WARNING, file=gen_f)
print(f'class {args.class_name}:', file=gen_f)
print(gen_init(flags_info), file=gen_f)
for info in flags_info:
print(gen_getter(info), file=gen_f)
print(gen_setter(info), file=gen_f)
print(_BUILD_CMD, file=gen_f)
print(f'file generated at {args.generated_file}')
if __name__ == '__main__':
main()
@@ -1,50 +0,0 @@
# api_name, impl_name, value_type
# eval related and etc.
config_file, config_file, str
task, task, str
pretrained_model_id, pretrained_model_id, str
train_dataset, dataset_name, str
train_split_name, train_split_name, str
template, template, str
instruct_column, instruct_column_in_dataset, str
ckpt_dir, output_dir, str
merged_model_dir, merge_base_and_lora_output_dir, str
logging_dir, logging_output_dir, str
per_device_batch_size, per_device_train_batch_size, int
gradient_accumulation_steps, gradient_accumulation_steps, int
lora_rank, lora_rank, int
lora_alpha, lora_alpha, int
lora_dropout, lora_dropout, float
max_steps, max_steps, int
num_epochs, num_epochs, float
max_seq_length, max_seq_length, int
learning_rate, learning_rate, float
lr_scheduler_type, lr_scheduler_type, str
load_precision, precision_mode, str
train_precision, train_precision, str
gradient_checkpointing, enable_gradient_checkpointing, bool
example_packing, use_example_packing, bool
attn_implementation, attn_implementation, str
optimizer, optimizer, str
warmup_ratio, warmup_ratio, float
report_to, report_to, str
save_steps, save_steps, int
logging_steps, logging_steps, int
huggingface_access_token, huggingface_access_token, str
eval_dataset, eval_dataset_path, str
eval_instruct_column, eval_column, str
eval_template, eval_template, str
eval_split_name, eval_split, str
eval_steps, eval_steps, int
eval_tasks, eval_tasks, str
eval_metric_name, eval_metric_name, str
completion_only, completion_only, bool
max_grad_norm, max_grad_norm, float
logger_level, logger_level, str
benchmark_out_file, benchmark_out_file, str
tuning_data_stats_file, tuning_data_stats_file, str
enable_peft, enable_peft, bool
merge_model_precision_mode, merge_model_precision_mode, str
target_modules, target_modules, str
@@ -1,15 +0,0 @@
# api_name, impl_name, value_type
task, task, str
pretrained_model_id, pretrained_model_id, str
quantization_method, quantization_method, str
quantization_precision_mode, quantization_precision_mode, str
quantization_dataset_name, quantization_dataset_name, str
text_column_in_quantization_dataset, text_column_in_quantization_dataset, str
quantization_output_dir, quantization_output_dir, str
device_map, device_map, str
max_memory, max_memory, str
group_size, group_size, int
desc_act, desc_act, bool
damp_percent, damp_percent, float
cache_examples_on_gpu, cache_examples_on_gpu, bool
awq_version, awq_version, str
@@ -1,9 +0,0 @@
# api_name, impl_name, value_type
task, task, str
template, template, str
dataset_name, dataset_name, str
train_split_name, train_split_name, str
instruct_column_in_dataset, instruct_column_in_dataset, str
use_multiprocessing, use_multiprocessing, bool
validate_k_rows_of_dataset, validate_k_rows_of_dataset, int
validate_percentage_of_dataset, validate_percentage_of_dataset, int
@@ -0,0 +1,79 @@
"""Get cluster info from environment variables."""
import dataclasses
import json
import os
from absl import logging
@dataclasses.dataclass
class ClusterInfo:
"""Contains information about the cluster.
Attributes:
primary_node_addr: The address of the primary node.
primary_node_port: The port of the primary node.
node_rank: The rank of the node.
num_nodes: The number of nodes in the cluster.
"""
primary_node_addr: str | None = None
primary_node_port: str | None = None
node_rank: int = 0
num_nodes: int = 1
# Allows unpacking operation like
# primary_node_addr, primary_node_port, _, _ = ClusterInfo()
# See https://stackoverflow.com/a/70753113
def __iter__(self):
return iter(dataclasses.astuple(self))
def get_cluster_spec() -> ClusterInfo:
"""Parses CLUSTER_SPEC environment variable and returns the cluster info.
Returns:
A ClusterInfo object.
"""
cluster_spec = os.getenv('CLUSTER_SPEC', None)
# If CLUSTER_SPEC is not set, use individual vars to construct cluster info.
if not cluster_spec:
cluster_info = ClusterInfo(
primary_node_addr=os.getenv('MASTER_ADDR', None),
primary_node_port=os.getenv('MASTER_PORT', None),
node_rank=int(os.getenv('RANK', '0')),
num_nodes=int(os.getenv('NNODES', '1')),
)
return cluster_info
cluster_data = json.loads(cluster_spec)
# Get primary node info
primary_node = cluster_data['cluster']['workerpool0'][0]
logging.info('primary node: %s', primary_node)
primary_node_addr, primary_node_port = primary_node.split(':')
logging.info('primary node address: %s', primary_node_addr)
logging.info('primary node port: %s', primary_node_port)
# Determine node rank of this machine
workerpool = cluster_data['task']['type']
if workerpool == 'workerpool0':
node_rank = 0
elif workerpool == 'workerpool1':
# Add 1 for the primary node, since `index` is the index of workerpool1.
node_rank = cluster_data['task']['index'] + 1
else:
raise ValueError(
'Only workerpool0 and workerpool1 are supported. Unknown workerpool:'
f' {workerpool}'
)
logging.info('node rank: %s', node_rank)
# Calculate total nodes.
num_nodes = 1 # For the primary node.
if 'workerpool1' in cluster_data['cluster']:
num_nodes += len(cluster_data['cluster']['workerpool1'])
logging.info('num nodes: %s', num_nodes)
return ClusterInfo(primary_node_addr, primary_node_port, node_rank, num_nodes)
@@ -0,0 +1,24 @@
"""Utility functions."""
import logging
import subprocess
import sys
import time
def run_cmd(cmd: list[str]) -> float:
"""Runs the command and logs the output.
Args:
cmd: The command to run.
Returns:
The time it took to run the command.
"""
cmd_str = ' \\\n'.join(cmd)
logging.info('launching cmd: \n%s', cmd_str)
start_time = time.time()
subprocess.run(cmd, stdout=sys.stdout, stderr=sys.stdout, check=True)
elapsed_time = round(time.time() - start_time, 2)
logging.info('Command %s finished in %0.2f seconds.', cmd_str, elapsed_time)
return elapsed_time
@@ -0,0 +1,197 @@
"""Calculate dataset statistics like token, example and character counts."""
from collections.abc import Mapping, Sequence
import dataclasses
import json
from typing import Any
import datasets
import numpy as np
import transformers
from util import dataset_validation_util
_MAX_NUM_DATASET_SAMPLES = 6
@dataclasses.dataclass
class SupervisedTuningDatasetBucket:
"""Represents a histogram bucket for tuning dataset distribution stats."""
count: float = 0
left: float = 0
right: float = 0
@dataclasses.dataclass
class SupervisedTuningDatasetDistribution:
"""Represents a histogram with summary statistics for tuning dataset distribution stats."""
sum: int = 0
billable_sum: int = 0
min: float = 0
max: float = 0
mean: float = 0
median: float = 0
p5: float = 0
p95: float = 0
buckets: list[SupervisedTuningDatasetBucket] = dataclasses.field(
default_factory=list
)
# Represents detailed tuning dataset statistics.
@dataclasses.dataclass
class SupervisedTuningDataStats:
"""Represents detailed tuning dataset stats."""
tuning_dataset_example_count: int = 0
total_tuning_character_count: int = 0
total_billable_token_count: int = 0
tuning_step_count: int = 0
# Represents a histogram and some summary statistics of the number of input
# tokens across examples.
user_input_token_distribution: SupervisedTuningDatasetDistribution | None = (
None
)
# Represents a histogram and some summary statistics for the number of output
# tokens across examples.
user_output_token_distribution: SupervisedTuningDatasetDistribution | None = (
None
)
# Represents the number of "messages" (a single-turn conversation will have a
# single message) across examples.
user_message_per_example_distribution: (
SupervisedTuningDatasetDistribution | None
) = None
user_dataset_examples: list[str] = dataclasses.field(default_factory=list)
def get_dataset_stats(
*,
raw: Any,
templated: Any,
template: str,
tokenizer: transformers.PreTrainedTokenizer,
column: str,
effective_batch_size: int,
) -> Mapping[str, Any]:
"""Calculates dataset statistics for managed fine-tuning, e.g., total number of tokens."""
tokenized_dataset = templated.map(lambda x: tokenizer(x[column]))
inputs = tokenized_dataset["input_ids"]
tuning_dataset_example_count = int(len(inputs))
total_billable_token_count = int(np.sum([len(ex) for ex in inputs]))
total_tuning_character_count = int(
np.sum([len(ex[column]) for ex in templated])
)
tuning_step_count = (
tuning_dataset_example_count + effective_batch_size - 1
) // effective_batch_size
# Assume that data is represented as ChatCompletions or Vertex Text-Bison
# formats to extract per-example input/output tokens.
user_inputs = []
user_outputs = []
user_input_messages_counts = []
for ex in raw:
if "messages" in ex:
messages = ex["messages"]
if messages:
# For ChatCompletions assume the last turn (i.e. the instruction
# response) is the expected output.
user_inputs.append({**ex, "messages": messages[:-1]})
user_outputs.append({**ex, "messages": messages[-1:]})
# Exclude everything but the last message for the number of input
# messages.
user_input_messages_counts.append(len(messages[:-1]))
elif "input_text" in ex:
# For Vertex Text-Bison, the `output_text` field is the expected output.
user_inputs.append({**ex, "output_text": ""})
user_outputs.append(
{**ex, "input_text": ex["output_text"], "output_text": ""}
)
# Vertex Text-Bison goes from input -> output; i.e. there is only a single
# input "message".
user_input_messages_counts.append(1)
def calc_histogram(
counts: Sequence[int],
) -> SupervisedTuningDatasetDistribution:
mean = np.mean(counts)
median = np.median(counts).item()
max_count = np.max(counts).item()
min_count = np.min(counts).item()
count_sum = np.sum(counts).item()
p5 = np.percentile(counts, 0.05).item()
p95 = np.percentile(counts, 0.95).item()
hist, bin_edges = np.histogram(counts, bins=10)
return SupervisedTuningDatasetDistribution(
sum=count_sum,
billable_sum=count_sum,
min=min_count,
max=max_count,
mean=mean,
median=median,
p5=p5,
p95=p95,
buckets=[
SupervisedTuningDatasetBucket(
count=hist[i].item(),
left=bin_edges[i].item(),
right=bin_edges[i + 1].item(),
)
for i in range(len(hist))
],
)
# Tokenize input and output messages separately to generate separate summary
# statistics about them.
user_input_token_distribution = None
if user_inputs:
user_input_dataset = dataset_validation_util.format_dataset(
datasets.Dataset.from_list(user_inputs), column, template, tokenizer
)
user_input_tokenized_dataset = user_input_dataset.map(
lambda x: tokenizer(x[column])
)
user_input_tokens = user_input_tokenized_dataset["input_ids"]
user_input_token_counts = np.array([len(ex) for ex in user_input_tokens])
user_input_token_distribution = calc_histogram(user_input_token_counts)
user_output_token_distribution = None
if user_outputs:
user_output_dataset = dataset_validation_util.format_dataset(
datasets.Dataset.from_list(user_outputs), column, template, tokenizer
)
user_output_tokenized_dataset = user_output_dataset.map(
lambda x: tokenizer(x[column])
)
user_output_tokens = user_output_tokenized_dataset["input_ids"]
user_output_token_counts = np.array([len(ex) for ex in user_output_tokens])
user_output_token_distribution = calc_histogram(user_output_token_counts)
user_messages_per_example_distribution = None
if user_input_messages_counts:
user_input_messages_counts = np.array(user_input_messages_counts)
user_messages_per_example_distribution = calc_histogram(
user_input_messages_counts
)
user_dataset_examples = [
json.dumps(ex)
for ex in raw.shuffle().select(
range(min(len(raw), _MAX_NUM_DATASET_SAMPLES))
)
]
dataset_stats = SupervisedTuningDataStats(
tuning_dataset_example_count=tuning_dataset_example_count,
total_tuning_character_count=total_tuning_character_count,
total_billable_token_count=total_billable_token_count,
tuning_step_count=tuning_step_count,
user_input_token_distribution=user_input_token_distribution,
user_output_token_distribution=user_output_token_distribution,
user_message_per_example_distribution=user_messages_per_example_distribution,
user_dataset_examples=user_dataset_examples,
)
return dataclasses.asdict(dataset_stats)
@@ -0,0 +1,140 @@
"""Util functions for reporting device (GPU, CPU) stats."""
import dataclasses
import psutil
import pynvml
import torch
@dataclasses.dataclass
class GpuStats:
"""Holds information about GPU usage stats.
For memory related, see
https://pytorch.org/docs/stable/notes/cuda.html#cuda-memory-management
"""
# device id
device_id: int
# memory reserved.
reserved: float
# memory occupied.
occupied: float
# memory reserved, but not used.
unused: float
# nvidia-smi usually reports more memory usages than pytorch (for driver,
# kernel and etc). `smi_diff` tracks this difference.
smi_diff: float
# Gpu utilization.
util: float
# Allows unpacking operation like
# device_id, reserved, occupied, unused, smi_diff, util = GpuStats(...)
# See https://stackoverflow.com/a/70753113
def __iter__(self):
return iter(dataclasses.astuple(self))
def gpu_stats() -> GpuStats:
"""Reports GPU memory usage and utilization."""
# See https://pytorch.org/docs/stable/notes/cuda.html#memory-management
bytes_per_gb = 1024.0**3
device = torch.cuda.current_device()
occupied = torch.cuda.memory_allocated(device) / bytes_per_gb
reserved = torch.cuda.memory_reserved(device) / bytes_per_gb
unused = reserved - occupied
def smi_mem(device):
try:
pynvml.nvmlInit()
handle = pynvml.nvmlDeviceGetHandleByIndex(device)
info = pynvml.nvmlDeviceGetMemoryInfo(handle)
return info.used / bytes_per_gb
except pynvml.NVMLError:
return 0.0
mem_used_smi = smi_mem(device)
smi_diff = mem_used_smi - reserved
util = torch.cuda.utilization(device)
return GpuStats(device, reserved, occupied, unused, smi_diff, util)
def gpu_stats_str(stats: GpuStats | None = None) -> str:
if stats is None:
stats = gpu_stats()
device, reserved, occupied, unused, smi_diff, util = stats
return (
f"GPU ({device=}) memory: {reserved:.2f}({occupied=:.2f}, {unused=:.2f}),"
f" {smi_diff=:.2f} GB. Utilization: {util:.2f}%"
)
@dataclasses.dataclass
class CpuStats:
"""Holds information about CPU usage stats."""
# Total CPU virtual memory i.e. virtual memory allocated + unallocated.
total_virtual_mem: float
# CPU virtual memory available for use.
unallocated_virtual_mem: float
# CPU virtual memory already used.
allocated_virtual_mem: float
# Total CPU swap memory i.e. swap memory allocated + unallocated.
total_swap_mem: float
# CPU swap memory available for use.
unallocated_swap_mem: float
# CPU swap memory already used.
allocated_swap_mem: float
# CPU utilization percentage.
utilization: float
def cpu_stats() -> CpuStats:
"""Reports CPU memory usage and utilization."""
# https://psutil.readthedocs.io/en/latest/#memory
gb = 1024.0**3
vmem = psutil.virtual_memory()
vmem_total = vmem.total / gb
vmem_available = vmem.available / gb
vmem_used = vmem_total - vmem_available
smem = psutil.swap_memory()
swap_total = smem.total / gb
swap_free = smem.free / gb
swap_used = smem.used / gb
# https://psutil.readthedocs.io/en/latest/#psutil.cpu_percent
cpu_util = psutil.cpu_percent(interval=1e-6)
return CpuStats(
total_virtual_mem=vmem_total,
unallocated_virtual_mem=vmem_available,
allocated_virtual_mem=vmem_used,
total_swap_mem=swap_total,
unallocated_swap_mem=swap_free,
allocated_swap_mem=swap_used,
utilization=cpu_util,
)
def cpu_stats_str(stats: CpuStats | None = None) -> str:
"""Returns a string representation of the CPU stats."""
if stats is None:
stats = cpu_stats()
total, occupied, unused = (
stats.total_virtual_mem,
stats.allocated_virtual_mem,
stats.unallocated_virtual_mem,
)
virtual_mem = (
f"CPU virtual memory: {total:.2f}({occupied=:.2f}, {unused=:.2f}) GB"
)
total, occupied, unused = (
stats.total_swap_mem,
stats.allocated_swap_mem,
stats.unallocated_swap_mem,
)
swap_mem = f"CPU swap memory: {total:.2f}({occupied=:.2f}, {unused=:.2f}) GB"
percent = stats.utilization
return f"{virtual_mem} {swap_mem} CPU Utilization: {percent:.2f}%"
@@ -1,5 +1,7 @@
"""Different trainer callbacks for PEFT Trainer."""
from collections.abc import MutableMapping
import math
import time
from absl import logging
@@ -9,7 +11,7 @@ from transformers.trainer_callback import TrainerCallback
from transformers.trainer_callback import TrainerControl
from transformers.trainer_callback import TrainerState
from vertex_vision_model_garden_peft.train.vmg import utils
from util import device_stats
class TrainerStatsCallback(TrainerCallback):
@@ -25,6 +27,30 @@ class TrainerStatsCallback(TrainerCallback):
self._peak_mem = 0.0
self._avg_throughput = 0.0
def on_log(
self,
args: TrainingArguments,
state: TrainerState,
control: TrainerControl,
logs: MutableMapping[str, float] | None = None,
**kwargs,
) -> None:
"""Calculates perplexity from train loss.
Args:
args: Arguments passed to the trainer.
state: State of the trainer.
control: Control of the trainer.
logs: A dict of logs from the training loop.
**kwargs: Additional keyword arguments, not used in this callback.
"""
del kwargs # Unused.
if self._partial_state.is_main_process:
train_loss = logs.get('loss') if logs is not None else None
if train_loss is not None:
perplexity = round(float(math.exp(train_loss)), 4)
logs['perplexity'] = perplexity
def on_step_end(
self,
args: TrainingArguments,
@@ -35,21 +61,29 @@ class TrainerStatsCallback(TrainerCallback):
if self._partial_state.is_main_process:
if state.global_step == 1:
self._prev_time = time.time()
delta_t = float('nan')
self._prev_num_token = state.num_input_tokens_seen
throughput = 0.0
else:
cur_time = time.time()
delta_t = cur_time - self._prev_time
cur_num_token = state.num_input_tokens_seen
throughput = (cur_num_token - self._prev_num_token) / (
cur_time - self._prev_time
)
self._prev_time = cur_time
self._avg_throughput += (delta_t - self._avg_throughput) / (
self._prev_num_token = cur_num_token
self._avg_throughput += (throughput - self._avg_throughput) / (
state.global_step - 1
)
gpu_stats = utils.gpu_stats()
self._peak_mem = max(gpu_stats.total_mem, self._peak_mem)
gpu_stats = device_stats.gpu_stats()
self._peak_mem = max(
gpu_stats.reserved + gpu_stats.smi_diff, self._peak_mem
)
logging.info(
'on_step_end: %s, throughput: %.2f s/it',
utils.gpu_stats_str(gpu_stats),
delta_t,
'on_step_end: Throughput: %.2f token/s. %s, %s',
throughput,
device_stats.gpu_stats_str(gpu_stats),
device_stats.cpu_stats_str(),
)
def on_train_begin(
@@ -61,7 +95,11 @@ class TrainerStatsCallback(TrainerCallback):
):
if self._partial_state.is_main_process:
self._start_time = time.time()
logging.info('on_train_begin: %s', utils.gpu_stats_str())
logging.info(
'on_train_begin: %s, %s',
device_stats.gpu_stats_str(),
device_stats.cpu_stats_str(),
)
def on_train_end(
self,
@@ -72,15 +110,17 @@ class TrainerStatsCallback(TrainerCallback):
):
if self._partial_state.is_main_process:
train_time = time.time() - self._start_time
throughput = state.num_input_tokens_seen / train_time
logging.info(
'training time %.2f s, throughput: %.2f s/it, peak_mem: %.2f GB',
'training time %.2f s, throughput (including overhead, e.g., ckpt'
' saving): %.2f token/s, peak_mem: %.2f GB',
train_time,
self._avg_throughput,
throughput,
self._peak_mem,
)
if self._filename:
with open(self._filename, 'a') as out_f:
out_f.write(
f'{self._max_seq_length/1024.0:.1f}k | {self._peak_mem:.2f} |'
f'{self._max_seq_length/1024.0:.1f} | {self._peak_mem:.2f} |'
f' {self._avg_throughput:.2f}\n'
)
@@ -0,0 +1,28 @@
compute_environment: LOCAL_MACHINE
debug: false
distributed_type: FSDP
downcast_bf16: 'no'
enable_cpu_affinity: false
fsdp_config:
fsdp_auto_wrap_policy: TRANSFORMER_BASED_WRAP
fsdp_transformer_layer_cls_to_wrap: Gemma2DecoderLayer
fsdp_backward_prefetch: NO_PREFETCH
fsdp_cpu_ram_efficient_loading: true
fsdp_forward_prefetch: false
fsdp_offload_params: true
fsdp_sharding_strategy: FULL_SHARD
fsdp_state_dict_type: SHARDED_STATE_DICT
fsdp_sync_module_states: true
fsdp_use_orig_params: false
fsdp_activation_checkpointing: false
main_training_function: main
mixed_precision: bf16
machine_rank: 0
num_machines: 1
num_processes: 8
rdzv_backend: static
same_network: true
tpu_env: []
tpu_use_cluster: false
tpu_use_sudo: false
use_cpu: false
@@ -0,0 +1,28 @@
compute_environment: LOCAL_MACHINE
debug: false
distributed_type: FSDP
downcast_bf16: 'no'
enable_cpu_affinity: false
fsdp_config:
fsdp_auto_wrap_policy: TRANSFORMER_BASED_WRAP
fsdp_transformer_layer_cls_to_wrap: Qwen2DecoderLayer
fsdp_backward_prefetch: NO_PREFETCH
fsdp_cpu_ram_efficient_loading: true
fsdp_forward_prefetch: false
fsdp_offload_params: true
fsdp_sharding_strategy: FULL_SHARD
fsdp_state_dict_type: SHARDED_STATE_DICT
fsdp_sync_module_states: true
fsdp_use_orig_params: false
fsdp_activation_checkpointing: false
main_training_function: main
mixed_precision: bf16
machine_rank: 0
num_machines: 1
num_processes: 8
rdzv_backend: static
same_network: true
tpu_env: []
tpu_use_cluster: false
tpu_use_sudo: false
use_cpu: false
@@ -31,7 +31,7 @@ dependencies:
- pip:
- --extra-index-url https://download.pytorch.org/whl/cu121
- absl-py==2.1.0
- accelerate==0.33.0 # Needed for fp8
- accelerate==0.34.2 # Needed for fp8
- datasets==2.19.2
- fbgemm-gpu==0.8.0+cu121 # Needed for fp8
- kfp==2.5.0
@@ -39,5 +39,5 @@ dependencies:
- protobuf==3.20.3
- pynvml==11.5.3
- torch==2.4.0+cu121 # Needed for fp8
- transformers==4.43.1
- trl==0.9.6
- transformers==4.47.1
- trl==0.11.2
@@ -5,23 +5,28 @@
--extra-index-url https://huggingface.github.io/autogptq-index/whl/cu118/
# keep sorted
accelerate==0.31.0
accelerate==0.34.2
auto_gptq==0.7.1+cu118
autoawq==0.2.5
autoawq==0.2.8
bitsandbytes==0.43.2
cloudml-hypertune==0.1.0.dev6
datasets==2.19.2
deepspeed==0.14.4
datasets==2.20.0
deepspeed==0.15.2
diffusers==0.25.1
evaluate==0.4.3
fsspec==2024.3.1
gcsfs==2024.3.1
lm_eval==0.4.3
immutabledict==4.2.1
ninja==1.11.1 # Needed to avoid `ninja 1.11.1.1 is not supported on this platform` error
nltk==3.9.1
optimum==1.17.1
peft==0.12.0
pynvml==11.5.3
rouge_score==0.1.2
torch==2.2.2+cu118
torchvision==0.17.2+cu118
transformers==4.43.1
trl==0.9.6
transformers==4.47.1
trl==0.11.2
wandb==0.17.1
ydata-profiling==4.7.0 # Upgrade the version from 4.6.0 to 4.7.0 to fix the old `pydantic` package error.
psutil==6.0.0
@@ -23,6 +23,14 @@ RUN wget https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples
ENV PIP_ROOT_USER_ACTION=ignore
RUN pip install --upgrade pip
# Remove packages that are not needed and are causing conflicts.
# dataproc_jupyter_plugin was installed as a part of pytorch-cu121.2-2.py310
# container which we don't need. It depends on ibis-framework and bigframes.
# The package and its dependencies request lower versions of pyarrow/pydantic
# than deepspeed/datasets. So, dataproc_jupyter_plugin conflicts with
# deepspeed/datasets.
RUN pip uninstall -y dataproc_jupyter_plugin ibis-framework bigframes
# Prefer to install with requirement file as much as possible for reasons
# described in b/355034754.
COPY model_oss/peft/train/vmg/dockerfile/requirements.txt /tmp/requirements.txt
@@ -58,15 +66,14 @@ WORKDIR /diffusers/examples
RUN mkdir -p ./vertex_vision_model_garden_peft/
COPY model_oss/peft/train/vmg/configs/* ./vertex_vision_model_garden_peft/
# custom `lm_eval` task.
ARG LM_EVAL_DIR=$(python -c 'import site; print(site.getsitepackages()[0])')/lm_eval
RUN mkdir -p $LM_EVAL_DIR/tasks/vertex && \
mv ./vertex_vision_model_garden_peft/custom_loglikelihood.yaml $LM_EVAL_DIR/tasks/vertex/
COPY model_oss/peft/train/vmg/*.py ./vertex_vision_model_garden_peft/train/vmg/
COPY model_oss/peft/train/vmg/templates /diffusers/examples/util/templates
COPY model_oss/util /diffusers/examples/util
COPY model_oss/peft/train/util/*.py /diffusers/examples/util/
COPY model_oss/util/* /diffusers/examples/util/
COPY model_oss/notebook_util/dataset_validation_util.py /diffusers/examples/util
COPY model_oss/peft/train/tests/*.py ./vertex_vision_model_garden_peft/tests/
COPY model_oss/peft/train/vmg/tests/*.py ./vertex_vision_model_garden_peft/tests/
COPY model_oss/peft/train/test_utils/test_util.py ./vertex_vision_model_garden_peft/tests/
COPY model_oss/peft/train/test_utils/command_builder.py ./vertex_vision_model_garden_peft/tests/
RUN chmod a+rwX -R /diffusers/examples/
ENV PYTHONPATH /diffusers/examples/
@@ -1,183 +1,284 @@
"""Library for running evaluations during training."""
from collections.abc import Callable, Mapping, MutableMapping, Sequence
import dataclasses
from typing import Any, Optional, Type
import string
from typing import Type
from absl import logging
import datasets
from lm_eval import evaluator
from lm_eval import tasks
from lm_eval import utils
from lm_eval.api import model as lm_model
from lm_eval.api import registry
from lm_eval.models import huggingface
from peft import peft_model
import evaluate
import numpy as np
import torch
import transformers
from transformers import trainer
from util import dataset_validation_util
from util import constants
_DESCRIPTION_EVALUATION = "evaluation"
_BUILTIN_EVAL_TASK = "builtin_eval"
_STRING_TRANSLATOR = str.maketrans("", "", string.punctuation)
_GREATER_IS_BETTER_MAP = {
"loss": False,
"perplexity": False,
"bleu": True,
"google_bleu": True,
"rouge1": True,
"rouge2": True,
"rougeL": True,
"rougeLsum": True,
}
@dataclasses.dataclass(frozen=True)
class EvalConfig:
"""Configuration for running evaluations during training.
Attributes:
steps: The number of steps to run evaluation.
tasks: The list of tasks to run evaluation on.
per_device_batch_size: The per device batch size for evaluation.
limit: The maximum number of examples to evaluate.
metric_name: The name of the metric to compute.
tokenize_dataset: Whether to tokenize the dataset.
dataset_path: The path to the dataset.
split: The split of the dataset to evaluate.
template: The template to use for the dataset.
column: The column name of the dataset.
metric_for_best_model: The metric to use for loading the best model.
"""
steps: int
tasks: list[str]
per_device_batch_size: int
num_fewshot: Optional[int]
limit: Optional[float]
metric_name: str
limit: float | None
metric_name: Sequence[str]
tokenize_dataset: bool
dataset_path: str = ""
split: str = "test"
template: str = ""
column: str = constants.DEFAULT_INSTRUCT_COLUMN_IN_DATASET
class PeftCausalLMModel(huggingface.HFLM):
"""PeftCausalLMModel that supports loading an in-memory model."""
AUTO_MODEL_CLASS = transformers.AutoModelForCausalLM
def __init__(
self,
model: peft_model.PeftModelForCausalLM,
tokenizer: transformers.PreTrainedTokenizerBase,
batch_size_per_gpu: int,
):
lm_model.LM.__init__(self)
self._model = model
self.tokenizer = tokenizer
self.vocab_size = tokenizer.vocab_size
tokenizer.pad_token_id = tokenizer.eos_token_id
self._config = model.config
self.batch_size_per_gpu = batch_size_per_gpu
self._device = model.device
self._max_length = None # Will be automatically determined from config.
self._add_special_tokens = (
None # Will be automatically determined from AUTO_MODEL_CLASS.
)
column: str = constants.DEFAULT_TRAIN_COLUMN
metric_for_best_model: str | None = None
def create_trainer(
cls: Type[transformers.Trainer],
eval_config: Optional[EvalConfig],
tokenizer: Optional[transformers.PreTrainedTokenizerBase],
args: trainer.TrainingArguments,
eval_config: EvalConfig | None,
tokenizer: transformers.PreTrainedTokenizerBase | None,
args: transformers.TrainingArguments,
**kwargs,
) -> transformers.Trainer:
"""Creates a trainer. If eval config is provided, injects evaluation loop."""
"""Creates a trainer. If eval config is provided, injects evaluation loop.
Args:
cls: The trainer class.
eval_config: The evaluation config.
tokenizer: The tokenizer.
args: The training arguments.
**kwargs: The keyword arguments.
Returns:
A trainer.
"""
if not eval_config:
return cls(args=args, **kwargs)
args.eval_strategy = "steps"
args.eval_steps = eval_config.steps
args.per_device_eval_batch_size = eval_config.per_device_batch_size
args.metric_for_best_model = eval_config.metric_for_best_model
args.greater_is_better = _GREATER_IS_BETTER_MAP.get(
eval_config.metric_for_best_model, None
)
args.save_strategy = (
transformers.trainer_utils.SaveStrategy.STEPS
if eval_config.metric_for_best_model is None
else transformers.trainer_utils.SaveStrategy.BEST
)
kwargs["tokenizer"] = tokenizer
if eval_config.tasks == [_BUILTIN_EVAL_TASK]:
try:
eval_dataset = dataset_validation_util.load_dataset_with_template(
dataset_name=eval_config.dataset_path,
split=eval_config.split,
try:
_, eval_dataset = dataset_validation_util.load_dataset_with_template(
dataset_name=eval_config.dataset_path,
split=eval_config.split,
input_column=eval_config.column,
template=eval_config.template,
tokenizer=tokenizer,
)
if eval_config.limit is not None:
if eval_config.limit >= 1:
limit = int(eval_config.limit)
else:
limit = int(eval_config.limit * len(eval_dataset))
eval_dataset = eval_dataset.select(range(limit))
if tokenizer is not None:
eval_dataset = dataset_validation_util.get_filtered_dataset(
dataset=eval_dataset,
input_column=eval_config.column,
template=eval_config.template,
max_seq_length=kwargs["max_seq_length"],
tokenizer=tokenizer,
)
if eval_config.limit is not None:
if eval_config.limit >= 1:
limit = int(eval_config.limit)
else:
limit = int(eval_config.limit * len(eval_dataset))
eval_dataset = eval_dataset.select(range(limit))
if eval_config.tokenize_dataset:
eval_dataset = eval_dataset.map(
lambda samples: tokenizer(samples[eval_config.column])
)
kwargs["eval_dataset"] = eval_dataset
except (OSError, ValueError, IndexError) as e:
logging.warning(
"Failed to load eval dataset %s. Evaluation will be skipped.\n%s",
eval_config.dataset_path,
e,
if eval_config.tokenize_dataset:
eval_dataset = eval_dataset.map(
lambda samples: tokenizer(samples[eval_config.column])
)
del args.evaluation_strategy
del args.eval_steps
del args.per_device_eval_batch_size
return cls(args=args, **kwargs)
kwargs["eval_dataset"] = eval_dataset
except (OSError, ValueError, IndexError) as e:
logging.warning(
"Failed to load eval dataset %s. Evaluation will be skipped.\n%s",
eval_config.dataset_path,
e,
)
del args.evaluation_strategy
del args.eval_steps
del args.per_device_eval_batch_size
return cls(args=args, **kwargs)
class LMEvalTrainer(cls):
"""Trainer with lm_eval injected as the eval library."""
def __init__(self, **kwargs):
super().__init__(**kwargs)
task_names = utils.pattern_match(eval_config.tasks, registry.ALL_TASKS)
logging.info("Selected Eval Tasks: %s", task_names)
task_args = {}
if eval_config.num_fewshot is not None:
task_args["num_fewshot"] = eval_config.num_fewshot
if eval_config.dataset_path:
task_args["dataset_path"] = "json"
task_args["dataset_kwargs"] = {
"data_files": {"test": eval_config.dataset_path},
}
self._eval_task_dict = tasks.get_task_dict(task_names, **task_args)
def _cleanup_text(text: str) -> str:
"""Cleans up the prediction and references text.
def evaluation_loop(
self,
dataloader: trainer.DataLoader,
description: str,
prediction_loss_only: Optional[bool] = None,
ignore_keys: Optional[list[str]] = None,
metric_key_prefix: str = "eval",
) -> trainer.EvalLoopOutput:
"""Custom evaluation loop that invokes lm_eval."""
if description.lower() != _DESCRIPTION_EVALUATION:
return super().evaluation_loop(
dataloader,
description,
prediction_loss_only,
ignore_keys,
metric_key_prefix,
)
Args:
text: The text to clean up.
model = self._wrap_model(self.model, training=False)
lm = PeftCausalLMModel(
model,
self.tokenizer or self.data_collator.tokenizer,
eval_config.per_device_batch_size,
)
results: dict[str, Any] = evaluator.evaluate(
lm=lm,
task_dict=self._eval_task_dict,
limit=eval_config.limit,
)["results"]
metric_name = eval_config.metric_name
# Compute average value if there are multiple tasks.
metric_values: list[float] = []
for result in results.values():
for key, value in result.items():
if key.split(",")[0] == metric_name:
metric_values.append(value)
if not metric_values:
raise ValueError(
f"Metric {metric_name} not found in eval response: {results}"
)
metric_average = sum(metric_values) / len(metric_values)
logging.info("%s value: %f\n%s", metric_name, metric_average, results)
return trainer.EvalLoopOutput(
# Only metrics field is set. Other fields are dummy values.
predictions=None,
label_ids=None,
metrics={f"{metric_key_prefix}_{metric_name}": metric_average},
num_samples=0,
)
Returns:
Cleaned up text.
"""
text = text.translate(_STRING_TRANSLATOR)
text = text.strip()
text = " ".join(text.split())
return text.lower()
# Use empty eval dataset as a placeholder.
return LMEvalTrainer(
args=args, eval_dataset=datasets.Dataset.from_dict({"test": []}), **kwargs
def create_compute_metrics(
tokenizer: transformers.PreTrainedTokenizerBase,
eval_metrics: Mapping[str, evaluate.EvaluationModule],
) -> Callable[[transformers.EvalPrediction], MutableMapping[str, float]]:
"""Creates a compute_metrics function using Hugging Face evaluate library.
Args:
tokenizer: The tokenizer for decoding predictions.
eval_metrics: The eval metrics to compute.
Returns:
Function that computes comprehensive metrics.
"""
def _preprocess_data(
predictions: np.ndarray, labels: np.ndarray
) -> tuple[Sequence[str], Sequence[str]]:
"""Preprocesses predictions and lavels before evaluation.
Args:
predictions: The predictions to preprocess.
labels: The labels to preprocess.
Returns:
A tuple (preprocessed predictions, labels).
"""
# Handle padding and special tokens.
predictions = np.where(
predictions != -100, predictions, tokenizer.pad_token_id
)
labels = np.where(labels != -100, labels, tokenizer.pad_token_id)
# Decode to text.
pred_texts = tokenizer.batch_decode(predictions, skip_special_tokens=True)
label_texts = tokenizer.batch_decode(labels, skip_special_tokens=True)
# Clean up text.
cleaned_pred_texts = [_cleanup_text(text) for text in pred_texts]
cleaned_label_texts = [_cleanup_text(text) for text in label_texts]
return cleaned_pred_texts, cleaned_label_texts
def _compute_metrics_with_tokenizer(
eval_pred: transformers.EvalPrediction,
) -> MutableMapping[str, float]:
"""Computes metrics using Hugging Face evaluate library.
Args:
eval_pred: The evaluation prediction.
Returns:
A dictionary of metrics.
"""
predictions, perplexities = eval_pred.predictions
labels = eval_pred.label_ids
pred_texts, label_texts = _preprocess_data(predictions, labels)
metrics = {}
for eval_metric, computed_eval_metric in eval_metrics.items():
match eval_metric:
case "perplexity":
# We don't use the perplexity from HF Evaluate since it loads the
# model again. This causes an increase in the GPU utilization and
# hence an OOM. Due to this, we compute the perplexity ourselves
# using the eval_loss over the unmasked tokens in
# preprocess_logits_for_metrics fn.
metrics[eval_metric] = np.mean(perplexities)
case "bleu" | "google_bleu":
num_valid_labels = len(list(filter(None, label_texts)))
if num_valid_labels:
eval_score = computed_eval_metric.compute(
predictions=pred_texts,
references=[[text] for text in label_texts],
)
metrics[eval_metric] = eval_score[eval_metric]
else:
metrics[eval_metric] = 0.0
case "rouge1" | "rouge2" | "rougeL" | "rougeLsum":
rouge_scores = computed_eval_metric.compute(
predictions=pred_texts,
references=label_texts,
use_stemmer=True,
)
metrics[eval_metric] = rouge_scores[eval_metric]
pred_lengths = [len(pred.split()) for pred in pred_texts]
label_lengths = [len(label.split()) for label in label_texts]
metrics["gen_len"] = np.mean(pred_lengths)
metrics["ref_len"] = np.mean(label_lengths)
metrics["length_ratio"] = np.mean(
[len(p) / len(r) if r else 0 for p, r in zip(pred_texts, label_texts)]
)
# Round all metrics to 4 decimal places.
return {k: round(float(v), 4) for k, v in metrics.items()}
return _compute_metrics_with_tokenizer
def preprocess_logits_for_metrics(
logits: torch.Tensor, labels: torch.Tensor
) -> tuple[torch.Tensor, torch.Tensor]:
"""Preprocesses the logits before caching them for eval metric calculation.
Args:
logits: Logits predicted by the model.
labels: Ground truth labels.
Returns:
A tuple (pred_ids, perplexities).
"""
# Calculate prediction IDs.
pred_ids = logits.argmax(dim=-1)
# This step shifts the logits and labels to align them correctly, where we are
# predicting the next token in a sequence. The last logit doesn't have a
# corresponding label, and the first label doesn't have a preceding logit to
# predict it. This calculation of perplexity is inspired from
# https://github.com/huggingface/evaluate/blob/main/metrics/perplexity/perplexity.py.
shift_logits = logits[..., :-1, :].contiguous()
shift_labels = labels[..., 1:].contiguous()
attn_mask = shift_labels != -100
loss_fct = torch.nn.CrossEntropyLoss(reduction="none")
perplexities = torch.exp(
(loss_fct(shift_logits.transpose(1, 2), shift_labels) * attn_mask).sum(1)
/ attn_mask.sum(1)
)
return (pred_ids, perplexities)
@@ -1,10 +1,10 @@
"""Instruct/Chat with LoRA models."""
import dataclasses
from collections.abc import Callable, Mapping, Sequence
import datetime
import json
import os
from typing import Any, Dict, Optional, Sequence
from typing import Any
import warnings
from absl import app
@@ -13,17 +13,17 @@ from absl import logging
from accelerate import DistributedType
from accelerate import PartialState
import bitsandbytes as bnb
import hypertune
import evaluate
from peft import get_peft_model
from peft import LoraConfig
import torch
from transformers import AutoModelForCausalLM
from transformers import TrainingArguments
from trl import DataCollatorForCompletionOnlyLM
from trl import SFTTrainer
import transformers
import trl
import wandb
from util import dataset_validation_util
from util import dataset_stats
from util import device_stats
from vertex_vision_model_garden_peft.train.vmg import callbacks
from vertex_vision_model_garden_peft.train.vmg import eval_lib
from vertex_vision_model_garden_peft.train.vmg import utils
@@ -31,14 +31,15 @@ from util import constants
from util import fileutils
_PRETRAINED_MODEL_ID = flags.DEFINE_string(
'pretrained_model_id',
_PRETRAINED_MODEL_NAME_OR_PATH = flags.DEFINE_string(
'pretrained_model_name_or_path',
None,
'The pretrained model id. Supported models can be causal language modeling'
' models from https://github.com/huggingface/peft/tree/main. Note, there'
' might be different paddings for different models. This tool assumes the'
' pretrained_model_id contains model name, and then choose proper padding'
' methods. e.g. it must contain `llama` for `Llama2 models`.',
'The pretrained model name or path. Supported models can be causal language'
' modeling models from https://github.com/huggingface/peft/tree/main. Note,'
' there might be different paddings for different models. This tool assumes'
' the pretrained_model_name_or_path contains model name, and then choose'
' proper padding methods. e.g. it must contain `llama` for `Llama2'
' models`.',
required=True,
)
@@ -48,10 +49,10 @@ _HUGGINGFACE_ACCESS_TOKEN = flags.DEFINE_string(
'The access token for loading huggingface gated models.',
)
_DATASET_NAME = flags.DEFINE_string(
'dataset_name',
_TRAIN_DATASET = flags.DEFINE_string(
'train_dataset',
None,
'The dataset name in huggingface.',
'The training dataset name in huggingface or path.',
)
_OUTPUT_DIR = flags.DEFINE_string(
@@ -119,8 +120,8 @@ _WEIGHT_DECAY = flags.DEFINE_float(
'The weight decay in the learning rate scheduler.',
)
_NUM_EPOCHS = flags.DEFINE_float(
'num_epochs',
_NUM_TRAIN_EPOCHS = flags.DEFINE_float(
'num_train_epochs',
None,
'The number of training epochs. Only used for'
' "sequence-classification-lora" with an integer value and for'
@@ -130,8 +131,8 @@ _NUM_EPOCHS = flags.DEFINE_float(
_MAX_STEPS = flags.DEFINE_integer(
'max_steps',
None,
'Total number of training steps. Overrides num_epochs if set. Only used for'
' "instruct-lora."',
'Total number of training steps. Overrides num_train_epochs if set. Only'
' used for "instruct-lora."',
)
_MAX_SEQ_LENGTH = flags.DEFINE_integer(
@@ -146,9 +147,9 @@ _LEARNING_RATE = flags.DEFINE_float(
'The learning rate after the potential warmup period.',
)
_INSTRUCT_COLUMN_IN_DATASET = flags.DEFINE_string(
'instruct_column_in_dataset',
constants.DEFAULT_INSTRUCT_COLUMN_IN_DATASET,
_TRAIN_COLUMN = flags.DEFINE_string(
'train_column',
constants.DEFAULT_TRAIN_COLUMN,
'The instruct column in dataset.',
)
@@ -170,8 +171,8 @@ _GRADIENT_ACCUMULATION_STEPS = flags.DEFINE_integer(
'The gradient accumulation steps.',
)
_ENABLE_GRADIENT_CHECKPOINTING = flags.DEFINE_boolean(
'enable_gradient_checkpointing',
_GRADIENT_CHECKPOINTING = flags.DEFINE_boolean(
'gradient_checkpointing',
False,
'Whether to enable gradient checkpointing.',
)
@@ -181,8 +182,8 @@ _ENABLE_PEFT = flags.DEFINE_boolean(
True,
'Whether to enable peft.',
)
_TEMPLATE = flags.DEFINE_string(
'template',
_TRAIN_TEMPLATE = flags.DEFINE_string(
'train_template',
None,
'Template for formatting language model training data. Must be a filename'
' under `templates` folder, without `.json` extension, e.g. `alpaca`, or a'
@@ -219,32 +220,18 @@ _EVAL_STEPS = flags.DEFINE_integer(
'The number of training steps between evaluations.',
)
_TRAIN_SPLIT_NAME = flags.DEFINE_string(
'train_split_name',
_TRAIN_SPLIT = flags.DEFINE_string(
'train_split',
'train',
'The train split name.',
)
_EVAL_TASKS = flags.DEFINE_list(
'eval_tasks',
None,
'List of eval task names (can have wildcards) as in'
' https://github.com/EleutherAI/lm-evaluation-harness. Will not run'
' evaluation if not set. Runs the built-in trainer evaluation loop if set'
' to `builtin_eval`.',
)
_EVAL_PER_DEVICE_BATCH_SIZE = flags.DEFINE_integer(
'eval_per_device_batch_size',
_PER_DEVICE_EVAL_BATCH_SIZE = flags.DEFINE_integer(
'per_device_eval_batch_size',
1,
'The per device batch size for model evaluation.',
)
_EVAL_NUM_FEWSHOT = flags.DEFINE_integer(
'eval_num_fewshot',
None,
'Run N-shot language model evaluation. Not implemented in `builtin_eval`.',
)
_EVAL_LIMIT = flags.DEFINE_float(
'eval_limit',
@@ -253,17 +240,18 @@ _EVAL_LIMIT = flags.DEFINE_float(
' total number of examples.',
)
_EVAL_METRIC_NAME = flags.DEFINE_string(
_EVAL_METRIC_NAME = flags.DEFINE_list(
'eval_metric_name',
'acc',
'The metric name to aggregate during model evaluation.',
['loss'],
'A comma-separated list of metric names to aggregate during model'
' evaluation. The supported metrics are: '
+ ', '.join(constants.SUPPORTED_EVAL_METRICS),
)
_EVAL_DATASET_PATH = flags.DEFINE_string(
'eval_dataset_path',
_EVAL_DATASET = flags.DEFINE_string(
'eval_dataset',
None,
'Overrides the default evaluation dataset path. In `builtin_eval` mode,'
' this can be any Hugging Face dataset name.',
'The Hugging Face dataset name or path to use for evaluation.',
)
# We set the default eval split as `test`, based on observation from
@@ -271,13 +259,13 @@ _EVAL_DATASET_PATH = flags.DEFINE_string(
_EVAL_SPLIT = flags.DEFINE_string(
'eval_split',
'test',
'Eval split name in the eval dataset for `builtin_eval`.',
'Eval split name in the eval dataset.',
)
_EVAL_TEMPLATE = flags.DEFINE_string(
'eval_template',
None,
'Template for formatting language model evaluation data for `builtin_eval`.'
'Template for formatting language model evaluation data.'
' Must be a filename under `templates` folder, without `.json` extension,'
' e.g. `alpaca`, or a Cloud Storage URI to a JSON file.',
)
@@ -285,7 +273,14 @@ _EVAL_TEMPLATE = flags.DEFINE_string(
_EVAL_COLUMN = flags.DEFINE_string(
'eval_column',
None,
'Eval column name in the eval dataset for `builtin_eval`.',
'Eval column name in the eval dataset.',
)
_METRIC_FOR_BEST_MODEL = flags.DEFINE_string(
'metric_for_best_model',
None,
'If set, the best model is saved at the end of training based on the'
' metric',
)
_TRAIN_PRECISION = flags.DEFINE_enum(
@@ -299,15 +294,15 @@ _TRAIN_PRECISION = flags.DEFINE_enum(
'Precision to train the model.',
)
_USE_EXAMPLE_PACKING = flags.DEFINE_boolean(
'use_example_packing',
_EXAMPLE_PACKING = flags.DEFINE_boolean(
'example_packing',
False,
'Enables example packing during training, which uses '
'`ConstantLengthDataset` under the hood.',
)
_COMPLETION_ONLY = flags.DEFINE_boolean(
'completion_only',
_INPUT_MASKING = flags.DEFINE_boolean(
'input_masking',
False,
'If set, it uses DataCollatorForCompletionOnlyLM to train the model on the'
' generated prompts only, i.e., masking out the input',
@@ -356,28 +351,53 @@ _TARGET_MODULES = flags.DEFINE_list(
'target_modules', None, 'The names of the modules to apply LoRA adapter to.'
)
_MAX_GPU_MEMORY_FRACTION = flags.DEFINE_float(
'max_gpu_memory_fraction',
'0.9',
'Maximum GPU memory a caching allocator is allowed to use per GPU.',
)
@flags.multi_flags_validator(
[
_COMPLETION_ONLY.name,
_USE_EXAMPLE_PACKING.name,
_INPUT_MASKING.name,
_EXAMPLE_PACKING.name,
],
message=(
'`use_example_packing=True` does not work with `completion_only=True`'
),
message='`example_packing=True` does not work with `input_masking=True`',
)
def check_example_packing(flags_dict: Dict[str, Any]) -> bool:
def check_example_packing(flags_dict: Mapping[str, Any]) -> bool:
"""Check to make sure example packing is enabled properly.
Args:
flags_dict: Dictionary containing flags to check.
Returns:
If `use_example_packing` is set properly.
If `example_packing` is set properly.
"""
if flags_dict[_INPUT_MASKING.name] and flags_dict[_EXAMPLE_PACKING.name]:
return False
return True
@flags.multi_flags_validator(
[
_INPUT_MASKING.name,
_TRAIN_TEMPLATE.name,
],
message='`train_template` should be provided if using `input_masking=True`',
)
def check_input_masking(flags_dict: Mapping[str, Any]) -> bool:
"""Check to make sure input_masking is enabled properly.
Args:
flags_dict: Dictionary containing flags to check.
Returns:
If `input_masking` is set properly
"""
if (
flags_dict[_COMPLETION_ONLY.name]
and flags_dict[_USE_EXAMPLE_PACKING.name]
flags_dict[_INPUT_MASKING.name]
and flags_dict[_TRAIN_TEMPLATE.name] is None
):
return False
return True
@@ -385,22 +405,65 @@ def check_example_packing(flags_dict: Dict[str, Any]) -> bool:
@flags.multi_flags_validator(
[
_COMPLETION_ONLY.name,
_TEMPLATE.name,
_EVAL_DATASET.name,
_EVAL_METRIC_NAME.name,
],
message='`template` should be provided if using `completion_only=True`',
message=(
'`eval_metric_name` should be a valid metric name and present when'
' eval_dataset is provided.'
),
)
def check_completion_only(flags_dict: Dict[str, Any]) -> bool:
"""Check to make sure completion_only is enabled properly.
def _validate_eval_metrics(flags_dict: Mapping[str, Any]) -> bool:
"""Validates the eval metric name.
Args:
flags_dict: Dictionary containing flags to check.
Returns:
If `completion_only` is set properly
If the eval metrics are valid.
"""
if flags_dict[_COMPLETION_ONLY.name] and flags_dict[_TEMPLATE.name] is None:
return False
if flags_dict[_EVAL_DATASET.name] is None:
return True
eval_metrics = flags_dict[_EVAL_METRIC_NAME.name]
for eval_metric in eval_metrics:
if eval_metric not in constants.SUPPORTED_EVAL_METRICS:
raise flags.ValidationError(f'Invalid eval metric: {eval_metric}')
if 'perplexity' in eval_metrics and 'loss' not in eval_metrics:
_EVAL_METRIC_NAME.value.append('loss')
logging.warning(
'Adding `loss` to eval_metric_name because `perplexity` is present.'
)
return True
@flags.multi_flags_validator(
[
_METRIC_FOR_BEST_MODEL.name,
_EVAL_METRIC_NAME.name,
],
message='`metric_for_best_model` should be in `eval_metric_name`.',
)
def _validate_metric_for_best_model(flags_dict: Mapping[str, Any]) -> bool:
"""Validates the metric for best model.
Args:
flags_dict: Dictionary containing flags to check.
Returns:
If the metric for best model is valid.
"""
if flags_dict[_METRIC_FOR_BEST_MODEL.name] is None:
return True
metric_for_best_model = flags_dict[_METRIC_FOR_BEST_MODEL.name]
eval_metric_name = flags_dict[_EVAL_METRIC_NAME.name]
if metric_for_best_model not in eval_metric_name:
raise flags.ValidationError(
'Invalid metric for picking the best model:'
f' {metric_for_best_model}. The metric should be one'
f' of the {eval_metric_name}.'
)
return True
@@ -411,10 +474,43 @@ def check_completion_only(flags_dict: Dict[str, Any]) -> bool:
# https://github.com/huggingface/notebooks/blob/main/sagemaker/28_train_llms_with_qlora/scripts/run_clm.py.
def _calculate_hf_eval_metrics(
tokenizer: transformers.PreTrainedTokenizerBase,
eval_config: eval_lib.EvalConfig | None,
) -> tuple[
Callable[[transformers.EvalPrediction], Mapping[str, float]], torch.Tensor
]:
"""Calculates the HF evaluation metrics.
Args:
tokenizer: The tokenizer to use for evaluation.
eval_config: The evaluation config to use.
Returns:
The compute metrics and preprocess logits for metrics.
"""
if eval_config is None:
return None, None
hf_eval_metrics = {}
for metric in eval_config.metric_name:
if metric in constants.SUPPORTED_HF_EVAL_METRICS:
if metric in constants.ROUGE_VARIANTS:
hf_eval_metrics[metric] = evaluate.load('rouge')
else:
hf_eval_metrics[metric] = evaluate.load(metric)
if not hf_eval_metrics:
return None, None
return (
eval_lib.create_compute_metrics(tokenizer, hf_eval_metrics),
eval_lib.preprocess_logits_for_metrics,
)
# Copied from https://github.com/artidoro/qlora/blob/main/qlora.py.
def find_all_linear_names(
model: AutoModelForCausalLM, precision_mode: str
) -> list[str]:
model: transformers.AutoModelForCausalLM, precision_mode: str
) -> Sequence[str]:
"""Finds all linear module names."""
if precision_mode == constants.PRECISION_MODE_4:
cls = bnb.nn.Linear4bit
@@ -433,47 +529,51 @@ def find_all_linear_names(
def finetune_instruct(
pretrained_model_id: str,
dataset_name: str,
pretrained_model_name_or_path: str,
train_dataset: str,
output_dir: str,
logging_output_dir: str,
lora_rank: int = 64,
lora_alpha: int = 16,
lora_dropout: float = 0.1,
warmup_ratio: int = 0.03,
num_epochs: Optional[float] = None,
max_steps: Optional[int] = None,
num_train_epochs: float | None = None,
max_steps: int | None = None,
warmup_steps: int = 10,
max_seq_length: int = 512,
learning_rate: float = 2e-4,
precision_mode: str = None,
instruct_column_in_dataset: str = constants.DEFAULT_INSTRUCT_COLUMN_IN_DATASET,
train_column: str = constants.DEFAULT_TRAIN_COLUMN,
per_device_train_batch_size: int = 4,
gradient_accumulation_steps: int = 4,
optim: str = 'paged_adamw_32bit',
weight_decay: float = 0.001,
enable_gradient_checkpointing: bool = False,
gradient_checkpointing: bool = False,
enable_peft: bool = True,
template: str = None,
train_template: str = None,
lr_scheduler_type: str = 'constant',
save_steps: int = 10,
logging_steps: int = 10,
train_split_name: str = 'train',
eval_config: Optional[eval_lib.EvalConfig] = None,
train_split: str = 'train',
eval_config: eval_lib.EvalConfig | None = None,
report_to: str = constants.REPORT_TO_NONE,
access_token: Optional[str] = None,
access_token: str | None = None,
train_precision: str = constants.PRECISION_MODE_16B,
use_example_packing: bool = False,
attn_implementation: Optional[str] = None,
example_packing: bool = False,
attn_implementation: str | None = None,
max_grad_norm: float = 0.3,
completion_only: bool = False,
input_masking: bool = False,
logger_level: str = 'passive',
benchmark_out_file: Optional[str] = None,
tuning_data_stats_file: Optional[str] = None,
target_modules: Optional[str] = None,
benchmark_out_file: str | None = None,
tuning_data_stats_file: str | None = None,
target_modules: str | None = None,
) -> None:
"""Finetunes instruct."""
logging.info('on entering instruct_lora, %s', utils.gpu_stats_str())
logging.info(
'on entering instruct_lora, %s,\n%s',
device_stats.gpu_stats_str(),
device_stats.cpu_stats_str(),
)
gradient_checkpointing_kwargs = {}
# DDP provides limited support with the reentrant variant of gradient
# checkpoint [1]. Below is an indirect way of checking whether DDP will be
@@ -483,17 +583,25 @@ def finetune_instruct(
if PartialState().distributed_type == DistributedType.MULTI_GPU:
gradient_checkpointing_kwargs['use_reentrant'] = False
tokenizer = utils.load_tokenizer(
pretrained_model_id,
tokenizer = dataset_validation_util.load_tokenizer(
pretrained_model_name_or_path,
'right',
access_token=access_token,
)
train_dataset = dataset_validation_util.load_dataset_with_template(
dataset_name,
split=train_split_name,
input_column=instruct_column_in_dataset,
template=template,
train_dataset, train_dataset_with_template = (
dataset_validation_util.load_dataset_with_template(
train_dataset,
split=train_split,
input_column=train_column,
template=train_template,
tokenizer=tokenizer,
)
)
train_dataset_with_template = dataset_validation_util.get_filtered_dataset(
dataset=train_dataset_with_template,
input_column=train_column,
max_seq_length=max_seq_length,
tokenizer=tokenizer,
)
@@ -508,24 +616,26 @@ def finetune_instruct(
'getting tuning data stats with effective batch size %s',
effective_batch_size,
)
train_dataset_stats = utils.get_dataset_stats(
train_dataset,
tokenizer,
instruct_column_in_dataset,
effective_batch_size,
train_dataset_stats = dataset_stats.get_dataset_stats(
raw=train_dataset,
templated=train_dataset_with_template,
template=train_template,
tokenizer=tokenizer,
column=train_column,
effective_batch_size=effective_batch_size,
)
logging.info('stats: %s', train_dataset_stats)
tuning_data_stats_file = dataset_validation_util.force_gcs_fuse_path(
tuning_data_stats_file
)
with open(tuning_data_stats_file, 'w') as out_f:
json.dump(dataclasses.asdict(train_dataset_stats), out_f)
json.dump(train_dataset_stats, out_f)
model = utils.load_model(
pretrained_model_id=pretrained_model_id,
pretrained_model_name_or_path=pretrained_model_name_or_path,
tokenizer=tokenizer,
precision_mode=precision_mode,
enable_gradient_checkpointing=enable_gradient_checkpointing,
gradient_checkpointing=gradient_checkpointing,
access_token=access_token,
attn_implementation=attn_implementation,
train_precision=train_precision,
@@ -550,7 +660,9 @@ def finetune_instruct(
# `get_peft_model`, which may revert other changes we did before. That's why
# we are calling `get_peft_model` explicitly here.
model = get_peft_model(model, peft_config)
adapter_for_eval_dir = os.path.join(output_dir, 'adapter_for_eval')
logging.info('saving adapter for evaluation to %s...', adapter_for_eval_dir)
peft_config.save_pretrained(adapter_for_eval_dir)
# This is to work-around mix-precision training. This issue is not fixed as
# of transformers==4.41.2.
# See b/332760883#comment30 for more details.
@@ -568,14 +680,13 @@ def finetune_instruct(
# b/357970482#comment3
accelerator_config = {'use_configured_state': True}
training_arguments = TrainingArguments(
training_arguments = transformers.TrainingArguments(
report_to=report_to,
output_dir=output_dir,
per_device_train_batch_size=per_device_train_batch_size,
gradient_accumulation_steps=gradient_accumulation_steps,
optim=optim,
save_steps=save_steps,
save_strategy='steps',
save_total_limit=3,
logging_dir=os.path.join(logging_output_dir, 'logs'),
logging_steps=logging_steps,
@@ -583,21 +694,24 @@ def finetune_instruct(
fp16=(train_precision == constants.PRECISION_MODE_16),
bf16=(train_precision == constants.PRECISION_MODE_16B),
max_grad_norm=max_grad_norm,
num_train_epochs=num_epochs if num_epochs else -1,
num_train_epochs=num_train_epochs if num_train_epochs else -1,
max_steps=max_steps if max_steps else -1,
warmup_ratio=warmup_ratio,
warmup_steps=warmup_steps,
group_by_length=False,
lr_scheduler_type=lr_scheduler_type,
gradient_checkpointing=enable_gradient_checkpointing,
gradient_checkpointing=gradient_checkpointing,
gradient_checkpointing_kwargs=gradient_checkpointing_kwargs,
weight_decay=weight_decay,
log_level=logger_level,
accelerator_config=accelerator_config,
include_num_input_tokens_seen=True,
)
trainer_kwargs = {}
if completion_only and template:
template_json = dataset_validation_util.get_template(template_path=template)
if input_masking and train_template:
template_json = dataset_validation_util.get_template(
template_path=train_template
)
instruction_sep = dataset_validation_util.get_instruction_separator(
template_json
)
@@ -608,7 +722,7 @@ def finetune_instruct(
' `DataCollatorForCompletionOnlyLM`'
)
trainer_kwargs['data_collator'] = DataCollatorForCompletionOnlyLM(
trainer_kwargs['data_collator'] = trl.DataCollatorForCompletionOnlyLM(
instruction_template=instruction_sep,
response_template=response_sep,
tokenizer=tokenizer,
@@ -618,17 +732,23 @@ def finetune_instruct(
trainer_stats_callback = callbacks.TrainerStatsCallback(
max_seq_length, benchmark_out_file
)
compute_metrics, preprocess_logits = _calculate_hf_eval_metrics(
tokenizer, eval_config
)
trainer = eval_lib.create_trainer(
cls=SFTTrainer,
cls=trl.SFTTrainer,
eval_config=eval_config,
model=model,
train_dataset=train_dataset,
dataset_text_field=instruct_column_in_dataset,
train_dataset=train_dataset_with_template,
dataset_text_field=train_column,
max_seq_length=max_seq_length,
tokenizer=tokenizer,
args=training_arguments,
packing=use_example_packing,
packing=example_packing,
callbacks=[trainer_stats_callback],
compute_metrics=compute_metrics,
preprocess_logits_for_metrics=preprocess_logits,
**trainer_kwargs,
)
@@ -658,7 +778,7 @@ def finetune_instruct(
# This method saves the sharded weights like `accelerator.save_state`, see
# https://huggingface.co/docs/accelerate/en/usage_guides/fsdp#saving-and-loading
trainer.save_model(output_dir)
model = trainer.model.cpu() # Avoids GPU OOM
model = trainer.model
state_dict = trainer.accelerator.get_state_dict(model)
# To aggregate the weights from all the devices, we need to use
# `state_dict=state_dict`.
@@ -668,7 +788,6 @@ def finetune_instruct(
is_main_process=PartialState().is_main_process,
save_embedding_layers=False, # Only pad token is added. See go/lora-adapter-pad-token #pylint: disable=line-too-long
)
model.cuda() # Move back to GPU to do eval.
else:
trainer.model.save_pretrained(
final_checkpoint,
@@ -683,15 +802,6 @@ def finetune_instruct(
# https://github.com/huggingface/transformers/blob/v4.38.2/src/transformers/trainer_pt_utils.py#L1001 #pylint: disable=line-too-long
trainer.log_metrics('eval', metrics)
trainer.save_metrics('eval', metrics)
if PartialState().is_main_process:
hp_metric = metrics[f'eval_{eval_config.metric_name}']
hpt = hypertune.HyperTune()
hpt.report_hyperparameter_tuning_metric(
hyperparameter_metric_tag=constants.HP_METRIC_TAG,
metric_value=hp_metric,
)
logging.info('Send HP metric: %f to hyperparameter tuning.', hp_metric)
PartialState().wait_for_everyone()
if not enable_peft:
tokenizer.save_pretrained(
@@ -705,38 +815,41 @@ def main(unused_argv: Sequence[str]) -> None:
timeout=datetime.timedelta(seconds=_NCCL_TIMEOUT.value)
)
torch.cuda.set_per_process_memory_fraction(
_MAX_GPU_MEMORY_FRACTION.value, device=PartialState().local_process_index
)
utils.print_library_versions()
warnings.simplefilter(_WARNINGS_FILTER.value)
pretrained_model_id = fileutils.force_gcs_path(_PRETRAINED_MODEL_ID.value)
if dataset_validation_util.is_gcs_path(pretrained_model_id):
pretrained_model_id = dataset_validation_util.download_gcs_uri_to_local(
pretrained_model_id
)
output_dir = utils.GcsOrLocalDirectory(
_OUTPUT_DIR.value, check_empty=True, upload_from_all_nodes=True
pretrained_model_name_or_path = fileutils.force_gcs_path(
_PRETRAINED_MODEL_NAME_OR_PATH.value
)
if dataset_validation_util.is_gcs_path(pretrained_model_name_or_path):
pretrained_model_name_or_path = (
dataset_validation_util.download_gcs_uri_to_local(
pretrained_model_name_or_path
)
)
# GCS Fuse does not sync flushed files if not closed. See b/361771727.
logging_output_dir = fileutils.force_gcs_path(_LOGGING_OUTPUT_DIR.value)
# Creates evaluation config.
if _EVAL_TASKS.value:
if _EVAL_DATASET.value:
eval_config = eval_lib.EvalConfig(
tasks=_EVAL_TASKS.value,
per_device_batch_size=_EVAL_PER_DEVICE_BATCH_SIZE.value,
num_fewshot=_EVAL_NUM_FEWSHOT.value,
per_device_batch_size=_PER_DEVICE_EVAL_BATCH_SIZE.value,
limit=_EVAL_LIMIT.value,
metric_name=_EVAL_METRIC_NAME.value,
steps=_EVAL_STEPS.value,
dataset_path=dataset_validation_util.force_gcs_fuse_path(
_EVAL_DATASET_PATH.value
_EVAL_DATASET.value
),
split=_EVAL_SPLIT.value,
template=_EVAL_TEMPLATE.value,
column=_EVAL_COLUMN.value,
tokenize_dataset=False,
metric_for_best_model=_METRIC_FOR_BEST_MODEL.value,
)
else:
eval_config = None
@@ -745,40 +858,40 @@ def main(unused_argv: Sequence[str]) -> None:
wandb.login()
finetune_instruct(
pretrained_model_id=pretrained_model_id,
dataset_name=_DATASET_NAME.value,
output_dir=output_dir.local_dir,
pretrained_model_name_or_path=pretrained_model_name_or_path,
train_dataset=_TRAIN_DATASET.value,
output_dir=_OUTPUT_DIR.value,
logging_output_dir=logging_output_dir,
precision_mode=_PRECISION_MODE.value,
lora_rank=_LORA_RANK.value,
lora_alpha=_LORA_ALPHA.value,
lora_dropout=_LORA_DROPOUT.value,
warmup_ratio=_WARMUP_RATIO.value,
num_epochs=_NUM_EPOCHS.value,
num_train_epochs=_NUM_TRAIN_EPOCHS.value,
warmup_steps=_WARMUP_STEPS.value,
max_steps=_MAX_STEPS.value,
max_seq_length=_MAX_SEQ_LENGTH.value,
learning_rate=_LEARNING_RATE.value,
instruct_column_in_dataset=_INSTRUCT_COLUMN_IN_DATASET.value,
train_column=_TRAIN_COLUMN.value,
per_device_train_batch_size=_PER_DEVICE_TRAIN_BATCH_SIZE.value,
optim=_OPTIMIZER.value,
weight_decay=_WEIGHT_DECAY.value,
gradient_accumulation_steps=_GRADIENT_ACCUMULATION_STEPS.value,
enable_gradient_checkpointing=_ENABLE_GRADIENT_CHECKPOINTING.value,
gradient_checkpointing=_GRADIENT_CHECKPOINTING.value,
enable_peft=_ENABLE_PEFT.value,
template=_TEMPLATE.value,
train_template=_TRAIN_TEMPLATE.value,
lr_scheduler_type=_LR_SCHEDULER_TYPE.value,
save_steps=_SAVE_STEPS.value,
logging_steps=_LOGGING_STEPS.value,
train_split_name=_TRAIN_SPLIT_NAME.value,
train_split=_TRAIN_SPLIT.value,
eval_config=eval_config,
report_to=_REPORT_TO.value,
access_token=_HUGGINGFACE_ACCESS_TOKEN.value,
train_precision=_TRAIN_PRECISION.value,
use_example_packing=_USE_EXAMPLE_PACKING.value,
example_packing=_EXAMPLE_PACKING.value,
attn_implementation=_ATTN_IMPLEMENTATION.value,
max_grad_norm=_MAX_GRAD_NORM.value,
completion_only=_COMPLETION_ONLY.value,
input_masking=_INPUT_MASKING.value,
logger_level=_LOGGER_LEVEL.value,
benchmark_out_file=_BENCHMARK_OUT_FILE.value,
tuning_data_stats_file=_TUNING_DATA_STATS_FILE.value,
@@ -787,8 +900,6 @@ def main(unused_argv: Sequence[str]) -> None:
# Frees the model from GPU.
utils.force_gc()
output_dir.upload_to_gcs(skip_if_exists=True)
if __name__ == '__main__':
app.run(main)
@@ -1,6 +1,7 @@
"""Script to merge PEFT adapter with base model."""
from typing import Any, Dict, Sequence
from collections.abc import Mapping, Sequence
from typing import Any
from absl import app
from absl import flags
@@ -11,14 +12,14 @@ from util import constants
from util import fileutils
_PRETRAINED_MODEL_ID = flags.DEFINE_string(
'pretrained_model_id',
_PRETRAINED_MODEL_NAME_OR_PATH = flags.DEFINE_string(
'pretrained_model_name_or_path',
None,
'The pretrained model id. Supported models can be causal language modeling'
' models from https://github.com/huggingface/peft/tree/main. Note, there'
' might be different paddings for different models. This tool assumes the'
' pretrained_model_id contains model name, and then choose proper padding'
' methods. e.g. it must contain `llama` for `Llama2 models`.',
' pretrained_model_name_or_path contains model name, and then choose proper'
' padding methods. e.g. it must contain `llama` for `Llama2 models`.',
required=True,
)
@@ -30,7 +31,7 @@ _MERGE_BASE_AND_LORA_OUTPUT_DIR = flags.DEFINE_string(
_MERGE_MODEL_PRECISION_MODE = flags.DEFINE_enum(
'merge_model_precision_mode',
constants.PRECISION_MODE_16,
constants.PRECISION_MODE_16B,
[
constants.PRECISION_MODE_4,
constants.PRECISION_MODE_8,
@@ -48,20 +49,6 @@ _FINETUNED_LORA_MODEL_DIR = flags.DEFINE_string(
'The directory storing finetuned LoRA model weights.',
)
_RESTRICT_MODEL_UPLOAD_DOCKER_URI = flags.DEFINE_string(
'restrict_model_upload_docker_uri',
'',
'If set, mark output model as only uploadable to Model Registry with the'
' specified Docker URI.',
)
_EXECUTOR_INPUT = flags.DEFINE_string(
'executor_input',
'',
'For internal use. Kubeflow pipeline context when running trainer as part'
' of an internal pipeline.',
)
_HUGGINGFACE_ACCESS_TOKEN = flags.DEFINE_string(
'huggingface_access_token',
None,
@@ -71,12 +58,12 @@ _HUGGINGFACE_ACCESS_TOKEN = flags.DEFINE_string(
@flags.multi_flags_validator(
[
_PRETRAINED_MODEL_ID.name,
_PRETRAINED_MODEL_NAME_OR_PATH.name,
_FINETUNED_LORA_MODEL_DIR.name,
_MERGE_BASE_AND_LORA_OUTPUT_DIR.name,
],
)
def check_merge_lora_model_flags(flags_dict: Dict[str, Any]) -> bool:
def check_merge_lora_model_flags(flags_dict: Mapping[str, Any]) -> bool:
"""Check if required flags are set on merge model LoRA task.
Args:
@@ -89,44 +76,33 @@ def check_merge_lora_model_flags(flags_dict: Dict[str, Any]) -> bool:
def main(unused_argv: Sequence[str]) -> None:
pretrained_model_id = fileutils.force_gcs_path(_PRETRAINED_MODEL_ID.value)
if dataset_validation_util.is_gcs_path(pretrained_model_id):
pretrained_model_id = dataset_validation_util.download_gcs_uri_to_local(
pretrained_model_id
pretrained_model_name_or_path = fileutils.force_gcs_path(
_PRETRAINED_MODEL_NAME_OR_PATH.value
)
if dataset_validation_util.is_gcs_path(pretrained_model_name_or_path):
pretrained_model_name_or_path = (
dataset_validation_util.download_gcs_uri_to_local(
pretrained_model_name_or_path
)
)
finetuned_lora_model_dir = utils.GcsOrLocalDirectory(
finetuned_lora_model_dir = fileutils.force_gcs_path(
_FINETUNED_LORA_MODEL_DIR.value
)
merge_base_and_lora_output_dir = utils.GcsOrLocalDirectory(
_MERGE_BASE_AND_LORA_OUTPUT_DIR.value
)
if dataset_validation_util.is_gcs_path(finetuned_lora_model_dir):
finetuned_lora_model_dir = (
dataset_validation_util.download_gcs_uri_to_local(
finetuned_lora_model_dir
)
)
utils.merge_causal_language_model_with_lora(
pretrained_model_id=pretrained_model_id,
pretrained_model_name_or_path=pretrained_model_name_or_path,
precision_mode=_MERGE_MODEL_PRECISION_MODE.value,
finetuned_lora_model_dir=finetuned_lora_model_dir.local_dir,
merged_model_output_dir=merge_base_and_lora_output_dir.local_dir,
finetuned_lora_model_dir=finetuned_lora_model_dir,
merged_model_output_dir=_MERGE_BASE_AND_LORA_OUTPUT_DIR.value,
access_token=_HUGGINGFACE_ACCESS_TOKEN.value,
)
if _RESTRICT_MODEL_UPLOAD_DOCKER_URI.value:
utils.write_first_party_model_metadata(
merge_base_and_lora_output_dir.local_dir,
_RESTRICT_MODEL_UPLOAD_DOCKER_URI.value,
)
if _EXECUTOR_INPUT.value:
utils.write_kfp_outputs(
_EXECUTOR_INPUT.value,
{
'saved_model': _MERGE_BASE_AND_LORA_OUTPUT_DIR.value,
},
)
merge_base_and_lora_output_dir.upload_to_gcs(skip_if_exists=True)
if __name__ == '__main__':
app.run(main)
@@ -1,349 +0,0 @@
"""Quantizes the model."""
import json
import os
from typing import Any, Dict, List, Sequence, Union
from absl import app
from absl import flags
from absl import logging
from auto_gptq import AutoGPTQForCausalLM
from auto_gptq import BaseQuantizeConfig
from awq import AutoAWQForCausalLM
from optimum.gptq.data import get_dataset
from transformers import AutoTokenizer
from util import dataset_validation_util
from vertex_vision_model_garden_peft.train.vmg import utils
from util import constants
_PRETRAINED_MODEL_ID = flags.DEFINE_string(
'pretrained_model_id',
None,
'The pretrained model id. Supported models can be causal language modeling'
' models from https://github.com/huggingface/peft/tree/main. Note, there'
' might be different paddings for different models. This tool assumes the'
' pretrained_model_id contains model name, and then choose proper padding'
' methods. e.g. it must contain `llama` for `Llama2 models`.',
)
_QUANTIZATION_METHOD = flags.DEFINE_enum(
'quantization_method',
None,
[constants.GPTQ, constants.AWQ],
'The quantization method. Choose from ["gtpq", "awq"].',
)
_QUANTIZATION_PRECISION_MODE = flags.DEFINE_enum(
'quantization_precision_mode',
constants.PRECISION_MODE_4,
[
constants.PRECISION_MODE_8,
constants.PRECISION_MODE_4,
constants.PRECISION_MODE_3,
constants.PRECISION_MODE_2,
],
'Quantization precision mode.',
)
_QUANTIZATION_DATASET_NAME = flags.DEFINE_string(
'quantization_dataset_name',
None,
'The dataset used for quantization. You can provide your own dataset in a'
' list of string or just use the original datasets used in GPTQ paper'
' ["wikitext2","c4","c4-new","ptb","ptb-new"] for GPTQ quantization. Using'
" a dataset more appropriate to the model's training can improve"
' quantisation accuracy. Note that the GPTQ dataset is not the same as the'
' dataset used to train the model.',
)
_TEXT_COLUMN_IN_QUANTIZATION_DATASET = flags.DEFINE_string(
'text_column_in_quantization_dataset',
constants.DEFAULT_TEXT_COLUMN_IN_QUANTIZATION_DATASET,
'The text column in quantization dataset.',
)
_QUANTIZATION_OUTPUT_DIR = flags.DEFINE_string(
'quantization_output_dir',
None,
'The directory to store the quantized model.',
)
_QUANTIZATION_DEVICE_MAP = flags.DEFINE_string(
'device_map', None, 'The device map.'
)
_QUANTIZATION_MAX_MEMORY = flags.DEFINE_string(
'max_memory', None, 'The maximum memory.'
)
_GROUP_SIZE = flags.DEFINE_integer(
'group_size',
None,
'The group size to use for quantization. Recommended value is 128 and -1'
' uses per-column quantization. Higher numbers use less VRAM, but have'
' lower quantisation accuracy. "None" is the lowest possible value.',
)
_DESC_ACT = flags.DEFINE_boolean(
'desc_act',
False,
'Whether to quantize columns in order of decreasing activation size.'
' Setting it to False can significantly speed up inference but the'
' perplexity may become slightly worse. Also known as act-order.',
)
_DAMP_PERCENT = flags.DEFINE_float(
'damp_percent',
0.1,
'The percent of the average Hessian diagonal to use for dampening.',
)
_CACHE_EXAMPLES_ON_GPU = flags.DEFINE_boolean(
'cache_examples_on_gpu',
True,
'Whether to cache the examples on GPU. Disabling will reduce VRAM usage,'
' but increase quantization time.',
)
_AWQ_VERSION = flags.DEFINE_enum(
'awq_version',
constants.GEMM,
[constants.GEMM, constants.GEMV],
'The version of the AWQ to use. It determines how matrix multiplication'
' runs under the hood. GEMV is 20% faster than GEMM, only at batch size 1'
' (not good for large contexts). GEMM is much faster than FP16 at batch'
' sizes below 8 (good with large contexts).',
)
@flags.multi_flags_validator(
[
_PRETRAINED_MODEL_ID.name,
_QUANTIZATION_METHOD.name,
_QUANTIZATION_PRECISION_MODE.name,
_QUANTIZATION_DATASET_NAME.name,
_QUANTIZATION_OUTPUT_DIR.name,
],
)
def check_quantization_flags(flags_dict: Dict[str, Any]) -> bool:
"""Check if required flags are set on quantization task.
Args:
flags_dict: Dictionary containing task and flags to check.
Returns:
If required flags are not None.
"""
required_flags = [
_QUANTIZATION_METHOD.name,
_PRETRAINED_MODEL_ID.name,
_QUANTIZATION_PRECISION_MODE.name,
_QUANTIZATION_DATASET_NAME.name,
_QUANTIZATION_OUTPUT_DIR.name,
]
return all(map(lambda x: flags_dict[x] is not None, required_flags))
def quantize_model(
quantization_method: str,
pretrained_model_id: str,
quantization_output_dir: str,
quantization_precision_mode: str = None,
quantization_dataset_name: Union[List[str]] = None,
text_column_in_quantization_dataset: str = constants.DEFAULT_TEXT_COLUMN_IN_QUANTIZATION_DATASET,
group_size: int = None,
desc_act: bool = True,
damp_percent: float = 0.1,
awq_version: str = 'GEMM',
device_map: str = None,
max_memory: Dict[Any, str] = None,
cache_examples_on_gpu: bool = True,
) -> None:
"""Quantizes the model using `quantization_method`."""
if quantization_method == constants.GPTQ:
gptq_quantize_model(
pretrained_model_id=pretrained_model_id,
gptq_output_dir=quantization_output_dir,
gptq_precision_mode=quantization_precision_mode,
gptq_dataset_name=quantization_dataset_name,
group_size=group_size,
desc_act=desc_act,
damp_percent=damp_percent,
cache_examples_on_gpu=cache_examples_on_gpu,
)
elif quantization_method == constants.AWQ:
awq_quantize_model(
pretrained_model_id=pretrained_model_id,
quantization_output_dir=quantization_output_dir,
quantization_precision_mode=quantization_precision_mode,
quantization_dataset_name=quantization_dataset_name,
text_column_in_quantization_dataset=text_column_in_quantization_dataset,
group_size=group_size,
awq_version=awq_version,
device_map=device_map,
max_memory=max_memory,
)
def awq_quantize_model(
pretrained_model_id: str,
quantization_output_dir: str,
quantization_precision_mode: str = None,
quantization_dataset_name: Union[List[str]] = None,
text_column_in_quantization_dataset: str = constants.DEFAULT_TEXT_COLUMN_IN_QUANTIZATION_DATASET,
group_size: int = None,
awq_version: str = 'GEMM',
device_map: str = None,
max_memory: Dict[Any, str] = None,
) -> None:
"""Quantizes the model using AWQ."""
if quantization_precision_mode != constants.PRECISION_MODE_4:
raise ValueError(
f'Invalid precision mode: {quantization_precision_mode} for AWQ. 4bit'
' quantization must be used.'
)
else:
bits = 4
if not group_size:
group_size = 128
if not device_map:
device_map = 'cpu'
if dataset_validation_util.is_gcs_path(quantization_dataset_name):
logging.info('Using custom dataset: %s', quantization_dataset_name)
with open(
dataset_validation_util.force_gcs_fuse_path(quantization_dataset_name),
'r',
) as f:
quantization_dataset = [line.rstrip('\n') for line in f]
else:
quantization_dataset = quantization_dataset_name
quant_config = {
'zero_point': True,
'q_group_size': group_size,
'w_bit': bits,
'version': awq_version,
}
logging.info('Quantization config: %s', quant_config)
model = AutoAWQForCausalLM.from_pretrained(
pretrained_model_id,
trust_remote_code=True,
device_map=device_map,
max_memory=max_memory,
low_cpu_mem_usage=True,
)
tokenizer = AutoTokenizer.from_pretrained(
pretrained_model_id, trust_remote_code=True
)
model.quantize(
tokenizer,
quant_config=quant_config,
calib_data=quantization_dataset,
text_column=text_column_in_quantization_dataset,
)
model.save_quantized(quantization_output_dir)
tokenizer.save_pretrained(quantization_output_dir)
def gptq_quantize_model(
pretrained_model_id: str,
gptq_output_dir: str,
gptq_precision_mode: str = None,
gptq_dataset_name: Union[List[str]] = None,
group_size: int = -1,
desc_act: bool = False,
damp_percent: float = 0.1,
cache_examples_on_gpu: bool = True,
) -> None:
"""Quantizes the model using GPTQ."""
logging.info(
'PYTORCH_CUDA_ALLOC_CONF: %s',
os.environ.get('PYTORCH_CUDA_ALLOC_CONF', ''),
)
if dataset_validation_util.is_gcs_path(gptq_dataset_name):
logging.info('Using custom dataset: %s', gptq_dataset_name)
with open(
dataset_validation_util.force_gcs_fuse_path(gptq_dataset_name), 'r'
) as f:
gptq_dataset = [line.rstrip('\n') for line in f]
else:
gptq_dataset = gptq_dataset_name
if gptq_precision_mode == constants.PRECISION_MODE_8:
bits = 8
elif gptq_precision_mode == constants.PRECISION_MODE_4:
bits = 4
elif gptq_precision_mode == constants.PRECISION_MODE_3:
bits = 3
elif gptq_precision_mode == constants.PRECISION_MODE_2:
bits = 2
else:
raise ValueError(f'Invalid precision mode: {gptq_precision_mode} for GPTQ.')
if not group_size:
group_size = -1
tokenizer = AutoTokenizer.from_pretrained(pretrained_model_id)
gptq_dataset = get_dataset(gptq_dataset, tokenizer)
quantization_config = BaseQuantizeConfig(
bits=bits,
group_size=group_size,
damp_percent=damp_percent,
desc_act=desc_act,
)
logging.info('Quantization config: %s', quantization_config.to_dict())
model = AutoGPTQForCausalLM.from_pretrained(
pretrained_model_id,
quantization_config,
low_cpu_mem_usage=True,
torch_dtype='auto',
trust_remote_code=True,
)
model.quantize(
examples=gptq_dataset,
cache_examples_on_gpu=cache_examples_on_gpu,
)
if utils.should_add_pad_token(pretrained_model_id):
tokenizer.add_special_tokens({'pad_token': '[PAD]'})
model.resize_token_embeddings(len(tokenizer))
model.save_pretrained(gptq_output_dir)
tokenizer.save_pretrained(gptq_output_dir)
def main(unused_argv: Sequence[str]) -> None:
pretrained_model_id = _PRETRAINED_MODEL_ID.value
if dataset_validation_util.is_gcs_path(pretrained_model_id):
pretrained_model_id = dataset_validation_util.download_gcs_uri_to_local(
pretrained_model_id
)
pretrained_model_id = dataset_validation_util.force_gcs_fuse_path(
pretrained_model_id
)
if _QUANTIZATION_MAX_MEMORY.value:
max_memory = json.loads(_QUANTIZATION_MAX_MEMORY.value)
else:
max_memory = None
quantize_model(
quantization_method=_QUANTIZATION_METHOD.value,
pretrained_model_id=pretrained_model_id,
quantization_output_dir=_QUANTIZATION_OUTPUT_DIR.value,
quantization_precision_mode=_QUANTIZATION_PRECISION_MODE.value,
quantization_dataset_name=_QUANTIZATION_DATASET_NAME.value,
text_column_in_quantization_dataset=_TEXT_COLUMN_IN_QUANTIZATION_DATASET.value,
group_size=_GROUP_SIZE.value,
desc_act=_DESC_ACT.value,
damp_percent=_DAMP_PERCENT.value,
awq_version=_AWQ_VERSION.value,
device_map=_QUANTIZATION_DEVICE_MAP.value,
max_memory=max_memory,
cache_examples_on_gpu=_CACHE_EXAMPLES_ON_GPU.value,
)
if __name__ == '__main__':
app.run(main)
@@ -1,229 +0,0 @@
"""Sequence classification with LoRA models."""
from typing import Sequence
from absl import app
from absl import flags
from datasets import load_dataset
import evaluate
from peft import get_peft_model
from peft import LoraConfig
import torch
from torch.optim import AdamW
from torch.utils.data import DataLoader
from tqdm import tqdm
from transformers import AutoModelForSequenceClassification
from transformers import AutoTokenizer
from transformers import get_linear_schedule_with_warmup
from util import dataset_validation_util
_PRETRAINED_MODEL_ID = flags.DEFINE_string(
"pretrained_model_id",
None,
"The pretrained model id. Supported models can be causal language modeling"
" models from https://github.com/huggingface/peft/tree/main. Note, there"
" might be different paddings for different models. This tool assumes the"
" pretrained_model_id contains model name, and then choose proper padding"
" methods. e.g. it must contain `llama` for `Llama2 models`.",
)
_OUTPUT_DIR = flags.DEFINE_string(
"output_dir",
None,
"The output directory.",
)
_DATASET_NAME = flags.DEFINE_string(
"dataset_name",
None,
"The dataset name in huggingface.",
)
_LORA_RANK = flags.DEFINE_integer(
"lora_rank",
16,
"The rank of the update matrices, expressed in int. Lower rank results in"
" smaller update matrices with fewer trainable parameters, referring to"
" https://huggingface.co/docs/peft/conceptual_guides/lora.",
)
_LORA_ALPHA = flags.DEFINE_integer(
"lora_alpha",
32,
"LoRA scaling factor, referring to"
" https://huggingface.co/docs/peft/conceptual_guides/lora.",
)
_LORA_DROPOUT = flags.DEFINE_float(
"lora_dropout",
0.05,
"dropout probability of the LoRA layers, referring to"
" https://huggingface.co/docs/peft/task_guides/token-classification-lora.",
)
_NUM_EPOCHS = flags.DEFINE_integer(
"num_epochs",
None,
"The number of training epochs.",
)
_BATCH_SIZE = flags.DEFINE_integer(
"batch_size",
32,
"The batch size.",
)
_LEARNING_RATE = flags.DEFINE_float(
"learning_rate",
2e-4,
"The learning rate after the potential warmup period.",
)
def finetune_sequence_classification(
pretrained_model_id: str,
dataset_name: str,
output_dir: str,
lora_rank: int = 8,
lora_alpha: int = 16,
lora_dropout: float = 0.1,
num_epochs: int = 20,
batch_size: int = 32,
learning_rate: float = 3e-4,
) -> None:
"""Finetunes sequence classification."""
task = "mrpc"
device = "cuda"
peft_config = LoraConfig(
task_type="SEQ_CLS",
inference_mode=False,
r=lora_rank,
lora_alpha=lora_alpha,
lora_dropout=lora_dropout,
)
if any(k in pretrained_model_id for k in ("gpt", "opt", "bloom")):
padding_side = "left"
else:
padding_side = "right"
tokenizer = AutoTokenizer.from_pretrained(
pretrained_model_id, padding_side=padding_side
)
if getattr(tokenizer, "pad_token_id") is None:
tokenizer.pad_token_id = tokenizer.eos_token_id
datasets = load_dataset(dataset_name, task)
metric = evaluate.load(dataset_name, task)
def tokenize_function(examples):
# max_length=None => use the model max length (it's actually the default)
outputs = tokenizer(
examples["sentence1"],
examples["sentence2"],
truncation=True,
max_length=None,
)
return outputs
tokenized_datasets = datasets.map(
tokenize_function,
batched=True,
remove_columns=["idx", "sentence1", "sentence2"],
)
# We also rename the 'label' column to 'labels' which is the expected name for
# labels by the models of the transformers library.
tokenized_datasets = tokenized_datasets.rename_column("label", "labels")
def collate_fn(examples):
return tokenizer.pad(examples, padding="longest", return_tensors="pt")
# Instantiate dataloaders.
train_dataloader = DataLoader(
tokenized_datasets["train"],
shuffle=True,
collate_fn=collate_fn,
batch_size=batch_size,
)
eval_dataloader = DataLoader(
tokenized_datasets["validation"],
shuffle=False,
collate_fn=collate_fn,
batch_size=batch_size,
)
model = AutoModelForSequenceClassification.from_pretrained(
pretrained_model_id, return_dict=True
)
model = get_peft_model(model, peft_config)
model.print_trainable_parameters()
optimizer = AdamW(params=model.parameters(), lr=learning_rate)
# Instantiate scheduler
lr_scheduler = get_linear_schedule_with_warmup(
optimizer=optimizer,
num_warmup_steps=0.06 * (len(train_dataloader) * num_epochs),
num_training_steps=(len(train_dataloader) * num_epochs),
)
model.to(device)
for epoch in range(num_epochs):
model.train()
for _, batch in enumerate(tqdm(train_dataloader)):
batch.to(device)
outputs = model(**batch)
loss = outputs.loss
loss.backward()
optimizer.step()
lr_scheduler.step()
optimizer.zero_grad()
model.eval()
for _, batch in enumerate(tqdm(eval_dataloader)):
batch.to(device)
with torch.no_grad():
outputs = model(**batch)
predictions = outputs.logits.argmax(dim=-1)
references = batch["labels"]
metric.add_batch(
predictions=predictions,
references=references,
)
eval_metric = metric.compute()
print(f"epoch {epoch}:", eval_metric)
model.save_pretrained(output_dir)
def main(unused_argv: Sequence[str]) -> None:
if dataset_validation_util.is_gcs_path(_PRETRAINED_MODEL_ID.value):
pretrained_model_id = dataset_validation_util.download_gcs_uri_to_local(
_PRETRAINED_MODEL_ID.value
)
else:
pretrained_model_id = _PRETRAINED_MODEL_ID.value
pretrained_model_path = dataset_validation_util.force_gcs_fuse_path(
pretrained_model_id
)
output_dir = dataset_validation_util.force_gcs_fuse_path(_OUTPUT_DIR.value)
finetune_sequence_classification(
pretrained_model_id=pretrained_model_path,
dataset_name=_DATASET_NAME.value,
output_dir=output_dir,
lora_rank=_LORA_RANK.value,
lora_alpha=_LORA_ALPHA.value,
lora_dropout=_LORA_DROPOUT.value,
num_epochs=int(_NUM_EPOCHS.value),
batch_size=_BATCH_SIZE.value,
learning_rate=_LEARNING_RATE.value,
)
if __name__ == "__main__":
app.run(main)
@@ -1,7 +1,7 @@
{
"description": "Chat template used by Llama 3.",
"source": "https://huggingface.co/meta-llama/Meta-Llama-3-70B-Instruct/blob/a5a71a7527eac1d651bb145436c72026887fb68e/tokenizer_config.json#L2053",
"chat_template": "{% set loop_messages = messages %}{% for message in loop_messages %}{% set content = '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n'+ message['content'] | trim + '<|eot_id|>' %}{% if loop.index0 == 0 %}{% set content = bos_token + content %}{% endif %}{{ content }}{% endfor %}{% if add_generation_prompt %}{{ '<|start_header_id|>assistant<|end_header_id|>\n\n' }}{% endif %}",
"chat_template": "{% set loop_messages = messages %}{% for message in loop_messages %}{% set content = '\n\n<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n'+ message['content'] | trim + '<|eot_id|>' %}{% if loop.index0 == 0 %}{% set content = bos_token + content %}{% endif %}{{ content }}{% endfor %}{% if add_generation_prompt %}{{ '\n\n<|start_header_id|>assistant<|end_header_id|>\n\n' }}{% endif %}",
"instruction_separator": "<|start_header_id|>user<|end_header_id|>\n\n",
"response_separator": "<|start_header_id|>assistant<|end_header_id|>\n\n"
}
@@ -0,0 +1,7 @@
{
"description": "Template used by openai chat.",
"source": "https://platform.openai.com/docs/api-reference/fine-tuning/chat-input",
"chat_template": "{% set loop_messages = messages %}{% set content = '' %}{% for message in loop_messages %}{% set content = content ~ '\n\n<|start_header_id|>' ~ message.role ~ '<|end_header_id|>\n\n' %}{% if message.content is string %}{% set content = content ~ message.content|trim ~ '<|eot_id|>' %}{% else %}{% set content = content ~ message.content|join(' ', attribute='text')|trim ~ '<|eot_id|>' %}{% endif %}{% if loop.index0 == 0 %}{% set content = bos_token ~ content %}{% endif %}{{ content }}{% endfor %}{% if add_generation_prompt %}{{ '<|start_header_id|>assistant<|end_header_id|>\n\n' }}{% endif %}",
"instruction_separator": "<|start_header_id|>user<|end_header_id|>\n\n",
"response_separator": "<|start_header_id|>assistant<|end_header_id|>\n\n"
}
@@ -0,0 +1,7 @@
{
"description": "Chat template used by Qwen 2.5.",
"source": "https://huggingface.co/Qwen/Qwen2.5-72B-Instruct/blob/main/tokenizer_config.json#L198",
"chat_template": "{%- if tools %}\n {{- '<|im_start|>system\\n' }}\n {%- if messages[0]['role'] == 'system' %}\n {{- messages[0]['content'] }}\n {%- else %}\n {{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}\n {%- endif %}\n {{- \"\\n\\n# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within <tools></tools> XML tags:\\n<tools>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\n</tools>\\n\\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\\n<tool_call>\\n{\\\"name\\\": <function-name>, \\\"arguments\\\": <args-json-object>}\\n</tool_call><|im_end|>\\n\" }}\n{%- else %}\n {%- if messages[0]['role'] == 'system' %}\n {{- '<|im_start|>system\\n' + messages[0]['content'] + '<|im_end|>\\n' }}\n {%- else %}\n {{- '<|im_start|>system\\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- for message in messages %}\n {%- if (message.role == \"user\") or (message.role == \"system\" and not loop.first) or (message.role == \"assistant\" and not message.tool_calls) %}\n {{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {{- '<|im_start|>' + message.role }}\n {%- if message.content %}\n {{- '\\n' + message.content }}\n {%- endif %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {{- '\\n<tool_call>\\n{\"name\": \"' }}\n {{- tool_call.name }}\n {{- '\", \"arguments\": ' }}\n {{- tool_call.arguments | tojson }}\n {{- '}\\n</tool_call>' }}\n {%- endfor %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != \"tool\") %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- message.content }}\n {{- '\\n</tool_response>' }}\n {%- if loop.last or (messages[loop.index0 + 1].role != \"tool\") %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n{%- endif %}\n",
"instruction_separator": "<|im_start|>user\n",
"response_separator": "<|im_start|>assistant\n"
}
@@ -1,7 +1,7 @@
{
"description": "Template used for chat based models.",
"source": "https://huggingface.co/meta-llama/Meta-Llama-3-70B-Instruct/blob/a5a71a7527eac1d651bb145436c72026887fb68e/tokenizer_config.json#L2053",
"chat_template": "{% set loop_messages = messages %}{% for message in loop_messages %}{% set content = '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n'+ message['content'] | trim + '<|eot_id|>' %}{% if loop.index0 == 0 %}{% set content = bos_token + content %}{% endif %}{{ content }}{% endfor %}{% if add_generation_prompt %}{{ '<|start_header_id|>model<|end_header_id|>\n\n' }}{% endif %}",
"chat_template": "{% set loop_messages = messages %}{% for message in loop_messages %}{% set content = '\n\n<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n'+ message['content'] | trim + '<|eot_id|>' %}{% if loop.index0 == 0 %}{% set content = bos_token + content %}{% endif %}{{ content }}{% endfor %}{% if add_generation_prompt %}{{ '\n\n<|start_header_id|>model<|end_header_id|>\n\n' }}{% endif %}",
"instruction_separator": "<|start_header_id|>user<|end_header_id|>\n\n",
"response_separator": "<|start_header_id|>model<|end_header_id|>\n\n"
}
@@ -3,16 +3,18 @@
# DO NOT MODIFY: this file is auto-generated
# See go/vmg-oss-peft-tests#command-builder-genpy
class InstructLoraCommandBuilder:
def __init__(self):
self._config_file = None
self._task = None
self._pretrained_model_id = None
self._dataset_name = None
self._train_split_name = None
self._template = None
self._instruct_column_in_dataset = None
self._gcs_rsync_interval_secs = None
self._pretrained_model_name_or_path = None
self._train_dataset = None
self._train_split = None
self._train_template = None
self._train_column = None
self._output_dir = None
self._merge_base_and_lora_output_dir = None
self._logging_output_dir = None
@@ -22,14 +24,14 @@ class InstructLoraCommandBuilder:
self._lora_alpha = None
self._lora_dropout = None
self._max_steps = None
self._num_epochs = None
self._num_train_epochs = None
self._max_seq_length = None
self._learning_rate = None
self._lr_scheduler_type = None
self._precision_mode = None
self._train_precision = None
self._enable_gradient_checkpointing = None
self._use_example_packing = None
self._gradient_checkpointing = None
self._example_packing = None
self._attn_implementation = None
self._optimizer = None
self._warmup_ratio = None
@@ -37,14 +39,14 @@ class InstructLoraCommandBuilder:
self._save_steps = None
self._logging_steps = None
self._huggingface_access_token = None
self._eval_dataset_path = None
self._eval_dataset = None
self._eval_column = None
self._eval_template = None
self._eval_split = None
self._eval_steps = None
self._eval_tasks = None
self._eval_metric_name = None
self._completion_only = None
self._metric_for_best_model = None
self._input_masking = None
self._max_grad_norm = None
self._logger_level = None
self._benchmark_out_file = None
@@ -52,6 +54,7 @@ class InstructLoraCommandBuilder:
self._enable_peft = None
self._merge_model_precision_mode = None
self._target_modules = None
self._unnamed_args = None
@property
def config_file(self):
@@ -70,44 +73,52 @@ class InstructLoraCommandBuilder:
self._task = val
@property
def pretrained_model_id(self):
return self._pretrained_model_id
def gcs_rsync_interval_secs(self):
return self._gcs_rsync_interval_secs
@pretrained_model_id.setter
def pretrained_model_id(self, val: str):
self._pretrained_model_id = val
@gcs_rsync_interval_secs.setter
def gcs_rsync_interval_secs(self, val: str):
self._gcs_rsync_interval_secs = val
@property
def pretrained_model_name_or_path(self):
return self._pretrained_model_name_or_path
@pretrained_model_name_or_path.setter
def pretrained_model_name_or_path(self, val: str):
self._pretrained_model_name_or_path = val
@property
def train_dataset(self):
return self._dataset_name
return self._train_dataset
@train_dataset.setter
def train_dataset(self, val: str):
self._dataset_name = val
self._train_dataset = val
@property
def train_split_name(self):
return self._train_split_name
def train_split(self):
return self._train_split
@train_split_name.setter
def train_split_name(self, val: str):
self._train_split_name = val
@train_split.setter
def train_split(self, val: str):
self._train_split = val
@property
def template(self):
return self._template
def train_template(self):
return self._train_template
@template.setter
def template(self, val: str):
self._template = val
@train_template.setter
def train_template(self, val: str):
self._train_template = val
@property
def instruct_column(self):
return self._instruct_column_in_dataset
def train_column(self):
return self._train_column
@instruct_column.setter
def instruct_column(self, val: str):
self._instruct_column_in_dataset = val
@train_column.setter
def train_column(self, val: str):
self._train_column = val
@property
def ckpt_dir(self):
@@ -182,12 +193,12 @@ class InstructLoraCommandBuilder:
self._max_steps = val
@property
def num_epochs(self):
return self._num_epochs
def num_train_epochs(self):
return self._num_train_epochs
@num_epochs.setter
def num_epochs(self, val: float):
self._num_epochs = val
@num_train_epochs.setter
def num_train_epochs(self, val: float):
self._num_train_epochs = val
@property
def max_seq_length(self):
@@ -231,19 +242,19 @@ class InstructLoraCommandBuilder:
@property
def gradient_checkpointing(self):
return self._enable_gradient_checkpointing
return self._gradient_checkpointing
@gradient_checkpointing.setter
def gradient_checkpointing(self, val: bool):
self._enable_gradient_checkpointing = val
self._gradient_checkpointing = val
@property
def example_packing(self):
return self._use_example_packing
return self._example_packing
@example_packing.setter
def example_packing(self, val: bool):
self._use_example_packing = val
self._example_packing = val
@property
def attn_implementation(self):
@@ -303,18 +314,18 @@ class InstructLoraCommandBuilder:
@property
def eval_dataset(self):
return self._eval_dataset_path
return self._eval_dataset
@eval_dataset.setter
def eval_dataset(self, val: str):
self._eval_dataset_path = val
self._eval_dataset = val
@property
def eval_instruct_column(self):
def eval_column(self):
return self._eval_column
@eval_instruct_column.setter
def eval_instruct_column(self, val: str):
@eval_column.setter
def eval_column(self, val: str):
self._eval_column = val
@property
@@ -326,11 +337,11 @@ class InstructLoraCommandBuilder:
self._eval_template = val
@property
def eval_split_name(self):
def eval_split(self):
return self._eval_split
@eval_split_name.setter
def eval_split_name(self, val: str):
@eval_split.setter
def eval_split(self, val: str):
self._eval_split = val
@property
@@ -341,14 +352,6 @@ class InstructLoraCommandBuilder:
def eval_steps(self, val: int):
self._eval_steps = val
@property
def eval_tasks(self):
return self._eval_tasks
@eval_tasks.setter
def eval_tasks(self, val: str):
self._eval_tasks = val
@property
def eval_metric_name(self):
return self._eval_metric_name
@@ -358,12 +361,20 @@ class InstructLoraCommandBuilder:
self._eval_metric_name = val
@property
def completion_only(self):
return self._completion_only
def metric_for_best_model(self):
return self._metric_for_best_model
@completion_only.setter
def completion_only(self, val: bool):
self._completion_only = val
@metric_for_best_model.setter
def metric_for_best_model(self, val: str):
self._metric_for_best_model = val
@property
def input_masking(self):
return self._input_masking
@input_masking.setter
def input_masking(self, val: bool):
self._input_masking = val
@property
def max_grad_norm(self):
@@ -421,9 +432,22 @@ class InstructLoraCommandBuilder:
def target_modules(self, val: str):
self._target_modules = val
def build_cmd(self) -> str:
@property
def unnamed_args(self):
return self._unnamed_args
@unnamed_args.setter
def unnamed_args(self, val: list):
self._unnamed_args = val
def build_cmd(self) -> list[str]:
cmd = []
args = ''
for k, v in self.__dict__.items():
if k == '_unnamed_args' and v is not None:
args += ' '.join(v)
continue
if v is not None:
cmd.append(f'--{k[1:]}={v}')
cmd.append(f'{args}')
return cmd
@@ -8,7 +8,7 @@ class QuantizeModelCommandBuilder:
def __init__(self):
self._task = None
self._pretrained_model_id = None
self._pretrained_model_name_or_path = None
self._quantization_method = None
self._quantization_precision_mode = None
self._quantization_dataset_name = None
@@ -31,12 +31,12 @@ class QuantizeModelCommandBuilder:
self._task = val
@property
def pretrained_model_id(self):
return self._pretrained_model_id
def pretrained_model_name_or_path(self):
return self._pretrained_model_name_or_path
@pretrained_model_id.setter
def pretrained_model_id(self, val: str):
self._pretrained_model_id = val
@pretrained_model_name_or_path.setter
def pretrained_model_name_or_path(self, val: str):
self._pretrained_model_name_or_path = val
@property
def quantization_method(self):
@@ -0,0 +1,61 @@
"""Run the tests from docker command line."""
import subprocess
import sys
from typing import Sequence
from absl import app
from absl import flags
_ALLOWED_TEST_FILE_PATHS = (
"test_instruct_lora_adapters",
"test_instruct_lora_features",
"test_instruct_lora_throughput",
"test_instruct_lora_trained_model_quality",
"test_validate_dataset_with_template",
)
_TEST_FILE_PATH = flags.DEFINE_multi_enum(
"test_file_path",
None,
_ALLOWED_TEST_FILE_PATHS + ("all",),
"The test file path.",
required=True,
)
_IS_AUTOMATED_TEST = flags.DEFINE_bool(
"is_automated_test",
True,
"Whether the test is an automated test.",
)
def main(argv: Sequence[str]) -> None:
if len(argv) > 1:
raise app.UsageError("Too many command-line arguments.")
test_file_path = _TEST_FILE_PATH.value
if "all" in test_file_path:
test_file_path = _ALLOWED_TEST_FILE_PATHS
for test_file in test_file_path:
cmd = [
"python3",
f"vertex_vision_model_garden_peft/tests/{test_file}.py",
]
if (
test_file == "test_instruct_lora_throughput"
and _IS_AUTOMATED_TEST.value
):
subprocess.run(
cmd + ["--", "-k", "peft_train_image_automated_test"],
stdout=sys.stdout,
stderr=sys.stdout,
check=True,
)
else:
subprocess.run(cmd, stdout=sys.stdout, stderr=sys.stdout, check=True)
if __name__ == "__main__":
app.run(main)
@@ -31,7 +31,7 @@ class AdapterTest(test_util.TestBase):
def setUp(self):
super().setUp()
self.docker_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0,1,2,3,4,5,6,7')
self.command_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0,1,2,3,4,5,6,7')
self.task_cmd_builder = task_cmd_builder.InstructLoraCommandBuilder()
self.task_cmd_builder.task = 'instruct-lora'
@@ -39,9 +39,9 @@ class AdapterTest(test_util.TestBase):
self.task_cmd_builder.train_dataset = test_util.get_test_data_path(
'peft_train_sample.jsonl'
)
self.task_cmd_builder.train_split_name = 'train'
self.task_cmd_builder.instruct_column = 'input_text'
self.task_cmd_builder.template = 'llama3-text-bison'
self.task_cmd_builder.train_split = 'train'
self.task_cmd_builder.train_column = 'input_text'
self.task_cmd_builder.train_template = 'llama3-text-bison'
self.task_cmd_builder.gradient_accumulation_steps = 1
self.task_cmd_builder.lora_rank = 16
self.task_cmd_builder.lora_alpha = 32
@@ -87,8 +87,8 @@ class AdapterTest(test_util.TestBase):
def test_llama_adapters(self, model_name):
test_function_name = inspect.stack()[0][3]
self.setup_output_dir(f'{test_function_name}-{model_name}')
self.task_cmd_builder.pretrained_model_id = (
test_util.get_pretrained_model_id(model_name)
self.task_cmd_builder.pretrained_model_name_or_path = (
test_util.get_pretrained_model_name_or_path(model_name)
)
start_time = time.time()
self.assertEqual(self.run_cmd(), 0)
@@ -4,19 +4,81 @@
import os
import time
import unittest
from absl.testing import absltest
from absl.testing import parameterized
import instruct_lora_command_builder as task_cmd_builder
import test_util
class EvalConfigTest(test_util.TestBase):
def setUp(self):
super().setUp()
self.task_cmd_builder = task_cmd_builder.InstructLoraCommandBuilder()
self.task_cmd_builder.pretrained_model_name_or_path = (
test_util.get_pretrained_model_name_or_path('llama3.1-8b-hf')
)
self.task_cmd_builder.config_file = (
'vertex_vision_model_garden_peft/llama_fsdp_8gpu.yaml'
)
self.task_cmd_builder.task = 'instruct-lora'
self.task_cmd_builder.per_device_batch_size = 1
self.task_cmd_builder.gradient_accumulation_steps = 1
self.task_cmd_builder.lora_rank = 16
self.task_cmd_builder.lora_alpha = 32
self.task_cmd_builder.lora_dropout = 0.05
self.task_cmd_builder.learning_rate = 5e-5
self.task_cmd_builder.warmup_ratio = 0.01
self.task_cmd_builder.max_steps = 10
self.task_cmd_builder.save_steps = 1000
self.task_cmd_builder.logging_steps = 1
self.task_cmd_builder.gradient_checkpointing = True
self.task_cmd_builder.attn_implementation = 'flash_attention_2'
self.task_cmd_builder.example_packing = True
self.task_cmd_builder.train_dataset = 'mlabonne/guanaco-llama2'
self.task_cmd_builder.train_split = 'train'
self.task_cmd_builder.train_column = 'text'
self.task_cmd_builder.train_template = 'openassistant-guanaco'
self.task_cmd_builder.ckpt_dir = '/tmp/adapter'
self.task_cmd_builder.logging_dir = '/tmp/logs'
self.task_cmd_builder.eval_steps = 10
self.task_cmd_builder.eval_dataset = 'mlabonne/guanaco-llama2'
self.task_cmd_builder.eval_split = 'test'
self.task_cmd_builder.eval_column = 'text'
self.task_cmd_builder.eval_template = 'openassistant-guanaco'
@parameterized.named_parameters(
('all_eval_metric', 'loss,perplexity,bleu,google_bleu,rouge1', 0),
('invalid_metric', 'invalid_metric', 1),
('only_loss', 'loss', 0),
('perplexity_without_loss', 'perplexity,bleu', 0),
('unsupported_eval_metric', 'f1', 1),
)
def test_hf_eval_metrics(self, eval_metric_name, expected_return_code):
self.task_cmd_builder.eval_metric_name = eval_metric_name
self.assertEqual(self.run_cmd(), expected_return_code)
@parameterized.named_parameters(
('valid_best_model_metric', 'loss,perplexity', 'perplexity', 0),
('only_loss', None, 'loss', 0),
('invalid_best_model_metric', 'loss', 'invalid_metric', 1),
)
def test_metric_for_best_model(
self, eval_metric_name, metric_for_best_model, expected_return_code
):
self.task_cmd_builder.eval_metric_name = eval_metric_name
self.task_cmd_builder.metric_for_best_model = metric_for_best_model
self.assertEqual(self.run_cmd(), expected_return_code)
class GcsUploadDownloadTest(test_util.TestBase):
def setUp(self):
super().setUp()
self.docker_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0')
self.command_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0')
self.task_cmd_builder = task_cmd_builder.InstructLoraCommandBuilder()
self.task_cmd_builder.task = 'instruct-lora'
@@ -24,9 +86,9 @@ class GcsUploadDownloadTest(test_util.TestBase):
self.task_cmd_builder.train_dataset = test_util.get_test_data_path(
'peft_train_sample.jsonl'
)
self.task_cmd_builder.train_split_name = 'train'
self.task_cmd_builder.instruct_column = 'input_text'
self.task_cmd_builder.template = 'llama3-text-bison'
self.task_cmd_builder.train_split = 'train'
self.task_cmd_builder.train_column = 'input_text'
self.task_cmd_builder.train_template = 'llama3-text-bison'
self.task_cmd_builder.gradient_accumulation_steps = 1
self.task_cmd_builder.lora_rank = 16
self.task_cmd_builder.lora_alpha = 32
@@ -45,9 +107,11 @@ class GcsUploadDownloadTest(test_util.TestBase):
),
('llama2_7b_hf', 'NousResearch/Llama-2-7b-hf'),
)
def test_model_download_single_process(self, pretrained_model_id):
self.task_cmd_builder.pretrained_model_id = (
test_util.get_pretrained_model_id(pretrained_model_id)
def test_model_download_single_process(self, pretrained_model_name_or_path):
self.task_cmd_builder.pretrained_model_name_or_path = (
test_util.get_pretrained_model_name_or_path(
pretrained_model_name_or_path
)
)
start_time = time.time()
self.assertEqual(self.run_cmd(), 0)
@@ -61,24 +125,26 @@ class GcsUploadDownloadTest(test_util.TestBase):
),
('llama2_7b_hf', 'NousResearch/Llama-2-7b-hf'),
)
def test_model_download_multi_process(self, pretrained_model_id):
self.task_cmd_builder.pretrained_model_id = (
test_util.get_pretrained_model_id(pretrained_model_id)
def test_model_download_multi_process(self, pretrained_model_name_or_path):
self.task_cmd_builder.pretrained_model_name_or_path = (
test_util.get_pretrained_model_name_or_path(
pretrained_model_name_or_path
)
)
self.task_cmd_builder.config_file = (
'vertex_vision_model_garden_peft/llama_fsdp_8gpu.yaml'
)
self.docker_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0,1,2,3,4,5,6,7')
self.command_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0,1,2,3,4,5,6,7')
start_time = time.time()
self.assertEqual(self.run_cmd(), 0)
end_time = time.time()
self.assertLess(end_time - start_time, 5 * 60.0)
def test_70b_model_download(self):
self.task_cmd_builder.pretrained_model_id = (
'gs://vertex-model-garden-public-us/llama3/llama3-70b-hf'
def test_8b_model_download(self):
self.task_cmd_builder.pretrained_model_name_or_path = (
'gs://vertex-model-garden-public-us/llama3/llama3-8b-hf'
)
start_time = time.time()
self.assertEqual(self.run_cmd(), 0)
@@ -90,8 +156,8 @@ class GcsUploadDownloadTest(test_util.TestBase):
('merged-and-upload-to-gcs', 'gs://vmg-test-ttl-1y/tests/merged'),
)
def test_model_merge(self, output_dir):
self.task_cmd_builder.pretrained_model_id = (
test_util.get_pretrained_model_id('llama3.1-8b-hf')
self.task_cmd_builder.pretrained_model_name_or_path = (
test_util.get_pretrained_model_name_or_path('llama3.1-8b-hf')
)
ckpt_dir = os.path.join(
@@ -107,9 +173,13 @@ class GcsUploadDownloadTest(test_util.TestBase):
end_time = time.time()
self.assertLess(end_time - start_time, 5 * 60.0)
@unittest.skipIf(
not test_util.is_gpu_h100(),
'Skipping because this test is only for H100',
)
def test_model_fp8_conversion(self):
self.task_cmd_builder.pretrained_model_id = (
test_util.get_pretrained_model_id('llama3.1-8b-hf')
self.task_cmd_builder.pretrained_model_name_or_path = (
test_util.get_pretrained_model_name_or_path('llama3.1-8b-hf')
)
ckpt_dir = f'/tmp/output/output-{test_util.get_timestamp()}'
@@ -128,17 +198,17 @@ class GcsUploadDownloadTest(test_util.TestBase):
('merged-and-upload-to-gcs', 'gs://vmg-test-ttl-1y/tests/merged'),
)
def test_model_merge_and_upload_deepspeed(self, merged_model_dir):
self.task_cmd_builder.pretrained_model_id = (
test_util.get_pretrained_model_id('llama3.1-8b-hf')
self.task_cmd_builder.pretrained_model_name_or_path = (
test_util.get_pretrained_model_name_or_path('llama3.1-8b-hf')
)
self.task_cmd_builder.config_file = (
'vertex_vision_model_garden_peft/deepspeed_zero3_8gpu.yaml'
'vertex_vision_model_garden_peft/deepspeed_zero2_8gpu.yaml'
)
self.task_cmd_builder.merged_model_dir = os.path.join(
merged_model_dir, f'merged-{test_util.get_timestamp()}'
)
self.docker_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0,1,2,3,4,5,6,7')
self.command_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0,1,2,3,4,5,6,7')
start_time = time.time()
self.assertEqual(self.run_cmd(), 0)
end_time = time.time()
@@ -149,8 +219,8 @@ class GcsUploadDownloadTest(test_util.TestBase):
('save-multiple-times', 1),
)
def test_llama3_8b_save_and_merge_8_gpus_fsdp(self, save_steps):
self.task_cmd_builder.pretrained_model_id = (
test_util.get_pretrained_model_id('llama3.1-8b-hf')
self.task_cmd_builder.pretrained_model_name_or_path = (
test_util.get_pretrained_model_name_or_path('llama3.1-8b-hf')
)
self.task_cmd_builder.save_steps = save_steps
self.task_cmd_builder.max_steps = 3
@@ -159,7 +229,7 @@ class GcsUploadDownloadTest(test_util.TestBase):
)
self.task_cmd_builder.merged_model_dir = '/tmp/merged'
self.docker_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0,1,2,3,4,5,6,7')
self.command_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0,1,2,3,4,5,6,7')
start_time = time.time()
self.assertEqual(self.run_cmd(), 0)
end_time = time.time()
@@ -171,7 +241,7 @@ class TemplateAndDataStatsTest(test_util.TestBase):
def setUp(self):
super().setUp()
self.docker_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0')
self.command_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0')
self.task_cmd_builder = task_cmd_builder.InstructLoraCommandBuilder()
self.task_cmd_builder.task = 'instruct-lora'
@@ -187,35 +257,42 @@ class TemplateAndDataStatsTest(test_util.TestBase):
self.task_cmd_builder.attn_implementation = 'flash_attention_2'
self.task_cmd_builder.ckpt_dir = '/tmp'
def test_openai_chat_template(self):
self.task_cmd_builder.pretrained_model_id = (
test_util.get_pretrained_model_id('llama3.1-8b-hf')
@parameterized.named_parameters(
('multi-chat-string-content', 'openai-multi-chat-example-data.jsonl'),
(
'multi-chat-array-content',
'openai-multi-chat-example-data-array-content.jsonl',
),
)
def test_openai_chat_template(self, example_dataset):
self.task_cmd_builder.pretrained_model_name_or_path = (
test_util.get_pretrained_model_name_or_path('llama3.1-8b-hf')
)
self.task_cmd_builder.train_dataset = test_util.get_test_data_path(
'openai-multi-chat-example-data.jsonl'
example_dataset
)
self.task_cmd_builder.train_split_name = 'train'
self.task_cmd_builder.instruct_column = 'messages'
self.task_cmd_builder.template = 'llama3'
self.task_cmd_builder.train_split = 'train'
self.task_cmd_builder.train_column = 'messages'
self.task_cmd_builder.train_template = 'openai-chat'
self.assertEqual(self.run_cmd(), 0)
def test_openai_completion_template(self):
self.task_cmd_builder.pretrained_model_id = (
test_util.get_pretrained_model_id('llama3.1-8b-hf')
self.task_cmd_builder.pretrained_model_name_or_path = (
test_util.get_pretrained_model_name_or_path('llama3.1-8b-hf')
)
self.task_cmd_builder.train_dataset = test_util.get_test_data_path(
'openai-completion-example-data.jsonl'
)
self.task_cmd_builder.train_split_name = 'train'
self.task_cmd_builder.instruct_column = 'prompt'
self.task_cmd_builder.template = 'openai-completion'
self.task_cmd_builder.train_split = 'train'
self.task_cmd_builder.train_column = 'prompt'
self.task_cmd_builder.train_template = 'openai-completion'
self.assertEqual(self.run_cmd(), 0)
def test_data_stats_chat_template(self):
self.task_cmd_builder.pretrained_model_id = (
test_util.get_pretrained_model_id('llama3.1-8b-hf')
self.task_cmd_builder.pretrained_model_name_or_path = (
test_util.get_pretrained_model_name_or_path('llama3.1-8b-hf')
)
self.task_cmd_builder.config_file = (
'vertex_vision_model_garden_peft/llama_fsdp_8gpu.yaml'
@@ -223,17 +300,17 @@ class TemplateAndDataStatsTest(test_util.TestBase):
self.task_cmd_builder.train_dataset = test_util.get_test_data_path(
'openai-multi-chat-example-data.jsonl'
)
self.task_cmd_builder.train_split_name = 'train'
self.task_cmd_builder.instruct_column = 'messages'
self.task_cmd_builder.template = 'llama3'
self.task_cmd_builder.train_split = 'train'
self.task_cmd_builder.train_column = 'messages'
self.task_cmd_builder.train_template = 'llama3'
self.task_cmd_builder.tuning_data_stats_file = '/tmp/data-stats.json'
self.docker_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0,1,2,3,4,5,6,7')
self.command_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0,1,2,3,4,5,6,7')
self.assertEqual(self.run_cmd(), 0)
def test_data_stats_completion_template(self):
self.task_cmd_builder.pretrained_model_id = (
test_util.get_pretrained_model_id('llama3.1-8b-hf')
self.task_cmd_builder.pretrained_model_name_or_path = (
test_util.get_pretrained_model_name_or_path('llama3.1-8b-hf')
)
self.task_cmd_builder.config_file = (
'vertex_vision_model_garden_peft/llama_fsdp_8gpu.yaml'
@@ -241,12 +318,12 @@ class TemplateAndDataStatsTest(test_util.TestBase):
self.task_cmd_builder.train_dataset = test_util.get_test_data_path(
'openai-completion-example-data.jsonl'
)
self.task_cmd_builder.train_split_name = 'train'
self.task_cmd_builder.instruct_column = 'prompt'
self.task_cmd_builder.template = 'openai-completion'
self.task_cmd_builder.train_split = 'train'
self.task_cmd_builder.train_column = 'prompt'
self.task_cmd_builder.train_template = 'openai-completion'
self.task_cmd_builder.tuning_data_stats_file = '/tmp/data-stats.json'
self.docker_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0,1,2,3,4,5,6,7')
self.command_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0,1,2,3,4,5,6,7')
self.assertEqual(self.run_cmd(), 0)
@@ -255,7 +332,7 @@ class TargetModulesTest(test_util.TestBase):
def setUp(self):
super().setUp()
self.docker_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0')
self.command_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0')
self.task_cmd_builder = task_cmd_builder.InstructLoraCommandBuilder()
self.task_cmd_builder.task = 'instruct-lora'
@@ -263,9 +340,9 @@ class TargetModulesTest(test_util.TestBase):
self.task_cmd_builder.train_dataset = test_util.get_test_data_path(
'peft_train_sample.jsonl'
)
self.task_cmd_builder.train_split_name = 'train'
self.task_cmd_builder.instruct_column = 'input_text'
self.task_cmd_builder.template = 'llama3-text-bison'
self.task_cmd_builder.train_split = 'train'
self.task_cmd_builder.train_column = 'input_text'
self.task_cmd_builder.train_template = 'llama3-text-bison'
self.task_cmd_builder.gradient_accumulation_steps = 1
self.task_cmd_builder.lora_rank = 16
self.task_cmd_builder.lora_alpha = 32
@@ -278,8 +355,8 @@ class TargetModulesTest(test_util.TestBase):
self.task_cmd_builder.ckpt_dir = '/tmp'
def test_target_modules(self):
self.task_cmd_builder.pretrained_model_id = (
test_util.get_pretrained_model_id('llama3.1-8b-hf')
self.task_cmd_builder.pretrained_model_name_or_path = (
test_util.get_pretrained_model_name_or_path('llama3.1-8b-hf')
)
self.task_cmd_builder.target_modules = 'q_proj, v_proj, k_proj'
@@ -43,9 +43,9 @@ class TrainerThroughputTest(test_util.TestBase):
self.task_cmd_builder.attn_implementation = 'flash_attention_2'
self.task_cmd_builder.example_packing = True
self.task_cmd_builder.train_dataset = 'mlabonne/guanaco-llama2-1k'
self.task_cmd_builder.train_split_name = 'train'
self.task_cmd_builder.instruct_column = 'text'
self.task_cmd_builder.template = 'openassistant-guanaco'
self.task_cmd_builder.train_split = 'train'
self.task_cmd_builder.train_column = 'text'
self.task_cmd_builder.train_template = 'openassistant-guanaco'
self.task_cmd_builder.ckpt_dir = '/tmp/adapter'
self.task_cmd_builder.logging_dir = '/tmp/logs'
@@ -54,23 +54,24 @@ class TrainerThroughputTest(test_util.TestBase):
if ret != 0:
with open(self.task_cmd_builder.benchmark_out_file, 'a') as f:
max_seq_length = self.task_cmd_builder.max_seq_length
f.write(f'{max_seq_length/1024.0:.1f}k | failed | n/a\n')
f.write(f'{max_seq_length/1024.0:.1f} | failed | n/a\n')
return ret
@parameterized.product(
model_name=[
'llama3-70b-hf',
'llama3.1-8b-hf',
'llama3.1-70b-hf',
'Mistral-7B-v0.1',
'Mixtral-8x7B-v0.1',
'Gemma2-9b-it',
'gemma-2-9b-it',
'Qwen2.5-32B-Instruct',
],
precision=['4bit', '8bit', 'bfloat16'],
max_seq_length=list(range(4 * 1024, 24 * 1024 + 1, 4 * 1024)),
)
def test_model_single_gpu(self, model_name, precision, max_seq_length):
self.task_cmd_builder.pretrained_model_id = (
test_util.get_pretrained_model_id(model_name)
self.task_cmd_builder.pretrained_model_name_or_path = (
test_util.get_pretrained_model_name_or_path(model_name)
)
self.task_cmd_builder.max_seq_length = max_seq_length
self.task_cmd_builder.load_precision = precision
@@ -78,29 +79,30 @@ class TrainerThroughputTest(test_util.TestBase):
self.test_suite_output_dir, f'bm_{model_name}_{precision}.txt'
)
self.docker_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0')
self.command_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0')
self.assertEqual(self.run_cmd_and_handle_failure(), 0)
@parameterized.product(
model_name=[
'llama3-70b-hf',
'llama3.1-8b-hf',
'llama3.1-70b-hf',
'Mistral-7B-v0.1',
'Mixtral-8x7B-v0.1',
'Gemma2-9b-it',
'gemma-2-9b-it',
'Qwen2.5-32B-Instruct',
],
precision=['4bit', '8bit', 'bfloat16'],
max_seq_length=list(range(4 * 1024, 24 * 1024 + 1, 4 * 1024)),
num_gpus=[8],
config=['deepspeed_zero2', 'deepspeed_zero3'],
config=['deepspeed_zero2'],
)
def test_model_multi_gpu_deepspeed(
self, model_name, precision, max_seq_length, num_gpus, config
):
self.assertTrue(num_gpus == 4 or num_gpus == 8)
self.task_cmd_builder.pretrained_model_id = (
test_util.get_pretrained_model_id(model_name)
self.task_cmd_builder.pretrained_model_name_or_path = (
test_util.get_pretrained_model_name_or_path(model_name)
)
self.task_cmd_builder.max_seq_length = max_seq_length
self.task_cmd_builder.load_precision = precision
@@ -112,14 +114,18 @@ class TrainerThroughputTest(test_util.TestBase):
self.task_cmd_builder.config_file = (
f'vertex_vision_model_garden_peft/{config}_{num_gpus}gpu.yaml'
)
self.docker_builder.add_env_var(
self.command_builder.add_env_var(
'CUDA_VISIBLE_DEVICES', ','.join([str(x) for x in range(0, num_gpus)])
)
self.assertEqual(self.run_cmd_and_handle_failure(), 0)
@parameterized.product(
model_name=['llama3.1-70b-hf'],
model_name=[
'llama3.1-8b-hf',
'llama3.1-70b-hf',
'Qwen2.5-32B-Instruct',
],
precision=['4bit', '8bit', 'bfloat16'],
max_seq_length=list(range(4 * 1024, 24 * 1024 + 1, 4 * 1024)),
num_gpus=[8],
@@ -127,8 +133,8 @@ class TrainerThroughputTest(test_util.TestBase):
def test_model_multi_gpu_fsdp_lora(
self, model_name, precision, max_seq_length, num_gpus
):
self.task_cmd_builder.pretrained_model_id = (
test_util.get_pretrained_model_id(model_name)
self.task_cmd_builder.pretrained_model_name_or_path = (
test_util.get_pretrained_model_name_or_path(model_name)
)
self.task_cmd_builder.max_seq_length = max_seq_length
self.task_cmd_builder.load_precision = precision
@@ -136,18 +142,108 @@ class TrainerThroughputTest(test_util.TestBase):
self.test_suite_output_dir,
f'bm_fsdp_{num_gpus}gpu_{model_name}_{precision}.txt',
)
self.task_cmd_builder.config_file = (
'vertex_vision_model_garden_peft/llama_fsdp_8gpu.yaml'
)
if 'llama' in model_name.lower():
self.task_cmd_builder.config_file = (
'vertex_vision_model_garden_peft/llama2_fsdp_8gpu.yaml'
)
elif 'qwen' in model_name.lower():
self.task_cmd_builder.config_file = (
'vertex_vision_model_garden_peft/qwen2_fsdp_8gpu.yaml'
)
else:
self.fail(f'Unsupported model: {model_name}')
self.docker_builder.add_env_var(
self.command_builder.add_env_var(
'CUDA_VISIBLE_DEVICES', ','.join([str(x) for x in range(0, num_gpus)])
)
self.assertEqual(self.run_cmd_and_handle_failure(), 0)
@parameterized.product(
model_name=['llama3.1-70b-hf'],
model_name=['llama3.1-8b-hf', 'llama3.1-70b-hf'],
precision=['4bit', 'bfloat16'],
max_seq_length=list(range(4 * 1024, 24 * 1024 + 1, 4 * 1024)),
config=['deepspeed_zero2', 'fsdp'],
)
def test_peft_train_image_automated_test_llama(
self, model_name, precision, max_seq_length, config
):
num_gpus = 8
self.task_cmd_builder.pretrained_model_name_or_path = (
test_util.get_pretrained_model_name_or_path(model_name)
)
self.task_cmd_builder.max_seq_length = max_seq_length
self.task_cmd_builder.load_precision = precision
benchmark_out_file = os.path.join(
self.test_suite_output_dir,
f'bm_{config}_{num_gpus}gpu_{model_name}_{precision}.txt',
)
self.task_cmd_builder.benchmark_out_file = benchmark_out_file
if config == 'fsdp':
self.task_cmd_builder.config_file = (
f'vertex_vision_model_garden_peft/llama_{config}_{num_gpus}gpu.yaml'
)
else:
self.task_cmd_builder.config_file = (
f'vertex_vision_model_garden_peft/{config}_{num_gpus}gpu.yaml'
)
self.command_builder.add_env_var(
'CUDA_VISIBLE_DEVICES', ','.join([str(x) for x in range(0, num_gpus)])
)
self.run_cmd_and_handle_failure()
if test_util.is_gpu_h100():
self.assertEqual(
test_util.check_benchmark_results(
benchmark_out_file, 'llama', 10.0, max_seq_length
),
True,
)
@parameterized.product(
model_name=['gemma-2-2b-it', 'gemma-2-9b-it', 'gemma-2-27b-it'],
precision=['4bit', 'bfloat16'],
max_seq_length=list(range(4 * 1024, 24 * 1024 + 1, 4 * 1024)),
config=['deepspeed_zero2', 'deepspeed_zero3', 'fsdp'],
)
def test_peft_train_image_automated_test_gemma(
self, model_name, precision, max_seq_length, config
):
num_gpus = 8
self.task_cmd_builder.pretrained_model_name_or_path = (
test_util.get_pretrained_model_name_or_path(model_name)
)
self.task_cmd_builder.attn_implementation = 'eager'
self.task_cmd_builder.max_seq_length = max_seq_length
self.task_cmd_builder.load_precision = precision
benchmark_out_file = os.path.join(
self.test_suite_output_dir,
f'bm_{config}_{num_gpus}gpu_{model_name}_{precision}.txt',
)
self.task_cmd_builder.benchmark_out_file = benchmark_out_file
if config == 'fsdp':
self.task_cmd_builder.config_file = (
f'vertex_vision_model_garden_peft/gemma2_{config}_{num_gpus}gpu.yaml'
)
else:
self.task_cmd_builder.config_file = (
f'vertex_vision_model_garden_peft/{config}_{num_gpus}gpu.yaml'
)
self.command_builder.add_env_var(
'CUDA_VISIBLE_DEVICES', ','.join([str(x) for x in range(0, num_gpus)])
)
self.run_cmd_and_handle_failure()
if test_util.is_gpu_h100():
self.assertEqual(
test_util.check_benchmark_results(
benchmark_out_file, 'gemma', 10.0, max_seq_length
),
True,
)
@parameterized.product(
model_name=['llama3.1-8b-hf', 'llama3.1-70b-hf'],
precision=['bfloat16'],
max_seq_length=list(range(4 * 1024, 24 * 1024 + 1, 4 * 1024)),
num_gpus=[8],
@@ -155,8 +251,8 @@ class TrainerThroughputTest(test_util.TestBase):
def test_model_multi_gpu_fsdp_full_finetuning(
self, model_name, precision, max_seq_length, num_gpus
):
self.task_cmd_builder.pretrained_model_id = (
test_util.get_pretrained_model_id(model_name)
self.task_cmd_builder.pretrained_model_name_or_path = (
test_util.get_pretrained_model_name_or_path(model_name)
)
self.task_cmd_builder.max_seq_length = max_seq_length
self.task_cmd_builder.load_precision = precision
@@ -169,7 +265,7 @@ class TrainerThroughputTest(test_util.TestBase):
)
self.task_cmd_builder.enable_peft = False
self.docker_builder.add_env_var(
self.command_builder.add_env_var(
'CUDA_VISIBLE_DEVICES', ','.join([str(x) for x in range(0, num_gpus)])
)
@@ -0,0 +1,209 @@
# pylint: disable=missing-function-docstring
# pylint: disable=missing-class-docstring
"""Tests to make sure trained model achieves decent quality.
Right now, the metric is loss decreasing and we'll eyeball the TB graphs.
"""
import os
from absl.testing import absltest
from absl.testing import parameterized
import instruct_lora_command_builder as task_cmd_builder
import test_util
class TrainedModelQualityTest(test_util.TestBase):
_TEST_OUTPUT_DIR = os.path.expanduser('~/output')
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.test_suite_output_dir = os.path.join(
cls._TEST_OUTPUT_DIR,
os.path.splitext(os.path.basename(__file__))[0],
cls.__class__.__name__,
)
def setUp(self):
super().setUp()
self.task_cmd_builder = task_cmd_builder.InstructLoraCommandBuilder()
self.task_cmd_builder.task = 'instruct-lora'
self.task_cmd_builder.eval_metric_name = 'loss'
self.task_cmd_builder.per_device_batch_size = 1
self.task_cmd_builder.gradient_accumulation_steps = 8
self.task_cmd_builder.lora_rank = 16
self.task_cmd_builder.lora_alpha = 32
self.task_cmd_builder.lora_dropout = 0.05
self.task_cmd_builder.learning_rate = 5e-5
self.task_cmd_builder.num_train_epochs = 2.0
self.task_cmd_builder.warmup_ratio = 0.01
self.task_cmd_builder.max_steps = -1
self.task_cmd_builder.save_steps = 10
self.task_cmd_builder.eval_steps = 10
self.task_cmd_builder.max_seq_length = 4096
self.task_cmd_builder.load_precision = '4bit'
self.task_cmd_builder.gradient_checkpointing = True
self.task_cmd_builder.input_masking = True
self.task_cmd_builder.attn_implementation = 'flash_attention_2'
self.task_cmd_builder.report_to = 'tensorboard'
def setup_output_dir(self, testcase_name: str):
testcase_output_dir = os.path.join(
self.test_suite_output_dir, testcase_name
)
self.task_cmd_builder.ckpt_dir = os.path.join(
testcase_output_dir, 'adapter'
)
self.task_cmd_builder.logging_dir = os.path.join(
testcase_output_dir, 'logs'
)
self.task_cmd_builder.merged_model_dir = os.path.join(
testcase_output_dir, 'merged'
)
@parameterized.named_parameters(
('llama3-8b', 'llama3-8b-hf'),
('llama3.1-8b', 'llama3.1-8b-hf'),
)
def test_8b_model_deepspeed(self, model_name):
self.setup_output_dir(f'test_deepspeed_{model_name}')
self.task_cmd_builder.pretrained_model_name_or_path = (
test_util.get_pretrained_model_name_or_path(model_name)
)
self.task_cmd_builder.train_dataset = test_util.get_test_data_path(
'peft_train_sample.jsonl'
)
self.task_cmd_builder.train_split = 'train'
self.task_cmd_builder.train_column = 'input_text'
self.task_cmd_builder.train_template = 'llama3-text-bison'
self.task_cmd_builder.eval_dataset = test_util.get_test_data_path(
'peft_eval_sample.jsonl'
)
self.task_cmd_builder.eval_split = 'train'
self.task_cmd_builder.eval_column = self.task_cmd_builder.train_column
self.task_cmd_builder.eval_template = self.task_cmd_builder.train_template
self.command_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0')
self.assertEqual(self.run_cmd(), 0)
@parameterized.named_parameters(
('llama3-70b', 'llama3-70b-hf'),
('llama3.1-70b', 'llama3.1-70b-hf'),
)
def test_70b_model_deepspeed(self, model_name):
self.setup_output_dir(f'test_deepspeed_{model_name}')
self.task_cmd_builder.pretrained_model_name_or_path = (
test_util.get_pretrained_model_name_or_path(model_name)
)
self.task_cmd_builder.config_file = (
'vertex_vision_model_garden_peft/deepspeed_zero2_8gpu.yaml'
)
self.task_cmd_builder.train_dataset = 'timdettmers/openassistant-guanaco'
self.task_cmd_builder.train_split = 'train'
self.task_cmd_builder.train_column = 'text'
self.task_cmd_builder.train_template = 'openassistant-guanaco'
self.task_cmd_builder.eval_dataset = self.task_cmd_builder.train_dataset
self.task_cmd_builder.eval_split = 'test'
self.task_cmd_builder.eval_column = self.task_cmd_builder.train_column
self.task_cmd_builder.eval_template = self.task_cmd_builder.train_template
self.command_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0,1,2,3,4,5,6,7')
self.assertEqual(self.run_cmd(), 0)
@parameterized.named_parameters(
('llama3-70b', 'llama3-70b-hf'),
('llama3.1-70b', 'llama3.1-70b-hf'),
)
def test_70b_model_fsdp(self, model_name):
self.setup_output_dir(f'test_fsdp_{model_name}')
self.task_cmd_builder.pretrained_model_name_or_path = (
test_util.get_pretrained_model_name_or_path(model_name)
)
self.task_cmd_builder.config_file = (
'vertex_vision_model_garden_peft/llama_fsdp_8gpu.yaml'
)
self.task_cmd_builder.train_dataset = 'timdettmers/openassistant-guanaco'
self.task_cmd_builder.train_split = 'train'
self.task_cmd_builder.train_column = 'text'
self.task_cmd_builder.train_template = 'openassistant-guanaco'
self.task_cmd_builder.eval_dataset = self.task_cmd_builder.train_dataset
self.task_cmd_builder.eval_split = 'test'
self.task_cmd_builder.eval_column = self.task_cmd_builder.train_column
self.task_cmd_builder.eval_template = self.task_cmd_builder.train_template
self.command_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0,1,2,3,4,5,6,7')
self.assertEqual(self.run_cmd(), 0)
@parameterized.named_parameters(
('Qwen2.5-32B-Instruct', 'Qwen2.5-32B-Instruct'),
)
def test_qwen_model_deepspeed(self, model_name):
self.setup_output_dir(f'test_deepspeed_{model_name}')
self.task_cmd_builder.pretrained_model_name_or_path = model_name
self.task_cmd_builder.config_file = (
'vertex_vision_model_garden_peft/deepspeed_zero2_8gpu.yaml'
)
self.task_cmd_builder.train_dataset = test_util.get_test_data_path(
'llama-tuning-test/opposite-examples-train.jsonl'
)
self.task_cmd_builder.train_split = 'train'
self.task_cmd_builder.train_column = 'messages'
self.task_cmd_builder.train_template = 'qwen2_5'
self.task_cmd_builder.eval_dataset = test_util.get_test_data_path(
'llama-tuning-test/opposite-examples-eval.jsonl'
)
self.task_cmd_builder.eval_split = 'train'
self.task_cmd_builder.eval_column = self.task_cmd_builder.train_column
self.task_cmd_builder.eval_template = self.task_cmd_builder.train_template
self.command_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0,1,2,3,4,5,6,7')
# Note(lavrai): The following parameters are needed for the opposite-word
# dataset to converge properly.
self.task_cmd_builder.gradient_accumulation_steps = 1
self.task_cmd_builder.num_train_epochs = 10.0
self.task_cmd_builder.logging_steps = 1
self.assertEqual(self.run_cmd(), 0)
@parameterized.named_parameters(
('Qwen2.5-32B-Instruct', 'Qwen2.5-32B-Instruct'),
)
def test_qwen_model_fsdp(self, model_name):
self.setup_output_dir(f'test_fsdp_{model_name}')
self.task_cmd_builder.pretrained_model_name_or_path = (
test_util.get_pretrained_model_name_or_path(model_name)
)
self.task_cmd_builder.config_file = (
'vertex_vision_model_garden_peft/qwen2_fsdp_8gpu.yaml'
)
self.task_cmd_builder.train_dataset = test_util.get_test_data_path(
'llama-tuning-test/opposite-examples-train.jsonl'
)
self.task_cmd_builder.train_split = 'train'
self.task_cmd_builder.train_column = 'messages'
self.task_cmd_builder.train_template = 'qwen2_5'
self.task_cmd_builder.eval_dataset = test_util.get_test_data_path(
'llama-tuning-test/opposite-examples-eval.jsonl'
)
self.task_cmd_builder.eval_split = 'train'
self.task_cmd_builder.eval_column = self.task_cmd_builder.train_column
self.task_cmd_builder.eval_template = self.task_cmd_builder.train_template
self.command_builder.add_env_var('CUDA_VISIBLE_DEVICES', '0,1,2,3,4,5,6,7')
# Note(lavrai): The following parameters are needed for the opposite-word
# dataset to converge properly.
self.task_cmd_builder.gradient_accumulation_steps = 1
self.task_cmd_builder.num_train_epochs = 10.0
self.task_cmd_builder.logging_steps = 1
self.assertEqual(self.run_cmd(), 0)
if __name__ == '__main__':
absltest.main()
@@ -31,7 +31,7 @@ class ValidateDatasetWithTemplateTest(test_util.TestBase):
dict(
testcase_name="out_of_range_rows",
validate_top_k_rows=100000,
expected_result=1,
expected_result=0,
),
)
def test_validate_dataset_with_template_top_k_rows(
@@ -40,8 +40,8 @@ class ValidateDatasetWithTemplateTest(test_util.TestBase):
expected_result,
):
self.task_cmd_builder.dataset_name = "timdettmers/openassistant-guanaco"
self.task_cmd_builder.train_split_name = "train"
self.task_cmd_builder.instruct_column_in_dataset = "text"
self.task_cmd_builder.train_split = "train"
self.task_cmd_builder.train_column = "text"
self.task_cmd_builder.template = (
"gs://cloud-nas-260507-tmp-20240724/openassistant-guanaco.json"
)
@@ -79,8 +79,8 @@ class ValidateDatasetWithTemplateTest(test_util.TestBase):
expected_result,
):
self.task_cmd_builder.dataset_name = "timdettmers/openassistant-guanaco"
self.task_cmd_builder.train_split_name = "train"
self.task_cmd_builder.instruct_column_in_dataset = "text"
self.task_cmd_builder.train_split = "train"
self.task_cmd_builder.train_column = "text"
self.task_cmd_builder.template = (
"gs://cloud-nas-260507-tmp-20240724/openassistant-guanaco.json"
)
@@ -92,6 +92,32 @@ class ValidateDatasetWithTemplateTest(test_util.TestBase):
result = self.run_cmd()
self.assertEqual(result, expected_result)
@parameterized.named_parameters(
dict(
testcase_name="small_max_seq_length",
max_seq_length=10,
),
dict(
testcase_name="large_max_seq_length",
max_seq_length=1024,
),
)
def test_validate_dataset_with_template_max_seq_length(
self,
max_seq_length,
):
self.task_cmd_builder.dataset_name = "timdettmers/openassistant-guanaco"
self.task_cmd_builder.train_split = "train"
self.task_cmd_builder.train_column = "text"
self.task_cmd_builder.template = (
"gs://cloud-nas-260507-tmp-20240724/openassistant-guanaco.json"
)
self.task_cmd_builder.max_seq_length = max_seq_length
self.task_cmd_builder.validate_k_rows_of_dataset = None
self.task_cmd_builder.use_multiprocessing = True
result = self.run_cmd()
self.assertEqual(result, 0)
@parameterized.named_parameters(
dict(
testcase_name="invalid_default_input_column",
@@ -204,8 +230,8 @@ class ValidateDatasetWithTemplateTest(test_util.TestBase):
expected_result,
):
self.task_cmd_builder.dataset_name = dataset_name
self.task_cmd_builder.train_split_name = split
self.task_cmd_builder.instruct_column_in_dataset = input_column
self.task_cmd_builder.train_split = split
self.task_cmd_builder.train_column = input_column
self.task_cmd_builder.template = template
self.task_cmd_builder.validate_percentage_of_dataset = (
validate_percentage_of_dataset
@@ -311,8 +337,8 @@ class ValidateDatasetWithTemplateTest(test_util.TestBase):
expected_result,
):
self.task_cmd_builder.dataset_name = dataset_name
self.task_cmd_builder.train_split_name = "train"
self.task_cmd_builder.instruct_column_in_dataset = "text"
self.task_cmd_builder.train_split = "train"
self.task_cmd_builder.train_column = "text"
self.task_cmd_builder.template = template
self.task_cmd_builder.validate_percentage_of_dataset = (
validate_percentage_of_dataset
@@ -10,8 +10,9 @@ class ValidateDatasetWithTemplateCommandBuilder:
self._task = None
self._template = None
self._dataset_name = None
self._train_split_name = None
self._instruct_column_in_dataset = None
self._train_split = None
self._train_column = None
self._max_seq_length = None
self._use_multiprocessing = None
self._validate_k_rows_of_dataset = None
self._validate_percentage_of_dataset = None
@@ -41,20 +42,28 @@ class ValidateDatasetWithTemplateCommandBuilder:
self._dataset_name = val
@property
def train_split_name(self):
return self._train_split_name
def train_split(self):
return self._train_split
@train_split_name.setter
def train_split_name(self, val: str):
self._train_split_name = val
@train_split.setter
def train_split(self, val: str):
self._train_split = val
@property
def instruct_column_in_dataset(self):
return self._instruct_column_in_dataset
def train_column(self):
return self._train_column
@instruct_column_in_dataset.setter
def instruct_column_in_dataset(self, val: str):
self._instruct_column_in_dataset = val
@train_column.setter
def train_column(self, val: str):
self._train_column = val
@property
def max_seq_length(self):
return self._max_seq_length
@max_seq_length.setter
def max_seq_length(self, val: int):
self._max_seq_length = val
@property
def use_multiprocessing(self):
@@ -8,16 +8,18 @@ environment. Otherwise, `python3` is used.
"""
import argparse
import json
import os
from collections.abc import MutableSequence, Sequence
import multiprocessing
import subprocess
from typing import List, Optional, Sequence
import sys
from absl import app
from absl import flags
from absl import logging
from util import dataset_validation_util
from util import cluster_spec
from vertex_vision_model_garden_peft.train.vmg import utils
from util import constants
from util import gcs_syncer
from util import hypertune_utils
@@ -37,20 +39,21 @@ _TASK_TO_SCRIPT = {
constants.INSTRUCT_LORA: (
'vertex_vision_model_garden_peft/train/vmg/instruct_lora.py'
),
constants.MERGE_CAUSAL_LANGUAGE_MODEL_LORA: 'vertex_vision_model_garden_peft/train/vmg/merge_causal_language_model_lora.py',
constants.QUANTIZE_MODEL: (
'vertex_vision_model_garden_peft/train/vmg/quantize_model.py'
constants.MERGE_CAUSAL_LANGUAGE_MODEL_LORA: (
'vertex_vision_model_garden_peft/train/vmg/merge_causal_language_model_lora.py'
),
constants.SEQUENCE_CLASSIFICATION_LORA: 'vertex_vision_model_garden_peft/train/vmg/sequence_classification_lora.py',
constants.VALIDATE_DATASET_WITH_TEMPLATE: 'vertex_vision_model_garden_peft/train/vmg/validate_dataset_with_template.py',
constants.VALIDATE_DATASET_WITH_TEMPLATE: (
'vertex_vision_model_garden_peft/train/vmg/validate_dataset_with_template.py'
),
constants.RUN_TESTS: 'vertex_vision_model_garden_peft/tests/run_tests.py',
}
def launch_script_cmd(
script: str,
config_file: Optional[str],
config_file: str | None,
accelerate_args: argparse.Namespace = argparse.Namespace(),
) -> List[str]:
) -> MutableSequence[str]:
"""Returns the command to launch the script."""
if config_file:
cmd = [
@@ -69,59 +72,23 @@ def launch_script_cmd(
def _get_accelerate_args() -> argparse.Namespace:
"""Returns the accelerate args."""
# For the format of the cluster spec, see
# https://cloud.google.com/vertex-ai/docs/training/distributed-training#cluster-spec-format # pylint: disable=line-too-long
cluster_spec = os.getenv('CLUSTER_SPEC', default=None)
if not cluster_spec:
return argparse.Namespace()
logging.info('CLUSTER_SPEC: %s', cluster_spec)
cluster_data = json.loads(cluster_spec)
if (
'workerpool1' not in cluster_data['cluster']
or not cluster_data['cluster']['workerpool1']
):
return argparse.Namespace()
# Get primary node info
primary_node = cluster_data['cluster']['workerpool0'][0]
logging.info('primary node: %s', primary_node)
primary_node_addr, primary_node_port = primary_node.split(':')
logging.info('primary node address: %s', primary_node_addr)
logging.info('primary node port: %s', primary_node_port)
# Determine node rank of this machine
workerpool = cluster_data['task']['type']
if workerpool == 'workerpool0':
node_rank = 0
elif workerpool == 'workerpool1':
# Add 1 for the primary node, since `index` is the index of workerpool1.
node_rank = cluster_data['task']['index'] + 1
else:
raise ValueError(
'Only workerpool0 and workerpool1 are supported. Unknown workerpool:'
f' {workerpool}'
)
logging.info('node rank: %s', node_rank)
# Calculate total nodes
num_worker_nodes = len(cluster_data['cluster']['workerpool1'])
num_nodes = num_worker_nodes + 1 # Add 1 for the primary node
logging.info('num nodes: %s', num_nodes)
primary_node_addr, primary_node_port, node_rank, num_nodes = (
cluster_spec.get_cluster_spec()
)
accelerate_args = argparse.Namespace()
accelerate_args.machine_rank = node_rank
accelerate_args.num_machines = num_nodes
accelerate_args.main_process_ip = primary_node_addr
accelerate_args.main_process_port = primary_node_port
accelerate_args.max_restarts = 0
accelerate_args.monitor_interval = 120
if num_nodes > 1:
accelerate_args.machine_rank = node_rank
accelerate_args.num_machines = num_nodes
accelerate_args.main_process_ip = primary_node_addr
accelerate_args.main_process_port = primary_node_port
accelerate_args.max_restarts = 0
accelerate_args.monitor_interval = 120
return accelerate_args
def _append_args_to_command_in_place(
args: argparse.Namespace, command: List[str]
args: argparse.Namespace, command: MutableSequence[str]
):
for key, value in vars(args).items():
# If not specified, skip.
@@ -129,15 +96,25 @@ def _append_args_to_command_in_place(
command.append(f'--{key}={value}')
def _get_train_cmd_and_maybe_merge_cmd(
task: str, config_file: str, unknown: Sequence[str]
def _get_train_and_maybe_merge_cmd_and_dirs_to_sync(
task_type: str, config_file: str, unknown: Sequence[str]
) -> Sequence[Sequence[str]]:
"""Returns the training command and maybe the merge command if applicable."""
"""Returns the training and merge command(if applicable) and dirs to sync.
Args:
task_type: The task type.
config_file: The accelerate config file path.
unknown: The unknown args which are not recognised by the parser.
Returns:
The bash commands to execute and the directories to sync.
"""
dirs_to_sync = []
# Only populated when multi-node is used.
accelerate_args = _get_accelerate_args()
node_rank = getattr(accelerate_args, 'machine_rank', 0)
training_cmd = launch_script_cmd(
_TASK_TO_SCRIPT[task],
_TASK_TO_SCRIPT[task_type],
config_file,
accelerate_args=accelerate_args,
)
@@ -152,17 +129,30 @@ def _get_train_cmd_and_maybe_merge_cmd(
dataset_validation_util.force_gcs_fuse_path(training_args.output_dir)
)
local_output_dir, gcs_output_dir = gcs_syncer.manage_sync_path(
training_args.output_dir, node_rank
)
training_args.output_dir = local_output_dir
if gcs_syncer.is_gcs_or_gcsfuse_path(gcs_output_dir):
dirs_to_sync.append((local_output_dir, gcs_output_dir))
# Merge only flags.
merge_parser = argparse.ArgumentParser()
merge_parser.add_argument('--merge_model_precision_mode')
merge_parser.add_argument('--executor_input')
merge_parser.add_argument('--restrict_model_upload_docker_uri')
merge_parser.add_argument('--merge_base_and_lora_output_dir')
merge_args, unknown = merge_parser.parse_known_args(unknown)
if merge_args.merge_base_and_lora_output_dir:
merge_local_dir, merge_gcs_dir = gcs_syncer.manage_sync_path(
merge_args.merge_base_and_lora_output_dir, None
)
merge_args.merge_base_and_lora_output_dir = merge_local_dir
if gcs_syncer.is_gcs_or_gcsfuse_path(merge_gcs_dir):
dirs_to_sync.append((merge_local_dir, merge_gcs_dir))
# Common flags shared by merging and training.
common_parser = argparse.ArgumentParser()
common_parser.add_argument('--pretrained_model_id', required=True)
common_parser.add_argument('--pretrained_model_name_or_path', required=True)
common_parser.add_argument('--huggingface_access_token')
common_args, remaining = common_parser.parse_known_args(unknown)
@@ -173,17 +163,19 @@ def _get_train_cmd_and_maybe_merge_cmd(
commands = [training_cmd]
# Only the main node runs merging.
if (
merge_args.merge_base_and_lora_output_dir
and getattr(accelerate_args, 'machine_rank', 0) == 0
):
if merge_args.merge_base_and_lora_output_dir and node_rank == 0:
lora_dir = utils.get_final_checkpoint_path(training_args.output_dir)
lora_local_dir, lora_gcs_dir = gcs_syncer.manage_sync_path(
lora_dir, node_rank
)
if gcs_syncer.is_gcs_or_gcsfuse_path(lora_gcs_dir):
dirs_to_sync.append((lora_local_dir, lora_gcs_dir))
merge_cmd = [
'WORLD_SIZE=1', # To ignore other nodes in multi-node setting.
'python3',
_TASK_TO_SCRIPT[constants.MERGE_CAUSAL_LANGUAGE_MODEL_LORA],
f'--finetuned_lora_model_dir={lora_dir}',
f'--finetuned_lora_model_dir={lora_local_dir}',
]
_append_args_to_command_in_place(merge_args, merge_cmd)
_append_args_to_command_in_place(common_args, merge_cmd)
@@ -196,16 +188,51 @@ def _get_train_cmd_and_maybe_merge_cmd(
]
commands.append(conda_run_cmd)
return commands
return commands, dirs_to_sync
def _get_merge_cmd_and_dirs_to_sync(
task_type: str, config_file: str, unknown: Sequence[str]
) -> Sequence[Sequence[str]]:
"""Returns the merge command and dirs to sync.
Args:
task_type: The task type.
config_file: The accelerate config file path.
unknown: The unknown args which are not recognised by the parser.
Returns:
The bash commands to execute and the directories to sync.
"""
# Merge only flags.
merge_parser = argparse.ArgumentParser()
merge_parser.add_argument('--merge_base_and_lora_output_dir')
merge_args, unknown = merge_parser.parse_known_args(unknown)
dirs_to_sync = []
if merge_args.merge_base_and_lora_output_dir:
merge_local_dir, merge_gcs_dir = gcs_syncer.manage_sync_path(
merge_args.merge_base_and_lora_output_dir, None
)
merge_args.merge_base_and_lora_output_dir = merge_local_dir
if gcs_syncer.is_gcs_or_gcsfuse_path(merge_gcs_dir):
dirs_to_sync.append((merge_local_dir, merge_gcs_dir))
cmd = launch_script_cmd(_TASK_TO_SCRIPT[task_type], config_file)
_append_args_to_command_in_place(merge_args, cmd)
cmd.extend(unknown)
return [cmd], dirs_to_sync
def main(unused_argv: Sequence[str]) -> None:
parser = argparse.ArgumentParser()
parser.add_argument('--config_file')
parser.add_argument('--task')
parser.add_argument('--gcs_rsync_interval_secs', type=int, default=60)
args, unknown = parser.parse_known_args()
task = args.task
dirs_to_sync = None
if task in _TEXT_TO_IMAGE_TASKS_SCRIPTS:
# Setup accelerate config before running trainer.
@@ -224,8 +251,12 @@ def main(unused_argv: Sequence[str]) -> None:
] + list(map(dataset_validation_util.force_gcs_fuse_path, unknown))
commands = [config_gen_cmd, task_cmd]
elif task in [constants.INSTRUCT_LORA]:
commands = _get_train_cmd_and_maybe_merge_cmd(
task=task, config_file=args.config_file, unknown=unknown
commands, dirs_to_sync = _get_train_and_maybe_merge_cmd_and_dirs_to_sync(
task_type=task, config_file=args.config_file, unknown=unknown
)
elif task in [constants.MERGE_CAUSAL_LANGUAGE_MODEL_LORA]:
commands, dirs_to_sync = _get_merge_cmd_and_dirs_to_sync(
task_type=task, config_file=args.config_file, unknown=unknown
)
else:
assert task in _TASK_TO_SCRIPT
@@ -233,10 +264,29 @@ def main(unused_argv: Sequence[str]) -> None:
cmd.extend(unknown)
commands = [cmd]
rsync_process = None
mp_queue = multiprocessing.Queue(maxsize=1)
if dirs_to_sync:
rsync_process = gcs_syncer.setup_gcs_rsync(
dirs_to_sync, mp_queue, args.gcs_rsync_interval_secs
)
for cmd in commands:
logging.info('launching task=%s with cmd: \n%s', task, ' \\\n'.join(cmd))
subprocess.run(cmd, check=True)
# Both absl logging and python's logging module writes to stderr by default.
# Redirect output to stdout on purpose, such that log entries do not get
# marked as `Error` in Cloud's Log Explorer.
try:
subprocess.run(cmd, stdout=sys.stdout, stderr=sys.stdout, check=True)
except subprocess.CalledProcessError as e:
if rsync_process is not None and rsync_process.is_alive():
logging.info('Terminating GCS rsync process.')
rsync_process.terminate()
raise e
if rsync_process is not None:
gcs_syncer.cleanup_gcs_rsync(rsync_process, mp_queue)
if __name__ == '__main__':
logging.get_absl_handler().python_handler.stream = sys.stdout
app.run(main, flags_parser=lambda _args: flags.FLAGS(_args, known_only=True))
@@ -1,232 +1,44 @@
"""Common libraries for PEFT."""
import dataclasses
from collections.abc import Mapping, Sequence
import datetime
import gc
import multiprocessing as mp
import os
import subprocess
from typing import Any, Dict, Optional, Sequence
from typing import Any
from absl import logging
import accelerate
from accelerate import DistributedType
from accelerate import PartialState
from google.protobuf import json_format
from kfp.pipeline_spec import pipeline_spec_pb2
import numpy as np
import peft
from peft import PeftModel
from peft import prepare_model_for_kbit_training
import pynvml
import torch
import transformers
from transformers import AutoModelForCausalLM
from transformers import AutoTokenizer
from transformers import BitsAndBytesConfig
from transformers import FbgemmFp8Config
from transformers.integrations import is_deepspeed_zero3_enabled
import trl
from util import dataset_validation_util
from util import constants
from util import fileutils
_MODELS_REQUIRING_PAD_TOKEN = ("llama", "falcon", "mistral", "mixtral")
_MODELS_REQUIRING_EOS_TOEKN = ("gemma-2b", "gemma-7b")
_LLAMA_3_1_405B_MODEL_ID = "Meta-Llama-3.1-405B"
_LOCAL_MERGED_MODEL_DIR = "/tmp/merged_model"
class GcsOrLocalDirectory(os.PathLike):
"""A class to represent a directory with upload support if GCS path is given.
This class is used to represent a directory. It can be used for a temporary
local directory and for uploading files to the GCS directory later if the
given path is a GCS directory. If the given path is a local directory, a call
to gcs_dir attribute will raise an error. This class has multi-node and
multi-process support with accelerate.
Attributes:
local_dir: The local directory to store the files.
gcs_dir: The path to the GCS directory.
"""
def __init__(
self,
path: str,
check_empty: bool = False,
upload_from_all_nodes: bool = False,
):
"""Initializes the GcsOrLocalDirectory.
Args:
path: The path to the directory.
check_empty: If True, check if the GCS directory is empty. No-op for local
directory.
upload_from_all_nodes: If True, upload the local directory to GCS from all
nodes.
"""
if len(path) > 1:
path = path.rstrip("/")
self._upload_from_all_nodes = upload_from_all_nodes
if path.startswith(constants.GCS_URI_PREFIX) or path.startswith(
constants.GCSFUSE_URI_PREFIX
):
self._is_gcs_path = True
self._local_dir = _get_local_dir_from_gcs_dir(path)
self._gcs_dir = fileutils.force_gcs_path(path)
os.makedirs(self.local_dir, exist_ok=True)
with PartialState().main_process_first():
if (
check_empty
and PartialState().is_main_process
and not _is_gcs_dir_empty(self._gcs_dir)
):
raise ValueError(f"{self._gcs_dir} needs to be empty.")
else:
self._is_gcs_path = False
self._local_dir = path
self._gcs_dir = path
def __fspath__(self) -> str:
return self.local_dir
@property
def local_dir(self) -> str:
return self._local_dir
@property
def gcs_dir(self) -> str:
"""Returns the GCS directory path.
Returns:
The GCS directory path.
Raises:
ValueError: If the path is not a GCS path.
"""
if not self._is_gcs_path:
raise ValueError(f"{self._gcs_dir} is not a GCS path.")
return self._gcs_dir
def upload_to_gcs(
self,
skip_if_exists: bool = True,
force_upload: bool = False,
):
"""Uploads the local directory to GCS."""
if not self._is_gcs_path:
logging.info(
"Not uploading to GCS since %s is not a GCS path.", self.local_dir
)
return
if not os.listdir(self.local_dir):
logging.info("Not uploading to GCS since %s is empty.", self.local_dir)
return
target = os.path.dirname(self.gcs_dir) + "/"
# Avoid race condition uploading the same file from multiple processes.
with PartialState().main_process_first():
if not PartialState().is_local_main_process:
# Non local main processes don't upload.
pass
elif self._upload_from_all_nodes or PartialState().is_main_process:
logging.info("Uploading %s to %s...", self.local_dir, target)
cmd = [
"gsutil",
"-m",
"cp",
"-r",
]
if skip_if_exists:
cmd.append("-n")
if force_upload:
cmd.append("-f")
cmd.extend([self.local_dir, target])
subprocess.check_output(cmd)
logging.info("%s uploaded.", self.local_dir)
def _get_local_dir_from_gcs_dir(path: str) -> str:
return os.path.join(
constants.LOCAL_OUTPUT_DIR,
dataset_validation_util.force_gcs_fuse_path(path)[1:],
)
def _is_gcs_dir_empty(path: str) -> bool:
"""Checks if a GCS directory is empty.
Args:
path: The GCS directory path.
Returns:
True if the directory is empty.
Raises:
subprocess.CalledProcessError: If the gsutil command failure reason is not
because the dir is empty.
"""
path = path.rstrip("/") + "/"
try:
subprocess.check_output(["gsutil", "ls", path], stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
if (
str(e.output, encoding="utf-8")
== "CommandException: One or more URLs matched no objects.\n"
):
return True
else:
logging.info(str(e.output, encoding="utf-8"))
raise
else:
return False
def load_tokenizer(
pretrained_model_id: str,
padding_side: Optional[str] = None,
access_token: Optional[str] = None,
) -> AutoTokenizer:
"""Loads tokenizer based on `pretrained_model_id`."""
tokenizer_kwargs = {}
if should_add_eos_token(pretrained_model_id):
tokenizer_kwargs["add_eos_token"] = True
if padding_side:
tokenizer_kwargs["padding_side"] = padding_side
with PartialState().local_main_process_first():
tokenizer = AutoTokenizer.from_pretrained(
pretrained_model_id,
trust_remote_code=False,
use_fast=True,
token=access_token,
**tokenizer_kwargs,
)
if should_add_pad_token(pretrained_model_id):
tokenizer.add_special_tokens({"pad_token": "[PAD]"})
return tokenizer
_GEMMA2_MODEL = "gemma-2"
def load_model(
pretrained_model_id: str,
pretrained_model_name_or_path: str,
tokenizer: AutoTokenizer,
precision_mode: str = None,
enable_gradient_checkpointing: bool = False,
gradient_checkpointing_kwargs: Optional[Dict[str, Any]] = None,
access_token: Optional[str] = None,
attn_implementation: Optional[str] = None,
train_precision: Optional[str] = None,
device_map: Optional[str] = None,
gradient_checkpointing: bool = False,
gradient_checkpointing_kwargs: Mapping[str, Any] | None = None,
access_token: str | None = None,
attn_implementation: str | None = None,
train_precision: str | None = None,
device_map: str | None = None,
is_training: bool = True,
) -> AutoModelForCausalLM:
"""Loads models from the local dir if specified or from huggingface."""
@@ -304,25 +116,37 @@ def load_model(
raise ValueError(f"Invalid precision mode: {precision_mode}")
logging.info("using torch_type=%s", torch_dtype)
model_kwargs = {
"use_cache": not gradient_checkpointing,
"device_map": device_map,
"torch_dtype": torch_dtype,
"quantization_config": quantization_config,
"trust_remote_code": False,
"token": access_token,
"attn_implementation": attn_implementation,
}
if _GEMMA2_MODEL in pretrained_model_name_or_path:
# The cache_implementation for Gemma 2 is set to hybrid by default. This
# param is only supported by Gemma 2. The default 'hybrid' value causes an
# issue when use_cache is set to False. So we have to use 'None' in such
# cases.
# https://github.com/huggingface/transformers/commit/238b13478df209ab534f2195a397dc64a3930883
model_kwargs["cache_implementation"] = (
None if gradient_checkpointing else "hybrid"
)
model = AutoModelForCausalLM.from_pretrained(
pretrained_model_id,
use_cache=not enable_gradient_checkpointing,
device_map=device_map,
torch_dtype=torch_dtype,
quantization_config=quantization_config,
trust_remote_code=True,
token=access_token,
attn_implementation=attn_implementation,
pretrained_model_name_or_path, **model_kwargs
)
if precision_mode in (constants.PRECISION_MODE_4, constants.PRECISION_MODE_8):
model = prepare_model_for_kbit_training(
model,
use_gradient_checkpointing=enable_gradient_checkpointing,
use_gradient_checkpointing=gradient_checkpointing,
gradient_checkpointing_kwargs=gradient_checkpointing_kwargs,
)
if enable_gradient_checkpointing:
if gradient_checkpointing:
model.gradient_checkpointing_enable(
gradient_checkpointing_kwargs=gradient_checkpointing_kwargs
)
@@ -345,8 +169,10 @@ def load_model(
# https://stackoverflow.com/a/77408076
model.config.use_cache = False
if should_add_pad_token(pretrained_model_id):
model.resize_token_embeddings(len(tokenizer))
if dataset_validation_util.should_add_pad_token(
pretrained_model_name_or_path
):
model.resize_token_embeddings(len(tokenizer), mean_resizing=False)
if is_training:
# The following is needed since we added a new token that needs to be
# learned.
@@ -357,22 +183,24 @@ def load_model(
def _merge_causal_language_model_with_lora_internal(
pretrained_model_id: str,
pretrained_model_name_or_path: str,
merge_precision_mode: str,
finetuned_lora_model_dir: str,
merged_model_output_dir: str,
access_token: Optional[str] = None,
access_token: str | None = None,
) -> None:
"""Internal function to merges the base model with the lora adapter."""
logging.info("loading tokenizer...")
tokenizer = load_tokenizer(pretrained_model_id)
tokenizer = dataset_validation_util.load_tokenizer(
pretrained_model_name_or_path
)
# Note: merging peft adapter requires loading model in 16 bits, so merging
# is done on CPU on purpose in case one GPU cannot hold the base model.
logging.info("loading model %s...", pretrained_model_id)
logging.info("loading model %s...", pretrained_model_name_or_path)
device_map = "cpu"
model = load_model(
pretrained_model_id=pretrained_model_id,
pretrained_model_name_or_path=pretrained_model_name_or_path,
tokenizer=tokenizer,
precision_mode=merge_precision_mode,
access_token=access_token,
@@ -402,42 +230,12 @@ def _merge_causal_language_model_with_lora_internal(
)
def merge_causal_language_model_with_lora_fsdp(
pretrained_model_id: str,
merge_precision_mode: str,
finetuned_lora_model_dir: str,
merged_model_output_dir: str,
access_token: Optional[str] = None,
) -> None:
"""Merges the base model with the lora adapter for FSDP.
Only the main process should call this function.
Args:
pretrained_model_id: Predefined base model name or path to directory
containing model checkpoints.
merge_precision_mode: Precision mode for saving model weights.
finetuned_lora_model_dir: Path to directory containing PEFT-finetuned model
weights.
merged_model_output_dir: Path to directory to save the merged model.
access_token: Access token for accessing the model.
"""
assert PartialState().is_main_process
_merge_causal_language_model_with_lora_internal(
pretrained_model_id=pretrained_model_id,
merge_precision_mode=merge_precision_mode,
finetuned_lora_model_dir=finetuned_lora_model_dir,
merged_model_output_dir=merged_model_output_dir,
access_token=access_token,
)
def merge_causal_language_model_with_lora(
pretrained_model_id: str,
pretrained_model_name_or_path: str,
precision_mode: str,
finetuned_lora_model_dir: str,
merged_model_output_dir: str,
access_token: Optional[str] = None,
access_token: str | None = None,
) -> None:
"""Merges the base model with the lora adapter."""
@@ -452,39 +250,13 @@ def merge_causal_language_model_with_lora(
if PartialState().is_main_process:
logging.info("Starting merging job...")
# When deepspeed Zero3 is enabled, users are not allowed to specify
# `device_map` when loading the model (even on CPU).
#
# To work-around this, we kick off another process (from the
# is_main_process) and set up the environment to avoid using Deepspeed when
# doing the merging.
if is_deepspeed_zero3_enabled():
ctx = mp.get_context("spawn")
os.environ["ACCELERATE_USE_DEEPSPEED"] = "false"
merge_job = ctx.Process(
target=_merge_causal_language_model_with_lora_internal,
args=(
pretrained_model_id,
merge_precision_mode,
finetuned_lora_model_dir,
local_merged_model_dir,
),
kwargs={
"access_token": access_token,
},
)
merge_job.start()
merge_job.join()
os.environ["ACCELERATE_USE_DEEPSPEED"] = "true"
else:
_merge_causal_language_model_with_lora_internal(
pretrained_model_id=pretrained_model_id,
merge_precision_mode=merge_precision_mode,
finetuned_lora_model_dir=finetuned_lora_model_dir,
merged_model_output_dir=local_merged_model_dir,
access_token=access_token,
)
_merge_causal_language_model_with_lora_internal(
pretrained_model_name_or_path=pretrained_model_name_or_path,
merge_precision_mode=merge_precision_mode,
finetuned_lora_model_dir=finetuned_lora_model_dir,
merged_model_output_dir=local_merged_model_dir,
access_token=access_token,
)
logging.info("merging job is done")
# Wait for all processes to sync here.
@@ -492,7 +264,7 @@ def merge_causal_language_model_with_lora(
if precision_mode == constants.PRECISION_MODE_FP8:
convert_model_to_fp8(
pretrained_model_name_or_path=pretrained_model_id,
pretrained_model_name_or_path=pretrained_model_name_or_path,
merged_model_output_dir=local_merged_model_dir,
quantized_model_output_dir=merged_model_output_dir,
access_token=access_token,
@@ -503,7 +275,7 @@ def convert_model_to_fp8(
pretrained_model_name_or_path: str,
merged_model_output_dir: str,
quantized_model_output_dir: str,
access_token: Optional[str] = None,
access_token: str | None = None,
) -> None:
"""Converts the model to fp8.
@@ -533,166 +305,12 @@ def convert_model_to_fp8(
PartialState().wait_for_everyone()
@dataclasses.dataclass
class TuningDataStats:
tuning_dataset_example_count: int
total_billable_token_count: int
tuning_step_count: int
def get_dataset_stats(
dataset: Any,
tokenizer: transformers.PreTrainedTokenizer,
column: str,
effective_batch_size: int,
) -> TuningDataStats:
"""Calculates dataset statistics, e.g., total number of tokens."""
tokenized_dataset = dataset.map(lambda x: tokenizer(x[column]))
inputs = tokenized_dataset["input_ids"]
tuning_dataset_example_count = int(len(inputs))
total_billable_token_count = int(np.sum([len(ex) for ex in inputs]))
tuning_step_count = (
tuning_dataset_example_count + effective_batch_size - 1
) // effective_batch_size
return TuningDataStats(
tuning_dataset_example_count,
total_billable_token_count,
tuning_step_count,
)
def force_gc():
"""Collects garbage immediately to release unused CPU/GPU resources."""
gc.collect()
torch.cuda.empty_cache()
def should_add_pad_token(model_id: str) -> bool:
"""Returns whether the model requires adding a special pad token."""
return any(s.lower() in model_id.lower() for s in _MODELS_REQUIRING_PAD_TOKEN)
def should_add_eos_token(model_id: str) -> bool:
"""Returns whether the model requires adding a special eos token."""
return any(m in model_id for m in _MODELS_REQUIRING_EOS_TOEKN)
def write_kfp_outputs(
executor_input: str, output_artifacts: Dict[str, str]
) -> None:
"""Writes KFP outputs given a dict of output artifact names and URIs."""
# Only the main process writes to avoid race condition.
if PartialState().is_main_process:
executor_input = json_format.Parse(
executor_input, pipeline_spec_pb2.ExecutorInput()
)
outputs = executor_input.outputs
# set all artifacts
for name, uri in output_artifacts.items():
artifact_list = outputs.artifacts.get(name)
if not artifact_list or not artifact_list.artifacts:
raise ValueError(f"Artifact name={name} does not exist.")
artifact_list.artifacts[0].uri = uri
# write output file
executor_output = pipeline_spec_pb2.ExecutorOutput(
artifacts=outputs.artifacts
)
os.makedirs(os.path.dirname(outputs.output_file), exist_ok=True)
with open(outputs.output_file, "w") as f:
f.write(json_format.MessageToJson(executor_output, indent=None))
# Wait for the main process to finish before moving on to the next task.
PartialState().wait_for_everyone()
def upload_local_dir_to_gcs(local_dir: str, gcs_path: str):
"""Uploads local dir to GCS."""
if PartialState().is_main_process:
logging.info("uploading %s to %s...", local_dir, gcs_path)
subprocess.check_output([
"gsutil",
"-m",
"cp",
"-r",
local_dir,
gcs_path,
])
logging.info("%s uploaded.", local_dir)
PartialState().wait_for_everyone()
def write_first_party_model_metadata(output_dir: str, docker_uri: str) -> None:
"""Multi-process friendly version of fileutils.write_first_party_model_metadata."""
if PartialState().is_main_process:
fileutils.write_first_party_model_metadata(output_dir, docker_uri)
PartialState().wait_for_everyone()
@dataclasses.dataclass
class GpuStats:
"""Holds information about GPU usage stats.
For memory related, see
https://pytorch.org/docs/stable/notes/cuda.html#cuda-memory-management
"""
# total memory
total_mem: float
# memory occupied.
occupied: float
# memory reserved, but not used.
unused: float
# nvidia-smi usually reports more memory usages than pytorch (for driver,
# kernel and etc). `smi_diff` tracks this difference.
smi_diff: float
# Gpu utilization.
util: float
# Allows unpacking operation like
# total_mem, occupied, unused, smi_diff, util = GpuStats(...)
# See https://stackoverflow.com/a/70753113
def __iter__(self):
return iter(dataclasses.astuple(self))
def gpu_stats() -> GpuStats:
"""Reports GPU memory usage and utilization."""
# See https://pytorch.org/docs/stable/notes/cuda.html#memory-management
bytes_per_gb = 1024.0**3
device = torch.cuda.current_device()
occupied = torch.cuda.memory_allocated(device) / bytes_per_gb
reserved = torch.cuda.memory_reserved(device) / bytes_per_gb
unused = reserved - occupied
def smi_mem(device):
try:
pynvml.nvmlInit()
handle = pynvml.nvmlDeviceGetHandleByIndex(device)
info = pynvml.nvmlDeviceGetMemoryInfo(handle)
return info.used / bytes_per_gb
except pynvml.NVMLError:
return 0.0
mem_used_smi = smi_mem(device)
smi_diff = mem_used_smi - reserved
util = torch.cuda.utilization(device)
return GpuStats(mem_used_smi, occupied, unused, smi_diff, util)
def gpu_stats_str(stats: Optional[GpuStats] = None) -> str:
if stats is None:
stats = gpu_stats()
total, occupied, unused, smi_diff, util = stats
return (
f"GPU memory: {total:.2f}({occupied=:.2f}, {unused=:.2f},"
f" {smi_diff=:.2f}) GB. Utilization: {util:.2f}%"
)
def init_partial_state(
timeout: datetime.timedelta = datetime.timedelta(seconds=600),
) -> None:
@@ -722,7 +340,7 @@ def get_final_checkpoint_path(output_dir: str) -> str:
def _maybe_get_modules_to_not_convert_by_model_id(
pretrained_model_name_or_path: str,
) -> Optional[Sequence[str]]:
) -> Sequence[str] | None:
"""Returns the modules to not convert for the model."""
if _LLAMA_3_1_405B_MODEL_ID in pretrained_model_name_or_path:
return _get_llama_3_1_405b_modules_to_not_convert()
@@ -17,15 +17,15 @@ _DATASET_NAME = flags.DEFINE_string(
required=True,
)
_TRAIN_SPLIT_NAME = flags.DEFINE_string(
'train_split_name',
_TRAIN_SPLIT = flags.DEFINE_string(
'train_split',
'train',
'The train split name.',
)
_INSTRUCT_COLUMN_IN_DATASET = flags.DEFINE_string(
'instruct_column_in_dataset',
constants.DEFAULT_INSTRUCT_COLUMN_IN_DATASET,
_TRAIN_COLUMN = flags.DEFINE_string(
'train_column',
constants.DEFAULT_TRAIN_COLUMN,
'The instruct column in dataset.',
)
@@ -38,6 +38,12 @@ _TEMPLATE = flags.DEFINE_string(
required=True,
)
_MAX_SEQ_LENGTH = flags.DEFINE_integer(
'max_seq_length',
None,
'The maximum sequence length.',
)
_VALIDATE_PERCENTAGE_OF_DATASET = flags.DEFINE_integer(
'validate_percentage_of_dataset',
None,
@@ -64,9 +70,10 @@ def main(unused_argv: Sequence[str]) -> None:
dataset_validation_util.validate_dataset_with_template(
dataset_name=_DATASET_NAME.value,
split=_TRAIN_SPLIT_NAME.value,
input_column=_INSTRUCT_COLUMN_IN_DATASET.value,
split=_TRAIN_SPLIT.value,
input_column=_TRAIN_COLUMN.value,
template=_TEMPLATE.value,
max_seq_length=_MAX_SEQ_LENGTH.value,
use_multiprocessing=_USE_MULTIPROCESSING.value,
validate_percentage_of_dataset=_VALIDATE_PERCENTAGE_OF_DATASET.value,
validate_k_rows_of_dataset=_VALIDATE_K_ROWS_OF_DATASET.value,
@@ -90,12 +90,11 @@ TEXT_TO_IMAGE_DREAMBOOTH_LORA = 'text-to-image-dreambooth-lora'
TEXT_TO_IMAGE_DREAMBOOTH_LORA_SDXL = 'text-to-image-dreambooth-lora-sdxl'
SEQUENCE_CLASSIFICATION_LORA = 'sequence-classification-lora'
MERGE_CAUSAL_LANGUAGE_MODEL_LORA = 'merge-causal-language-model-lora'
QUANTIZE_MODEL = 'quantize-model'
INSTRUCT_LORA = 'instruct-lora'
VALIDATE_DATASET_WITH_TEMPLATE = 'validate-dataset-with-template'
RUN_TESTS = 'test'
DEFAULT_TEXT_COLUMN_IN_DATASET = 'quote'
DEFAULT_TEXT_COLUMN_IN_QUANTIZATION_DATASET = 'text'
DEFAULT_INSTRUCT_COLUMN_IN_DATASET = 'text'
DEFAULT_TRAIN_COLUMN = 'text'
FINAL_CHECKPOINT_DIRNAME = 'checkpoint-final'
@@ -113,13 +112,17 @@ PRECISION_MODE_16 = 'float16'
PRECISION_MODE_16B = 'bfloat16'
PRECISION_MODE_32 = 'float32'
# Quantization modes.
GPTQ = 'gptq'
AWQ = 'awq'
ROUGE_VARIANTS = ('rouge1', 'rouge2', 'rougeL', 'rougeLsum')
# AWQ versions.
GEMM = 'GEMM'
GEMV = 'GEMV'
# Supported HF evaluation metrics.
SUPPORTED_HF_EVAL_METRICS = (
'perplexity',
'bleu',
'google_bleu',
) + ROUGE_VARIANTS
# Supported evaluation metrics.
SUPPORTED_EVAL_METRICS = ('loss',) + SUPPORTED_HF_EVAL_METRICS
# Environment variable keys.
PRIVATE_BUCKET_ENV_KEY = 'AIP_PRIVATE_BUCKET_NAME'
@@ -1,9 +1,12 @@
"""Fileutil lib to copy files between gcs and local."""
import filecmp
import fnmatch
import os
import pathlib
import shutil
import subprocess
import time
from typing import List, Optional, Tuple
import uuid
@@ -57,6 +60,113 @@ def force_gcs_path(uri: str) -> str:
return uri
def is_file_available(
file_path: str, retry_interval_secs: int = 60, timeout_secs: int = 3600
) -> bool:
"""Checks and waits for a file to be available in GCS.
Args:
file_path: The file path to check.
retry_interval_secs: The interval in seconds to check the file.
timeout_secs: The timeout in seconds to wait for the file.
Returns:
True if the file is available, False otherwise.
"""
start_time = time.time()
while True:
try:
file_check_cmd = ['gcloud', 'storage', 'ls', file_path]
result = subprocess.run(
file_check_cmd, capture_output=True, text=True, check=True
)
if file_path in result.stdout:
logging.info('File %s exists.', file_path)
return True
except subprocess.CalledProcessError as e:
elapsed_time = time.time() - start_time
if elapsed_time > timeout_secs:
logging.info(
"Timeout: File '%s' not found after %d seconds. Error: %s",
file_path,
elapsed_time,
e,
)
return False
logging.info(
"File '%s' not found yet. Checking again in %d seconds. Error: %s",
file_path,
retry_interval_secs,
e,
)
time.sleep(retry_interval_secs)
def compare_dirs(
local_dir: str,
gcsfuse_dir: str,
retry_interval_secs: int = 30,
timeout_secs: int = 3600,
) -> bool:
"""Compares two directories and returns True if they are the same.
Args:
local_dir: The local directory.
gcsfuse_dir: The gcsfuse directory.
retry_interval_secs: The interval in seconds to check the directories.
timeout_secs: The timeout in seconds to wait for the directories.
Returns:
True if the directories are the same, False otherwise.
"""
start_time = time.time()
while True:
if os.path.exists(local_dir) and os.path.exists(gcsfuse_dir):
comparison = filecmp.dircmp(local_dir, gcsfuse_dir)
if (
not comparison.left_only
and not comparison.right_only
and not comparison.diff_files
):
return True
elapsed_time = time.time() - start_time
if elapsed_time > timeout_secs:
logging.info(
"Timeout: Directories '%s' and '%s' do not match after %d seconds.",
local_dir,
gcsfuse_dir,
elapsed_time,
)
return False
logging.info(
"Directories '%s' and '%s' do not match yet. Checking again in %d"
' seconds.',
local_dir,
gcsfuse_dir,
retry_interval_secs,
)
time.sleep(retry_interval_secs)
def download_gcs_file_to_memory(gcs_uri: str) -> bytes:
"""Downloads a gcs file to in memory.
Args:
gcs_uri: A string of GCS uri.
Returns:
The content of the gcs file in byte format.
"""
bucket = gcs_uri.split('/')[2]
file_path = gcs_uri[len(constants.GCS_URI_PREFIX + bucket + '/') :]
client = _get_gcs_client()
bucket = client.bucket(bucket)
blob = bucket.blob(file_path)
return blob.download_as_bytes()
def download_gcs_file_to_local_dir(gcs_uri: str, local_dir: str):
"""Download a gcs file to a local dir.
@@ -337,22 +447,13 @@ def get_output_video_file(video_output_file_path: str) -> str:
return out_local_video_file_name
def write_first_party_model_metadata(
output_path: str, required_container_uri: str
) -> None:
"""Write Vertex internal model metadata for first party artifacts."""
model_metadata_fname = 'model_metadata.jsonl'
if len(required_container_uri) > 126:
raise ValueError(f'Docker URI exceeds 126 chars: {required_container_uri}')
payload = '\n{}{}'.format( # serialized proto
chr(len(required_container_uri)),
required_container_uri,
)
os.makedirs(output_path, exist_ok=True)
output_dirs = [output_path]
if output_path.startswith('/gcs'):
# include all parent dirs, except "/", "/gcs"
output_dirs.extend([str(p) for p in pathlib.Path(output_path).parents][:-2])
for output_dir in output_dirs:
with open(os.path.join(output_dir, model_metadata_fname), 'w') as f:
f.write(payload)
def delete_local_file(local_file_path: str) -> None:
"""Deletes a local file."""
if os.path.exists(local_file_path):
os.remove(local_file_path)
def delete_local_dir(local_dir: str) -> None:
"""Deletes a local directory recursively."""
if os.path.exists(local_dir):
shutil.rmtree(local_dir)
@@ -0,0 +1,119 @@
#!/bin/bash
#
# This launcher downloads model files from GCS to local model directory before
# launching the actual command.
#
# If GCS URI is passed as an environment variable, set GCS_URI_ENV_KEY to the
# environment variable name.
# If GCS URI is passed as an argument, set GCS_URI_ARG_KEY to the argument name.
# The argument must be in the format of '--$GCS_URI_ARG_KEY=gs://*'. Do not
# separate argument name and value with spaces.
# This script will also try reading from AIP_STORAGE_URI or AIP_STORAGE_DIR.
# Note that AIP_STORAGE_DIR is expected to be a local path, so it bypasses the
# download process.
#
# Input priority: AIP_STORAGE_DIR > AIP_STORAGE_URI > GCS_URI_ENV_KEY > GCS_URI_ARG_KEY.
# Will output the local model directory to GCS_URI_ENV_KEY and GCS_URI_ARG_KEY
# if they are set. Both will be updated if both set.
#
# Requires google-cloud-sdk as a dependency (for gcloud storage CLI).
set -e
readonly LOCAL_MODEL_DIR=${LOCAL_MODEL_DIR:-"/tmp/model_dir"}
readonly LOCAL_ARGS_FILE=${LOCAL_ARGS_FILE:-"/tmp/args.txt"}
update_model_id() {
if [[ ! -z "$GCS_URI_ENV_KEY" ]]; then
echo "Updating env var $GCS_URI_ENV_KEY to $AIP_STORAGE_DIR."
export "$GCS_URI_ENV_KEY"="$AIP_STORAGE_DIR"
fi
if [[ ! -z "$GCS_URI_ARG_KEY" ]]; then
echo "Updating args $GCS_URI_ARG_KEY to $AIP_STORAGE_DIR."
updated=0
for (( i=1; i <= $#; i++)); do
arg="${!i}"
if [[ "$arg" == "--$GCS_URI_ARG_KEY="* ]]; then
echo "Found $arg, updating to $AIP_STORAGE_DIR."
set -- "${@:1:(($i-1))}" "--$GCS_URI_ARG_KEY=$AIP_STORAGE_DIR" "${@:$(($i+1))}";
updated=1
break
fi
done
if [[ $updated -eq 0 ]]; then
echo "Appending args $GCS_URI_ARG_KEY to $AIP_STORAGE_DIR."
set -- "$@" "--$GCS_URI_ARG_KEY=$AIP_STORAGE_DIR";
fi
fi
echo "$*" > "$LOCAL_ARGS_FILE"
}
maybe_download_model() {
if [[ -z "$GCS_URI_ENV_KEY" ]] && [[ -z "$GCS_URI_ARG_KEY" ]]; then
echo "Internal error: Required GCS_URI_ENV_KEY or GCS_URI_ARG_KEY."
exit 1
fi
echo "$*" > "$LOCAL_ARGS_FILE"
gcs_uri=""
if [[ ! -z "$AIP_STORAGE_DIR" ]]; then
# AIP_STORAGE_DIR is expected to be a local path.
echo "AIP_STORAGE_DIR set, proceeding to run the launcher."
update_model_id "$@"
return
elif [[ $AIP_STORAGE_URI == gs://* ]]; then
# Check AIP_STORAGE_URI environment variable.
echo "AIP_STORAGE_URI set and starts with 'gs://', proceeding to download from GCS."
gcs_uri="$AIP_STORAGE_URI"
elif [[ ! -z "$GCS_URI_ENV_KEY" ]] && [[ ${!GCS_URI_ENV_KEY} == gs://* ]]; then
# Check custom environment variable.
echo "Custom environment variable ${GCS_URI_ENV_KEY} set and starts with 'gs://', proceeding to download from GCS."
gcs_uri="${!GCS_URI_ENV_KEY}"
elif [[ ! -z "$GCS_URI_ARG_KEY" ]]; then
# Check custom args.
for arg in "$@"; do
if [[ "$arg" == "--$GCS_URI_ARG_KEY=gs://"* ]]; then
gcs_uri="${arg#*=}"
echo "Custom args ${GCS_URI_ARG_KEY} set and starts with 'gs://', proceeding to download from GCS."
break
elif [[ "$arg" == "--$GCS_URI_ARG_KEY" ]]; then
echo "Found $GCS_URI_ARG_KEY, but it's not in the format of '--$GCS_URI_ARG_KEY=gs://*'."
echo "Ensure the value of $GCS_URI_ARG_KEY is within the same arg, separated by '='."
exit 1
fi
done
fi
if [[ -z "$gcs_uri" ]]; then
echo "No GCS URI found, proceeding to run the launcher."
return
fi
# Remove trailing '/' if any.
gcs_uri="${gcs_uri%%/}"
export AIP_STORAGE_DIR="$LOCAL_MODEL_DIR/${gcs_uri##gs://}"
# Create the target directory.
mkdir -p "$AIP_STORAGE_DIR"
echo "Downloading model from ${gcs_uri} to ${AIP_STORAGE_DIR}."
# Use gcloud storage CLI to copy the content from GCS to the target directory.
if gcloud storage cp -r "$gcs_uri/*" "$AIP_STORAGE_DIR"; then
echo "Model downloaded successfully to ${AIP_STORAGE_DIR}."
update_model_id "$@"
else
echo "Failed to download model from GCS."
exit 1
fi
}
run_local_command() {
command=$(cat "$LOCAL_ARGS_FILE")
rm -f "$LOCAL_ARGS_FILE"
echo "Launch command: $command"
eval "$command"
}
maybe_download_model "$@"
run_local_command
@@ -0,0 +1,176 @@
"""Sync local directory to GCS directory using rsync."""
import multiprocessing
import os
import subprocess
import time
from typing import Optional, Sequence, Tuple
from absl import logging
from util import constants
from util import fileutils
_GCS_COMMAND_RETRIES = 3
_RSYNC_RETRY_INTERVAL_SECS = 30
def is_gcs_or_gcsfuse_path(path: str) -> bool:
"""Returns if the path is a GCS or gcsfuse path.
Args:
path: The path to check.
Returns:
True if the path is a GCS or gcsfuse path.
"""
return path.startswith(
(constants.GCS_URI_PREFIX, constants.GCSFUSE_URI_PREFIX)
)
def manage_sync_path(
path: str, node_rank: Optional[int] = None
) -> Tuple[str, str]:
"""Returns local dir and GCS location for the given path if the given path is a GCS or gcsfuse path.
It will also create a local directory if it does not exist. Otherwise, it
returns the same path.
Args:
path: The local or GCS path to manage.
node_rank: The node rank to be appended to the GCS path.
Returns:
The local and GCS paths.
"""
local_dir = path
gcs_dir = path
if is_gcs_or_gcsfuse_path(path):
local_dir = os.path.join(
constants.LOCAL_OUTPUT_DIR,
fileutils.force_gcs_fuse_path(path)[1:],
)
gcs_dir = fileutils.force_gcs_path(path)
if not os.path.exists(local_dir):
os.makedirs(local_dir, exist_ok=True)
if node_rank is None:
return local_dir, gcs_dir
return local_dir, os.path.join(gcs_dir, f"node-{node_rank}")
def setup_gcs_rsync(
dirs_to_sync: Sequence[Tuple[str, str]],
mp_queue: multiprocessing.Queue,
gcs_rsync_interval_secs: int,
) -> multiprocessing.Process:
"""Sets up the GCS rsync process.
Args:
dirs_to_sync: The absolute directory paths which will be synced to GCS.
mp_queue: The multiprocessing queue to check if the training is finished.
gcs_rsync_interval_secs: Integer, interval in seconds to run gcs rsync.
Returns:
The GCS rsync process.
"""
rsync_process = multiprocessing.Process(
target=start_gcs_rsync,
args=(dirs_to_sync, mp_queue, gcs_rsync_interval_secs),
)
rsync_process.start()
return rsync_process
def cleanup_gcs_rsync(
rsync_process: multiprocessing.Process, mp_queue: multiprocessing.Queue
) -> None:
"""Cleans up the GCS rsync process.
Args:
rsync_process: The GCS rsync process.
mp_queue: The multiprocessing queue.
"""
mp_queue.put("finish rsync process")
rsync_process.join()
if rsync_process.exitcode == 0:
logging.info("Artifacts have been uploaded to GCS.")
else:
logging.error(
"GCS rsync process failed with exit code %d.", rsync_process.exitcode
)
def _rsync_local_to_gcs(local_dir: str, gcs_dir: str) -> None:
"""Syncs the local directory to GCS.
Args:
local_dir: The local directory to sync.
gcs_dir: The GCS directory to sync to.
"""
if not os.listdir(local_dir):
logging.info("Not rsyncing to GCS since %s is empty.", local_dir)
return
logging.info("Rsyncing %s <--> %s...", local_dir, gcs_dir)
cmd = [
"gcloud",
"storage",
"rsync",
"-r",
"--delete-unmatched-destination-objects",
]
cmd.extend([local_dir, gcs_dir])
attempt = 0
while attempt < _GCS_COMMAND_RETRIES:
try:
subprocess.check_output(cmd)
break
except subprocess.CalledProcessError as e:
attempt += 1
if attempt < _GCS_COMMAND_RETRIES:
logging.exception(
"Attempt %d: Command failed: %s. Retrying in %d seconds...",
attempt,
e,
_RSYNC_RETRY_INTERVAL_SECS,
)
time.sleep(_RSYNC_RETRY_INTERVAL_SECS)
else:
logging.exception(
"Command failed after %d attempts: %s.", e, _GCS_COMMAND_RETRIES
)
logging.info("%s rsynced to %s.", local_dir, gcs_dir)
def start_gcs_rsync(
dirs_to_sync: Sequence[Tuple[str, str]],
mp_queue: multiprocessing.Queue,
gcs_rsync_interval_secs: int,
) -> None:
"""Starts a rsync process to sync local directories to GCS directories.
Args:
dirs_to_sync: A list of tuples, where each tuple contains local directory
which will be synced to GCS. For example: [('/tmp/local_dir_1',
'gs://bucket/gcs_dir_1'), ('/tmp/local_dir_2', 'gs://bucket/gcs_dir_2')]
mp_queue: The multiprocessing queue to check if the training is finished.
gcs_rsync_interval_secs: Integer, interval in seconds to run gcs rsync.
"""
while True:
for local_dir, gcs_dir in dirs_to_sync:
_rsync_local_to_gcs(local_dir, gcs_dir)
if not mp_queue.empty():
break
time.sleep(gcs_rsync_interval_secs)
# Sync up the directory one more time to avoid a race condition.
# There can be a case when we are doing an rsync and receive a signal that
# the training has been done. The final checkpoint will be skipped in such
# case. So we do a final sync to make sure that the all directories
# are synced.
for local_dir, gcs_dir in dirs_to_sync:
_rsync_local_to_gcs(local_dir, gcs_dir)
@@ -0,0 +1,35 @@
#!/bin/bash
# !/bin/bash
# The Startup prober built to check whether models listed in local disk are
# loaded in memory and are ready to serve traffic. The script returns 0 if
# succeed. Any other returned value are consider as an error. More detail could be
# found from [shell script Exit codes](http://shellscript.sh/exitcodes.html).
#
# TorchServe: The Management API listens on port 8081 and is only accessible
# from localhost by default.
if [[ -z "${MNG_PORT}" ]]; then
MNG_PORT=7081 # We default the management_port to 7081.
else
MNG_PORT="${MNG_PORT}"
fi
check_model_availability(){
local MODEL_NAME=$1
# Returns whether "READY" is found in the model status.
# Reference: https://pytorch.org/serve/management_api.html#describe-model.
curl -s "http://localhost:${MNG_PORT}/models/${MODEL_NAME}" | grep "READY" -q
}
main(){
check_model_availability "$MODEL" # Assume Dockerfile sets MODEL environment parameter.
local available=$?
if [[ $available -gt 0 ]]
then
echo "Warning: Model(${MODEL}) is not yet available."
return 1
fi
return 0
}
main
@@ -37,18 +37,18 @@
"\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/bigquery_ml/Anomaly_detection_in_Cloud_Audit_logs_with_BQML.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/bigquery_ml/Anomaly_detection_in_Cloud_Audit_logs_with_BQML.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/community/bigquery_ml/Anomaly_detection_in_Cloud_Audit_logs_with_BQML.ipynb\">\n",
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" <img src=\"https://www.gstatic.com/images/branding/gcpiconscolors/vertexai/v1/32px.svg\" alt=\"Vertex AI logo\">\n",
" Open in Vertex AI Workbench\n",
" </a>\n",
" </td> \n",
@@ -47,18 +47,18 @@
"\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/bigquery_ml/bq_ml_with_vision_translation_nlp.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/bigquery_ml/bq_ml_with_vision_translation_nlp.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/community/bigquery_ml/bq_ml_with_vision_translation_nlp.ipynb\">\n",
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" <img src=\"https://www.gstatic.com/images/branding/gcpiconscolors/vertexai/v1/32px.svg\" alt=\"Vertex AI logo\">\n",
" Open in Vertex AI Workbench\n",
" </a>\n",
" </td>\n",
@@ -35,18 +35,18 @@
"\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/bigquery_ml/bqml-online-prediction.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/bigquery_ml/bqml-online-prediction.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/official/bigquery_ml/bqml-online-prediction.ipynb\">\n",
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" <img src=\"https://www.gstatic.com/images/branding/gcpiconscolors/vertexai/v1/32px.svg\" alt=\"Vertex AI logo\">\n",
" Open in Vertex AI Workbench\n",
" </a>\n",
" </td> \n",
@@ -38,7 +38,7 @@
" </td>\n",
" <td>\n",
" <a href=\"github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/cohere/cohere_embedding_with_matching_engine.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
@@ -36,18 +36,18 @@
"\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/vertex_ai_experiments_classification.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/vertex_ai_experiments_classification.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/vertex_ai_experiments_classification.ipynb\">\n",
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" <img src=\"https://www.gstatic.com/images/branding/gcpiconscolors/vertexai/v1/32px.svg\" alt=\"Vertex AI logo\">\n",
" Open in Vertex AI Workbench\n",
" </a>\n",
" </td> \n",
@@ -33,18 +33,18 @@
"\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/explainable_ai/SDK_Custom_Container_XAI.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/explainable_ai/SDK_Custom_Container_XAI.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/explainable_ai/SDK_Custom_Container_XAI.ipynb\">\n",
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" <img src=\"https://www.gstatic.com/images/branding/gcpiconscolors/vertexai/v1/32px.svg\" alt=\"Vertex AI logo\">\n",
" Open in Vertex AI Workbench\n",
" </a>\n",
" </td> \n",
@@ -33,12 +33,12 @@
"\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/official/feature_store/gapic-feature-store.ipynb\"\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/official/feature_store/gapic-feature-store.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
@@ -34,20 +34,20 @@
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage6/get_started_vertex_feature_store_serving.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
" \n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/ml_ops/stage6/get_started_vertex_feature_store_serving.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" \n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/community/ml_ops/stage6/get_started_vertex_feature_store_serving.ipynb\">\n",
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" <img src=\"https://www.gstatic.com/images/branding/gcpiconscolors/vertexai/v1/32px.svg\" alt=\"Vertex AI logo\">\n",
" Open in Vertex AI Workbench\n",
" </a>\n",
" </td>\n",
@@ -33,18 +33,18 @@
"\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/vertex-ai-samples/blob/main/notebooks/community/feature_store/mobile_gaming/mobile_gaming_feature_store.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/feature_store/mobile_gaming/mobile_gaming_feature_store.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/feature_store/mobile_gaming/mobile_gaming_feature_store.ipynb\">\n",
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
" <img src=\"https://www.gstatic.com/images/branding/gcpiconscolors/vertexai/v1/32px.svg\" alt=\"Vertex AI logo\">\n",
" Open in Vertex AI Workbench\n",
" </a>\n",
" </td> \n",
@@ -32,12 +32,12 @@
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/feature_store/sdk-feature-store.ipynb\"\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/feature_store/sdk-feature-store.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
@@ -34,12 +34,12 @@
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_image_classification_batch.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_image_classification_batch.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
@@ -34,12 +34,12 @@
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_image_classification_export_edge.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_image_classification_export_edge.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
@@ -34,12 +34,12 @@
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_image_classification_online.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_image_classification_online.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
@@ -34,12 +34,12 @@
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_image_classification_online_proxy.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_image_classification_online_proxy.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
@@ -34,12 +34,12 @@
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_image_object_detection_batch.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_image_object_detection_batch.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
@@ -34,12 +34,12 @@
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_image_object_detection_export_edge.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_image_object_detection_export_edge.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
@@ -34,12 +34,12 @@
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_image_object_detection_online.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_image_object_detection_online.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
@@ -34,12 +34,12 @@
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_image_segmentation_batch.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_image_segmentation_batch.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
@@ -34,12 +34,12 @@
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_image_segmentation_online.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_image_segmentation_online.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
@@ -34,12 +34,12 @@
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_tabular_binary_classification_batch.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_tabular_binary_classification_batch.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
@@ -34,12 +34,12 @@
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_tabular_binary_classification_online.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_tabular_binary_classification_online.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
@@ -34,12 +34,12 @@
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_tabular_classification_batch.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_tabular_classification_batch.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
@@ -34,12 +34,12 @@
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_tabular_classification_batch_explain.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_tabular_classification_batch_explain.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
@@ -34,12 +34,12 @@
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_tabular_classification_export_cloud.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_tabular_classification_export_cloud.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
@@ -34,12 +34,12 @@
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_tabular_classification_online.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_tabular_classification_online.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
@@ -34,12 +34,12 @@
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_tabular_classification_online_explain.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_tabular_classification_online_explain.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
@@ -34,12 +34,12 @@
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_tabular_forecasting_batch.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_tabular_forecasting_batch.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
@@ -34,12 +34,12 @@
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_tabular_regression_online_bq.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_tabular_regression_online_bq.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",
@@ -34,12 +34,12 @@
"<table align=\"left\">\n",
" <td>\n",
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_text_classification_batch.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
" <img src=\"https://www.gstatic.com/pantheon/images/bigquery/welcome_page/colab-logo.svg\" alt=\"Colab logo\"> Run in Colab\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/gapic/automl/showcase_automl_text_classification_batch.ipynb\">\n",
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
" <img width=\"32px\" src=\"https://www.svgrepo.com/download/217753/github.svg\" alt=\"GitHub logo\">\n",
" View on GitHub\n",
" </a>\n",
" </td>\n",

Some files were not shown because too many files have changed in this diff Show More