mirror of
https://github.com/GoogleCloudPlatform/vertex-ai-samples.git
synced 2026-09-26 22:51:56 +00:00
Compare commits
436
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
20902244de | ||
|
|
c3526504d8 | ||
|
|
9a409b9011 | ||
|
|
c9cca725c6 | ||
|
|
3ddc77293b | ||
|
|
7fa90ee179 | ||
|
|
b88a775d33 | ||
|
|
d58718ce27 | ||
|
|
f380b42d49 | ||
|
|
98be4d8cb4 | ||
|
|
765d6ee296 | ||
|
|
d08959b1a0 | ||
|
|
aec5fbfd6f | ||
|
|
fe42cb6ebd | ||
|
|
7c90baf6e3 | ||
|
|
f9be4f470d | ||
|
|
309889bf6b | ||
|
|
8eabca5939 | ||
|
|
830a762d2d | ||
|
|
be95016723 | ||
|
|
0a7a2f6eeb | ||
|
|
c0196a16b8 | ||
|
|
8e53879df1 | ||
|
|
8ecc2c25c6 | ||
|
|
d98d427271 | ||
|
|
b35c2a89cb | ||
|
|
bc93be1651 | ||
|
|
baa9c06cf7 | ||
|
|
3f3ef75aba | ||
|
|
1a2a0f1d50 | ||
|
|
93a099f65b | ||
|
|
b6804cdf78 | ||
|
|
b641e0857e | ||
|
|
e12faf03ed | ||
|
|
d24f0d0f21 | ||
|
|
c50d38e82f | ||
|
|
52f458fd7d | ||
|
|
eeaf34aa3b | ||
|
|
705f64dc32 | ||
|
|
3830e14fd6 | ||
|
|
bd55db1efc | ||
|
|
07c0f3710f | ||
|
|
f9de0b6315 | ||
|
|
5052d1f44d | ||
|
|
35fbd744e2 | ||
|
|
6d394e639c | ||
|
|
540410ba89 | ||
|
|
26e6548988 | ||
|
|
16de6f1b99 | ||
|
|
8cb2e868ce | ||
|
|
3153e24e57 | ||
|
|
f40a81dda7 | ||
|
|
1590d1cc6f | ||
|
|
6b065f1c5a | ||
|
|
b88fddd6bb | ||
|
|
22454b5318 | ||
|
|
e26190b5e3 | ||
|
|
e6ecd23556 | ||
|
|
a342923353 | ||
|
|
0adcf3d60c | ||
|
|
49547be529 | ||
|
|
9dbd6303b0 | ||
|
|
ac049f3de1 | ||
|
|
3bca163dea | ||
|
|
8904b43308 | ||
|
|
828926e9ab | ||
|
|
851dfb72c1 | ||
|
|
dea652ceca | ||
|
|
56310240b3 | ||
|
|
d828534f28 | ||
|
|
5b6340a15e | ||
|
|
2d3a490aca | ||
|
|
764ea292e5 | ||
|
|
867410462e | ||
|
|
1874743d19 | ||
|
|
b19fcc9f66 | ||
|
|
12db1f9e05 | ||
|
|
853b5c0a97 | ||
|
|
00aa9a2672 | ||
|
|
7eb4eea074 | ||
|
|
4b8b1e503b | ||
|
|
db0f7fb6d7 | ||
|
|
cd04f66ac0 | ||
|
|
419e01d1d3 | ||
|
|
e7a51b394b | ||
|
|
fdfec862be | ||
|
|
6da196a80b | ||
|
|
280f62a1d3 | ||
|
|
20e524dda5 | ||
|
|
b0c7c70b81 | ||
|
|
dcfc30edab | ||
|
|
03fea0608d | ||
|
|
6c15941242 | ||
|
|
1bd5c364f5 | ||
|
|
1c6e4a36c1 | ||
|
|
080d1819ed | ||
|
|
5679e46a12 | ||
|
|
d54b3845fe | ||
|
|
6a2d06f8f4 | ||
|
|
38a37ae8b9 | ||
|
|
be20a635e4 | ||
|
|
db06465158 | ||
|
|
b42b6c6fb8 | ||
|
|
73fbc762fe | ||
|
|
994a86d07a | ||
|
|
71c1eca210 | ||
|
|
20cdcefea3 | ||
|
|
26db26d100 | ||
|
|
01575ae76d | ||
|
|
1c431bdb85 | ||
|
|
096a5d069e | ||
|
|
d795b6e1f5 | ||
|
|
34eaf50f2c | ||
|
|
08ffe85ddf | ||
|
|
3ade1ab265 | ||
|
|
6e71605669 | ||
|
|
f8af22386c | ||
|
|
9d7a744924 | ||
|
|
4f8a527f5c | ||
|
|
4a987f5dcb | ||
|
|
a2a3de5767 | ||
|
|
3ca5d6cad6 | ||
|
|
9117fbbb71 | ||
|
|
607c2605fa | ||
|
|
3509bbc383 | ||
|
|
8593308244 | ||
|
|
806801b4ea | ||
|
|
a1b1ff9a6b | ||
|
|
3acd72ec81 | ||
|
|
12347f3ce2 | ||
|
|
f9c4e32088 | ||
|
|
78da2206b0 | ||
|
|
46fa993732 | ||
|
|
df0c0d209b | ||
|
|
2e8d6239df | ||
|
|
1841201fee | ||
|
|
f10857f299 | ||
|
|
1e4b3aefdb | ||
|
|
e3bcff62fc | ||
|
|
ce3a439d06 | ||
|
|
b47d4b46f3 | ||
|
|
1cc87860c4 | ||
|
|
5d6aa4479d | ||
|
|
5a25b06f2d | ||
|
|
bb055ed061 | ||
|
|
974610a555 | ||
|
|
d78574e640 | ||
|
|
ff367ae9f5 | ||
|
|
40b5e74645 | ||
|
|
dee509e8d7 | ||
|
|
fd5921fa32 | ||
|
|
c74a44a4a8 | ||
|
|
367c985642 | ||
|
|
f7a970e15b | ||
|
|
9a914a5af4 | ||
|
|
e5315be85a | ||
|
|
6daf663a69 | ||
|
|
45a65f1db8 | ||
|
|
240c291728 | ||
|
|
4aec14c576 | ||
|
|
f7d4d3a9c3 | ||
|
|
3c64a8aa58 | ||
|
|
5f692ea299 | ||
|
|
ab1e97ac18 | ||
|
|
78630ae2c0 | ||
|
|
0f48628782 | ||
|
|
93e9fbac92 | ||
|
|
231b2ef02b | ||
|
|
7132c12831 | ||
|
|
2b547e8279 | ||
|
|
8b84524244 | ||
|
|
60fe1bd2c6 | ||
|
|
0edea80ffa | ||
|
|
493e50a999 | ||
|
|
8440e7f164 | ||
|
|
906aa91fe7 | ||
|
|
34e282172f | ||
|
|
bddf642b58 | ||
|
|
25b89c497f | ||
|
|
23a51dbcaa | ||
|
|
26761198d7 | ||
|
|
5b4e88e791 | ||
|
|
83cc796687 | ||
|
|
3e29cc62c7 | ||
|
|
2b1bb77f4b | ||
|
|
7144b87f01 | ||
|
|
ebf4d6d8be | ||
|
|
2ccd913e2e | ||
|
|
d777dd8625 | ||
|
|
d912d3d4d8 | ||
|
|
bafe623590 | ||
|
|
152077a823 | ||
|
|
81c94f9711 | ||
|
|
897e8e3e47 | ||
|
|
ddc125da69 | ||
|
|
abb66ade41 | ||
|
|
2915824641 | ||
|
|
44447637bd | ||
|
|
6a8345446d | ||
|
|
27a7b8b1da | ||
|
|
04471e7104 | ||
|
|
e78ea4e805 | ||
|
|
7487a14783 | ||
|
|
757d0c5087 | ||
|
|
60cb93a9a9 | ||
|
|
0fb72773f4 | ||
|
|
5d2fc74f78 | ||
|
|
1cc26481b2 | ||
|
|
85b0346eab | ||
|
|
910cbacb54 | ||
|
|
c7206e3cc8 | ||
|
|
12d721d33e | ||
|
|
16df2216d1 | ||
|
|
fb26b7213c | ||
|
|
d90f52e122 | ||
|
|
652f34b814 | ||
|
|
c84f8738f8 | ||
|
|
9d72bbf237 | ||
|
|
85df50d06f | ||
|
|
9ab6cddade | ||
|
|
02ffffaeb7 | ||
|
|
dfc5635d34 | ||
|
|
90b686cf69 | ||
|
|
ad63153778 | ||
|
|
7858f8644e | ||
|
|
3df4098364 | ||
|
|
ae3c1877e4 | ||
|
|
2798ab1e02 | ||
|
|
7bd2c567a1 | ||
|
|
56503cce6a | ||
|
|
a5a9f53a32 | ||
|
|
469e8436e9 | ||
|
|
e9f9a5c29b | ||
|
|
102400a67f | ||
|
|
0ae53f47d4 | ||
|
|
ff3e0b4784 | ||
|
|
0f4546c18c | ||
|
|
ee381e15f5 | ||
|
|
4ddeeb290d | ||
|
|
7e99b07440 | ||
|
|
bc1ecd6260 | ||
|
|
f662ffb3e1 | ||
|
|
c40c0e5247 | ||
|
|
bd3a0f5af0 | ||
|
|
99f318333b | ||
|
|
11e7ba47a4 | ||
|
|
399427c2de | ||
|
|
0f116ab253 | ||
|
|
304000d719 | ||
|
|
36df462615 | ||
|
|
909f771bfd | ||
|
|
e9bef3542d | ||
|
|
037a3b041a | ||
|
|
f55e6c60cd | ||
|
|
2cd815c640 | ||
|
|
b1c0cc9a9d | ||
|
|
af63d1c0e2 | ||
|
|
c51a82febb | ||
|
|
8e6e4729aa | ||
|
|
0e97a83836 | ||
|
|
f6645e0125 | ||
|
|
52385a6071 | ||
|
|
2365d733c4 | ||
|
|
71e6423066 | ||
|
|
139ed95ffc | ||
|
|
cafd192417 | ||
|
|
0d7ec7cd60 | ||
|
|
7fd934045a | ||
|
|
4e82877269 | ||
|
|
6ef111144d | ||
|
|
e9b8aa02e9 | ||
|
|
ac1af33c8c | ||
|
|
5bc18b01e4 | ||
|
|
e98b9d6eb4 | ||
|
|
5e6b8bf597 | ||
|
|
5b39e7d995 | ||
|
|
c4f08589a9 | ||
|
|
04c6ff4ec7 | ||
|
|
bcb0b19dc4 | ||
|
|
5586fd7c4d | ||
|
|
30e747b966 | ||
|
|
080e2b5bb5 | ||
|
|
e908774b5b | ||
|
|
60e4416a7e | ||
|
|
b207b270b4 | ||
|
|
497e93aba1 | ||
|
|
9a6c36d016 | ||
|
|
c889a57c9e | ||
|
|
dbe5d61929 | ||
|
|
c180408f41 | ||
|
|
869b19d342 | ||
|
|
3d967b180d | ||
|
|
49710a9225 | ||
|
|
9d31463585 | ||
|
|
bcd86a3707 | ||
|
|
9335ea3591 | ||
|
|
0f7343feee | ||
|
|
12cd965ce6 | ||
|
|
4e5c75fed6 | ||
|
|
b28f941abe | ||
|
|
32632711ff | ||
|
|
d676d87cce | ||
|
|
153a8044b8 | ||
|
|
c0d9250416 | ||
|
|
fd16e39f91 | ||
|
|
1551ca9435 | ||
|
|
80fcd2904f | ||
|
|
e974c034ba | ||
|
|
f0112cfc9a | ||
|
|
d2d4493397 | ||
|
|
33e7d18502 | ||
|
|
6628866130 | ||
|
|
0cd6146a6c | ||
|
|
b61395f465 | ||
|
|
649b209577 | ||
|
|
506a6e66d7 | ||
|
|
5bd6cfe6a7 | ||
|
|
ca27881ca7 | ||
|
|
5fa0ed6185 | ||
|
|
14f58e30c5 | ||
|
|
6af94b51aa | ||
|
|
2f818117db | ||
|
|
04fe89c556 | ||
|
|
f42a184171 | ||
|
|
03f0647b76 | ||
|
|
1f39732ae9 | ||
|
|
7dd0b31b58 | ||
|
|
ff843173cf | ||
|
|
da19b116e9 | ||
|
|
d8b365dfd4 | ||
|
|
1247c80fed | ||
|
|
2cf2bf1080 | ||
|
|
5e9e8139c1 | ||
|
|
0728a0036f | ||
|
|
aa52d21643 | ||
|
|
103888d75e | ||
|
|
13d0d5d9b0 | ||
|
|
79c6669686 | ||
|
|
dceb0c4c1c | ||
|
|
0c9cdca713 | ||
|
|
6124092681 | ||
|
|
629e739327 | ||
|
|
b68cbd8255 | ||
|
|
7fec30c12f | ||
|
|
a754843c39 | ||
|
|
436db4a35b | ||
|
|
8dba2d040b | ||
|
|
560dd9da15 | ||
|
|
8ec17d6aca | ||
|
|
f545282c36 | ||
|
|
7e4e14e084 | ||
|
|
be5933115d | ||
|
|
be46140138 | ||
|
|
79f4dbaafe | ||
|
|
9577f8324c | ||
|
|
01274fe767 | ||
|
|
1690b07e4a | ||
|
|
6b0de60a5c | ||
|
|
19b541b6cb | ||
|
|
22f6841079 | ||
|
|
7c47c95e3a | ||
|
|
7735e6ae69 | ||
|
|
247a540625 | ||
|
|
f017606f77 | ||
|
|
1d7024341a | ||
|
|
9181dba316 | ||
|
|
a8320f3943 | ||
|
|
6fc34ae4f1 | ||
|
|
5566346fdc | ||
|
|
e584acdb48 | ||
|
|
4022811d3c | ||
|
|
4d29c490f8 | ||
|
|
2315942901 | ||
|
|
505d5049e0 | ||
|
|
20411db737 | ||
|
|
39dbbde22c | ||
|
|
34251594a4 | ||
|
|
7342673331 | ||
|
|
b5d19719e0 | ||
|
|
59536e9e61 | ||
|
|
7d74bc3caa | ||
|
|
f681879a8a | ||
|
|
b5b65198a6 | ||
|
|
3a5a14f1d8 | ||
|
|
157f8538ed | ||
|
|
532bf04933 | ||
|
|
99547ccb73 | ||
|
|
2e0cd74533 | ||
|
|
b9a9d76e8b | ||
|
|
fb61e0631c | ||
|
|
16c38c8fbf | ||
|
|
8888e8ad7f | ||
|
|
c787a0e99e | ||
|
|
8ea77a7cb0 | ||
|
|
2bb6d6deb2 | ||
|
|
7b235c935a | ||
|
|
3c88e9284c | ||
|
|
e967b02a22 | ||
|
|
aeb87cbc44 | ||
|
|
1f39a8f892 | ||
|
|
d2a6508379 | ||
|
|
39d1646b3c | ||
|
|
4c5ede0130 | ||
|
|
7715f79807 | ||
|
|
7c8eeeb1d1 | ||
|
|
6caffbe5c3 | ||
|
|
99929ca018 | ||
|
|
6aadabd967 | ||
|
|
9b5be742c1 | ||
|
|
63d5b5e3bf | ||
|
|
e01174f169 | ||
|
|
62c903f47d | ||
|
|
da77846b88 | ||
|
|
7c123e68d3 | ||
|
|
9f26e8385d | ||
|
|
0fffaee6dc | ||
|
|
c34b7ab651 | ||
|
|
d57d9be9d4 | ||
|
|
88f3ecf567 | ||
|
|
ecfbeaa8ce | ||
|
|
3e5a319455 | ||
|
|
f35ce3432a | ||
|
|
2e9ff4a941 | ||
|
|
61fbd37fa4 | ||
|
|
474e4e602b | ||
|
|
e409cf710b | ||
|
|
e9bac09dce | ||
|
|
b799aad08a | ||
|
|
4d6bd1afff | ||
|
|
b4040ff01d | ||
|
|
c29e4fde26 | ||
|
|
c6fdad745f | ||
|
|
3c60c2cb97 | ||
|
|
278a014817 | ||
|
|
89ec43c706 | ||
|
|
ba6be7ee99 |
@@ -7,6 +7,12 @@ from resource_cleanup_manager import (
|
||||
ResourceCleanupManager,
|
||||
MatchingEngineIndexEndpointResourceCleanupManager,
|
||||
MatchingEngineIndexResourceCleanupManager,
|
||||
FeatureStoreCleanupManager,
|
||||
PipelineJobCleanupManager,
|
||||
TrainingJobCleanupManager,
|
||||
HyperparameterTuningCleanupManager,
|
||||
BatchPredictionJobCleanupManager,
|
||||
ExperimentCleanupManager
|
||||
)
|
||||
|
||||
rate_limit = RateLimit(max_count=25, per=60, greedy=False)
|
||||
@@ -48,6 +54,12 @@ managers: List[ResourceCleanupManager] = [
|
||||
ModelResourceCleanupManager(), # ModelResourceCleanupManager must follow EndpointResourceCleanupManager due to deployed models blocking model deletion.
|
||||
MatchingEngineIndexEndpointResourceCleanupManager(),
|
||||
MatchingEngineIndexResourceCleanupManager(),
|
||||
FeatureStoreCleanupManager(),
|
||||
PipelineJobCleanupManager(),
|
||||
TrainingJobCleanupManager(),
|
||||
HyperparameterTuningCleanupManager(),
|
||||
BatchPredictionJobCleanupManager(),
|
||||
# ExperimentCleanupManager(), # Experiment missing _resource_noun
|
||||
]
|
||||
|
||||
run_cleanup_managers(managers=managers, is_dry_run=is_dry_run)
|
||||
|
||||
@@ -97,13 +97,10 @@ class EndpointResourceCleanupManager(VertexAIResourceCleanupManager):
|
||||
vertex_ai_resource = aiplatform.Endpoint
|
||||
|
||||
def delete(self, resource):
|
||||
# TODO: Remove this once https://github.com/googleapis/python-aiplatform/issues/1441 is fixed
|
||||
resource._sync_gca_resource()
|
||||
for deployed_model_id in [
|
||||
models.id for models in resource._gca_resource.deployed_models
|
||||
]:
|
||||
resource._undeploy(deployed_model_id=deployed_model_id)
|
||||
|
||||
resource.delete(force=True)
|
||||
|
||||
|
||||
@@ -117,3 +114,45 @@ class MatchingEngineIndexResourceCleanupManager(VertexAIResourceCleanupManager):
|
||||
|
||||
class MatchingEngineIndexEndpointResourceCleanupManager(VertexAIResourceCleanupManager):
|
||||
vertex_ai_resource = aiplatform.MatchingEngineIndexEndpoint
|
||||
|
||||
def delete(self, resource):
|
||||
resource.undeploy_all()
|
||||
resource.delete(force=True)
|
||||
|
||||
class FeatureStoreCleanupManager(VertexAIResourceCleanupManager):
|
||||
vertex_ai_resource = aiplatform.Featurestore
|
||||
|
||||
class PipelineJobCleanupManager(VertexAIResourceCleanupManager):
|
||||
vertex_ai_resource = aiplatform.PipelineJob
|
||||
|
||||
class TrainingJobCleanupManager(VertexAIResourceCleanupManager):
|
||||
vertex_ai_resource = aiplatform.training_jobs._CustomTrainingJob
|
||||
|
||||
job_types = [
|
||||
aiplatform.AutoMLImageTrainingJob,
|
||||
aiplatform.AutoMLTextTrainingJob,
|
||||
aiplatform.AutoMLTabularTrainingJob,
|
||||
aiplatform.AutoMLVideoTrainingJob,
|
||||
aiplatform.AutoMLForecastingTrainingJob,
|
||||
aiplatform.CustomJob,
|
||||
aiplatform.CustomTrainingJob,
|
||||
aiplatform.CustomContainerTrainingJob,
|
||||
aiplatform.CustomPythonPackageTrainingJob
|
||||
]
|
||||
|
||||
def list(self) -> Any:
|
||||
return [
|
||||
job
|
||||
for job_type in self.job_types
|
||||
for job in job_type.list()
|
||||
]
|
||||
|
||||
class HyperparameterTuningCleanupManager(VertexAIResourceCleanupManager):
|
||||
vertex_ai_resource = aiplatform.HyperparameterTuningJob
|
||||
|
||||
|
||||
class BatchPredictionJobCleanupManager(VertexAIResourceCleanupManager):
|
||||
vertex_ai_resource = aiplatform.BatchPredictionJob
|
||||
|
||||
class ExperimentCleanupManager(VertexAIResourceCleanupManager):
|
||||
vertex_ai_resource = aiplatform.Experiment
|
||||
|
||||
@@ -156,7 +156,7 @@ def _create_tag(filepath: str) -> str:
|
||||
return tag
|
||||
|
||||
|
||||
rate_limit = RateLimit(max_count=50, per=60, greedy=True)
|
||||
rate_limit = RateLimit(max_count=25, per=60, greedy=True)
|
||||
|
||||
|
||||
def process_and_execute_notebook(
|
||||
@@ -245,7 +245,7 @@ def process_and_execute_notebook(
|
||||
result.logs_bucket = operation_metadata.build.logs_bucket
|
||||
|
||||
# Block and wait for the result
|
||||
operation_result = operation.result(timeout=86400)
|
||||
operation_result = operation.result(timeout=timeout_in_seconds)
|
||||
|
||||
result.duration = datetime.datetime.now() - time_start
|
||||
result.is_pass = True
|
||||
|
||||
@@ -10,4 +10,5 @@ google-cloud-aiplatform
|
||||
google-cloud-storage
|
||||
google-cloud-build
|
||||
ratemate
|
||||
GitPython
|
||||
GitPython
|
||||
tqdm
|
||||
@@ -2,9 +2,9 @@ git+https://github.com/tensorflow/docs
|
||||
ipython
|
||||
jupyter
|
||||
nbconvert
|
||||
black==22.10.0
|
||||
black==22.12.0
|
||||
pyupgrade==2.38.4
|
||||
isort==5.10.1
|
||||
flake8==4.0.1
|
||||
isort==5.12.0
|
||||
flake8==6.0.0
|
||||
nbqa==1.5.3
|
||||
|
||||
|
||||
+3
-5
@@ -44,12 +44,10 @@ Finally, run this code block to check for errors. Each step will attempt to
|
||||
automatically fix any issues. If the fixes can't be performed automatically,
|
||||
then you will need to manually address them before submitting your PR.
|
||||
|
||||
Note: For official, only submit one notebook per PR.
|
||||
|
||||
```shell
|
||||
nbqa black "$notebook"
|
||||
nbqa pyupgrade "$notebook"
|
||||
nbqa isort "$notebook"
|
||||
nbqa flake8 "$notebook" --extend-ignore=W391,E501,F821,E402,F404,W503,E203,E722,W293,W291
|
||||
python3 -m tensorflow_docs.tools.nbfmt --remove_outputs "$notebook"
|
||||
docker run -v ${PWD}:/setup/app gcr.io/cloud-devrel-public-resources/notebook_linter:latest your_notebook
|
||||
```
|
||||
|
||||
## Code Reviews
|
||||
|
||||
@@ -8,3 +8,5 @@
|
||||
/cpr-examples @samthrasher
|
||||
/Train_tabular_models_with_many_frameworks_and_import_to_Vertex_AI_using_Pipelines @Ark-kun
|
||||
/pipeline_components @Ark-kun
|
||||
/pipeline_components/image_ml_model_training @lakeyk
|
||||
/prediction_featurestore_integration @googleapis/vertex-prediction-team
|
||||
|
||||
+2
-2
@@ -6,8 +6,8 @@ download_from_gcs_op = components.load_component_from_url("https://raw.githubuse
|
||||
select_columns_using_Pandas_on_CSV_data_op = components.load_component_from_url("https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/399405402d95f4a011e2d2e967c96f8508ba5688/community-content/pipeline_components/pandas/Select_columns/in_CSV_format/component.yaml")
|
||||
fill_all_missing_values_using_Pandas_on_CSV_data_op = components.load_component_from_url("https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/399405402d95f4a011e2d2e967c96f8508ba5688/community-content/pipeline_components/pandas/Fill_all_missing_values/in_CSV_format/component.yaml")
|
||||
binarize_column_using_Pandas_on_CSV_data_op = components.load_component_from_url("https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/399405402d95f4a011e2d2e967c96f8508ba5688/community-content/pipeline_components/pandas/Binarize_column/in_CSV_format/component.yaml")
|
||||
train_logistic_regression_model_using_scikit_learn_from_CSV_op = components.load_component_from_url("https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/399405402d95f4a011e2d2e967c96f8508ba5688/community-content/pipeline_components/ML_frameworks/Scikit_learn/Train_logistic_regression_model/from_CSV/component.yaml")
|
||||
upload_Scikit_learn_pickle_model_to_Google_Cloud_Vertex_AI_op = components.load_component_from_url("https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/1f5cf6e06409b704064b2086c0a705e4e6b4fcde/community-content/pipeline_components/google-cloud/Vertex_AI/Models/Upload_Scikit-learn_pickle_model/component.yaml")
|
||||
train_logistic_regression_model_using_scikit_learn_from_CSV_op = components.load_component_from_url("https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/1f5cf6e06409b704064b2086c0a705e4e6b4fcde/community-content/pipeline_components/ML_frameworks/Scikit_learn/Train_logistic_regression_model/from_CSV/component.yaml")
|
||||
upload_Scikit_learn_pickle_model_to_Google_Cloud_Vertex_AI_op = components.load_component_from_url("https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/399405402d95f4a011e2d2e967c96f8508ba5688/community-content/pipeline_components/google-cloud/Vertex_AI/Models/Upload_Scikit-learn_pickle_model/component.yaml")
|
||||
deploy_model_to_endpoint_op = components.load_component_from_url("https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/399405402d95f4a011e2d2e967c96f8508ba5688/community-content/pipeline_components/google-cloud/Vertex_AI/Models/Deploy_to_endpoint/component.yaml")
|
||||
|
||||
# %% Pipeline definition
|
||||
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
name: Load image classification model from tfhub
|
||||
description: |
|
||||
Loads specified model from TFHub, creates layer to receive additional (3 channel) imagery data.
|
||||
Args:
|
||||
class_names (Sequence[str]):
|
||||
Sequence of strings of categories for classification corresponding to input data.
|
||||
loaded_model_path (str):
|
||||
Output path for the loaded model.
|
||||
image_size_path (str):
|
||||
Output path for the model expected image size.
|
||||
model_name (Optional[str]):
|
||||
Name of the pre-trained image classification model to load from TFHub.
|
||||
Eligible model_name:
|
||||
- efficientnetv2-s
|
||||
- efficientnetv2-m
|
||||
- efficientnetv2-l
|
||||
- efficientnetv2-s-21k
|
||||
- efficientnetv2-m-21k
|
||||
- efficientnetv2-l-21k
|
||||
- efficientnetv2-xl-21k
|
||||
- efficientnetv2-b0-21k
|
||||
- efficientnetv2-b1-21k
|
||||
- efficientnetv2-b2-21k
|
||||
- efficientnetv2-b3-21k
|
||||
- efficientnetv2-s-21k-ft1k
|
||||
- efficientnetv2-m-21k-ft1k
|
||||
- efficientnetv2-l-21k-ft1k
|
||||
- efficientnetv2-xl-21k-ft1k
|
||||
- efficientnetv2-b0-21k-ft1k
|
||||
- efficientnetv2-b1-21k-ft1k
|
||||
- efficientnetv2-b2-21k-ft1k
|
||||
- efficientnetv2-b3-21k-ft1k
|
||||
- efficientnetv2-b0
|
||||
- efficientnetv2-b1
|
||||
- efficientnetv2-b2
|
||||
- efficientnetv2-b3
|
||||
- efficientnet_b0
|
||||
- efficientnet_b1
|
||||
- efficientnet_b2
|
||||
- efficientnet_b3
|
||||
- efficientnet_b4
|
||||
- efficientnet_b5
|
||||
- efficientnet_b6
|
||||
- efficientnet_b7
|
||||
- bit_s-r50x1
|
||||
- inception_v3
|
||||
- inception_resnet_v2
|
||||
- resnet_v1_50
|
||||
- resnet_v1_101
|
||||
- resnet_v1_152
|
||||
- resnet_v2_50
|
||||
- resnet_v2_101
|
||||
- resnet_v2_152
|
||||
- nasnet_large
|
||||
- nasnet_mobile
|
||||
- pnasnet_large
|
||||
- mobilenet_v2_100_224
|
||||
- mobilenet_v2_130_224
|
||||
- mobilenet_v2_140_224
|
||||
- mobilenet_v3_small_100_224
|
||||
- mobilenet_v3_small_075_224
|
||||
- mobilenet_v3_large_100_224
|
||||
- mobilenet_v3_large_075_224
|
||||
dropout_rate (Optional[float]):
|
||||
Fraction of input units to drop in the last layer. Value should be between 0.0 and 1.0.
|
||||
trainable (Optional[bool]):
|
||||
If true fine tuning will be performed on entire Hub model. If false only additional
|
||||
layers will be trained.
|
||||
l2_regularization_penalty (Optional[float]):
|
||||
l2 regularization penalty.
|
||||
inputs:
|
||||
- {name: class_names, type: 'typing.List[str]', description: List of class names corresponding
|
||||
to the input image data}
|
||||
- {name: model_name, type: String, description: Name of the TFHub model to load, default: efficientnetv2-xl-21k,
|
||||
optional: true}
|
||||
- {name: dropout_rate, type: Float, description: Dropout rate, default: '0.2', optional: true}
|
||||
- name: trainable
|
||||
type: Boolean
|
||||
description: True if fine tuning should be performed
|
||||
default: "True"
|
||||
optional: true
|
||||
- {name: l2_regularization_penalty, type: Float, description: Regularization penalty,
|
||||
default: '0.0001', optional: true}
|
||||
outputs:
|
||||
- {name: loaded_model_path, type: TensorflowSavedModel, description: Output path for
|
||||
the loaded model}
|
||||
- {name: image_size_path, type: HeightWidth}
|
||||
implementation:
|
||||
container:
|
||||
image: us-docker.pkg.dev/vertex-ai/ready-to-go-image-classification/image-components:v0.1
|
||||
# command is a list of strings (command-line arguments).
|
||||
# The YAML language has two syntaxes for lists and you can use either of them.
|
||||
# Here we use the "flow syntax" - comma-separated strings inside square brackets.
|
||||
command: [
|
||||
python3,
|
||||
# Path of the program inside the container
|
||||
/pipelines/component/src/loading_component.py,
|
||||
--loaded-model-path,
|
||||
{outputPath: loaded_model_path},
|
||||
--class-names,
|
||||
{inputValue: class_names},
|
||||
--model-name,
|
||||
{inputValue: model_name},
|
||||
--dropout-rate,
|
||||
{inputValue: dropout_rate},
|
||||
--trainable,
|
||||
{inputValue: trainable},
|
||||
--l2-regularization-penalty,
|
||||
{inputValue: l2_regularization_penalty},
|
||||
--image-size-path,
|
||||
{outputPath: image_size_path},
|
||||
]
|
||||
@@ -0,0 +1,62 @@
|
||||
# python3 -m pip install "kfp<2.0.0" "google-cloud-aiplatform>=1.16.0" --upgrade --quiet
|
||||
from kfp import components
|
||||
from kfp.v2 import dsl
|
||||
|
||||
# %% Loading components
|
||||
upload_Tensorflow_model_to_Google_Cloud_Vertex_AI_op = components.load_component_from_url('https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/399405402d95f4a011e2d2e967c96f8508ba5688/community-content/pipeline_components/google-cloud/Vertex_AI/Models/Upload_Tensorflow_model/component.yaml')
|
||||
deploy_model_to_endpoint_op = components.load_component_from_url('https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/399405402d95f4a011e2d2e967c96f8508ba5688/community-content/pipeline_components/google-cloud/Vertex_AI/Models/Deploy_to_endpoint/component.yaml')
|
||||
transcode_imagedataset_tfrecord_from_csv_op = components.load_component_from_url('https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/community-content/pipeline_components/image_ml_model_training/transcode_tfrecord_image_dataset_from_csv/component.yaml')
|
||||
load_image_classification_model_from_tfhub_op = components.load_component_from_url('https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/b5b65198a6c2ffe8c0fa2aa70127e3325752df68/community-content/pipeline_components/image_ml_model_training/load_image_classification_model/component.yaml')
|
||||
preprocess_image_data_op = components.load_component_from_url('https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/community-content/pipeline_components/image_ml_model_training/preprocess_image_data/component.yaml')
|
||||
train_tensorflow_image_classification_model_op = components.load_component_from_url('https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/community-content/pipeline_components/image_ml_model_training/train_image_classification_model/component.yaml')
|
||||
|
||||
|
||||
# %% Pipeline definition
|
||||
def image_classification_pipeline():
|
||||
class_names = ['daisy', 'dandelion', 'roses', 'sunflowers', 'tulips']
|
||||
csv_image_data_path = 'gs://cloud-samples-data/ai-platform/flowers/flowers.csv'
|
||||
deploy_model = False
|
||||
|
||||
image_data = dsl.importer(
|
||||
artifact_uri=csv_image_data_path, artifact_class=dsl.Dataset).output
|
||||
|
||||
image_tfrecord_data = transcode_imagedataset_tfrecord_from_csv_op(
|
||||
csv_image_data_path=image_data,
|
||||
class_names=class_names
|
||||
).outputs['tfrecord_image_data_path']
|
||||
|
||||
loaded_model_outputs = load_image_classification_model_from_tfhub_op(
|
||||
class_names=class_names,
|
||||
).outputs
|
||||
|
||||
preprocessed_data = preprocess_image_data_op(
|
||||
image_tfrecord_data,
|
||||
height_width_path=loaded_model_outputs['image_size_path'],
|
||||
).outputs
|
||||
|
||||
trained_model = (train_tensorflow_image_classification_model_op(
|
||||
preprocessed_training_data_path = preprocessed_data['preprocessed_training_data_path'],
|
||||
preprocessed_validation_data_path = preprocessed_data['preprocessed_validation_data_path'],
|
||||
model_path=loaded_model_outputs['loaded_model_path']).
|
||||
set_cpu_limit('96').
|
||||
set_memory_limit('128G').
|
||||
add_node_selector_constraint('cloud.google.com/gke-accelerator', 'NVIDIA_TESLA_A100').
|
||||
set_gpu_limit('8').
|
||||
outputs['trained_model_path'])
|
||||
|
||||
vertex_model_name = upload_Tensorflow_model_to_Google_Cloud_Vertex_AI_op(
|
||||
model=trained_model,
|
||||
).outputs['model_name']
|
||||
|
||||
# Deploying the model might incur additional costs over time
|
||||
if deploy_model:
|
||||
vertex_endpoint_name = deploy_model_to_endpoint_op(
|
||||
model_name=vertex_model_name,
|
||||
).outputs['endpoint_name']
|
||||
|
||||
pipeline_func = image_classification_pipeline
|
||||
|
||||
# %% Pipeline submission
|
||||
if __name__ == '__main__':
|
||||
from google.cloud import aiplatform
|
||||
aiplatform.PipelineJob.from_pipeline_func(pipeline_func=pipeline_func).submit()
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
name: Preprocess image data
|
||||
description: |
|
||||
Preprocess the image data and split between train and validation.
|
||||
Args:
|
||||
input_data_path (str):
|
||||
Input path for the TFRecord image data. Data will be formatted as 'label' (encoded image
|
||||
label), and 'image_raw' (the binary string of the image data).
|
||||
height_width_path (str):
|
||||
Path to square height and width to resize images to. File should contain single float value.
|
||||
Value is dependent on training model.
|
||||
preprocessed_training_data_path (str):
|
||||
Output path for the TFRecord training data. Data will be formatted as 'label' (encoded image
|
||||
label), and 'image_raw' (the binary string of the image data).
|
||||
preprocessed_validation_data_path (str):
|
||||
Output path for the TFRecord validation data. Data will be formatted as 'label' (encoded
|
||||
image label), and 'image_raw' (the binary string of the image data).
|
||||
validation_split (Optional[float]):
|
||||
Fraction of data that will make up validation dataset. Value should be between 0.0 and 1.0.
|
||||
seed (Optional[int]):
|
||||
The global random seed to ensure the system gets a unique random sequence
|
||||
that is deterministic (https://www.tensorflow.org/api_docs/python/tf/random/set_seed).
|
||||
inputs:
|
||||
- {name: input_data_path, type: ImageDatasetTFRecord, description: 'Input path for
|
||||
the TFRecord image data,'}
|
||||
- {name: height_width_path, type: HeightWidth, description: 'Path to square height and width to
|
||||
resize images to,'}
|
||||
- {name: validation_split, type: Float, description: 'Fraction of data that will make
|
||||
up validation dataset,', default: '0.2', optional: true}
|
||||
- {name: seed, type: Integer, description: Random seed, default: '0', optional: true}
|
||||
outputs:
|
||||
- {name: preprocessed_training_data_path, type: ImageDatasetTFRecord, description: 'Output
|
||||
path for the training data,'}
|
||||
- {name: preprocessed_validation_data_path, type: ImageDatasetTFRecord, description: 'Output
|
||||
path for the validation data,'}
|
||||
implementation:
|
||||
container:
|
||||
image: us-docker.pkg.dev/vertex-ai/ready-to-go-image-classification/image-components:v0.1
|
||||
# command is a list of strings (command-line arguments).
|
||||
# The YAML language has two syntaxes for lists and you can use either of them.
|
||||
# Here we use the "flow syntax" - comma-separated strings inside square brackets.
|
||||
command: [
|
||||
python3,
|
||||
# Path of the program inside the container
|
||||
/pipelines/component/src/preprocessing_component.py,
|
||||
--input-data-path,
|
||||
{inputPath: input_data_path},
|
||||
--height-width-path,
|
||||
{inputPath: height_width_path},
|
||||
--validation-split,
|
||||
{inputValue: validation_split},
|
||||
--seed,
|
||||
{inputValue: seed},
|
||||
--preprocessed-training-data-path,
|
||||
{outputPath: preprocessed_training_data_path},
|
||||
--preprocessed-validation-data-path,
|
||||
{outputPath: preprocessed_validation_data_path},
|
||||
]
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
name: Train tensorflow image classification model
|
||||
description: |
|
||||
Creates a trained image classification TensorFlow model.
|
||||
Args:
|
||||
preprocessed_training_data_path (str):
|
||||
Input path to the TFRecord training data. Data will be formatted as 'label' (encoded image
|
||||
label), and 'image_raw' (the binary string of the image data).
|
||||
preprocessed_validation_data_path (str):
|
||||
Input path to the TFRecord validation data. Data will be formatted as 'label' (encoded
|
||||
image label), and 'image_raw' (the binary string of the image data).
|
||||
model_path (str):
|
||||
Input path to the loaded pre-trained model.
|
||||
trained_model_path (str):
|
||||
Output path to save the trained model to.
|
||||
optimizer_name (Optional[str]):
|
||||
Name of the tf.keras optimizer. Available optimizers are listed at
|
||||
https://keras.io/api/optimizers/
|
||||
optimizer_parameters (Optional[Dict[str, str]]):
|
||||
Optimizer parameters.
|
||||
loss_function_name (Optional[str]):
|
||||
Name of the loss function.
|
||||
loss_function_parameters (Optional[Dict[str, str]]):
|
||||
Loss function parameters.
|
||||
number_of_epochs (Optional[int]):
|
||||
Number of training iterations over data.
|
||||
metric_names (Optional[Sequence[str]]):
|
||||
List of tf.keras.metrics to be evaluated by the model during training and testing. Available
|
||||
metrics are listed at https://keras.io/api/metrics/.
|
||||
seed Optional(int):
|
||||
The global random seed to ensure the system gets a unique random sequence
|
||||
that is deterministic (https://www.tensorflow.org/api_docs/python/tf/random/set_seed).
|
||||
inputs:
|
||||
- {name: preprocessed_training_data_path, type: ImageDatasetTFRecord, description: 'Input
|
||||
path for the training data,'}
|
||||
- {name: preprocessed_validation_data_path, type: ImageDatasetTFRecord, description: 'Input
|
||||
path for the validation data,'}
|
||||
- {name: model_path, type: TensorflowSavedModel, description: 'Input path for the
|
||||
model,'}
|
||||
- {name: optimizer_name, type: String, description: 'Name of the optimizer,', default: SGD,
|
||||
optional: true}
|
||||
- {name: optimizer_parameters, type: 'typing.Dict[str, str]', description: 'Optimizer
|
||||
parameters,', default: '{}', optional: true}
|
||||
- {name: loss_function_name, type: String, description: 'Name of the loss function,',
|
||||
default: CategoricalCrossentropy, optional: true}
|
||||
- {name: loss_function_parameters, type: 'typing.Dict[str, str]', description: 'Loss
|
||||
function parameters,', default: '{}', optional: true}
|
||||
- {name: number_of_epochs, type: Integer, description: 'Number of epochs,', default: '10',
|
||||
optional: true}
|
||||
- {name: metric_names, type: 'typing.List[str]', description: 'List of metrics to
|
||||
use,', default: '["accuracy"]', optional: true}
|
||||
- {name: seed, type: Integer, description: 'Random seed,', default: '0', optional: true}
|
||||
- {name: batch_size, type: Integer, description: Batch size, default: '16', optional: true}
|
||||
outputs:
|
||||
- {name: trained_model_path, type: TensorflowSavedModel, description: 'Output path
|
||||
for the saved model,'}
|
||||
implementation:
|
||||
container:
|
||||
image: us-docker.pkg.dev/vertex-ai/ready-to-go-image-classification/image-components:v0.1
|
||||
# command is a list of strings (command-line arguments).
|
||||
# The YAML language has two syntaxes for lists and you can use either of them.
|
||||
# Here we use the "flow syntax" - comma-separated strings inside square brackets.
|
||||
command: [
|
||||
python3,
|
||||
# Path of the program inside the container
|
||||
/pipelines/component/src/training_component.py,
|
||||
--preprocessed-training-data-path,
|
||||
{inputPath: preprocessed_training_data_path},
|
||||
--preprocessed-validation-data-path,
|
||||
{inputPath: preprocessed_validation_data_path},
|
||||
--model-path,
|
||||
{inputPath: model_path},
|
||||
--trained-model-path,
|
||||
{outputPath: trained_model_path},
|
||||
--optimizer-name,
|
||||
{inputValue: optimizer_name},
|
||||
--loss-function-name,
|
||||
{inputValue: loss_function_name},
|
||||
--number-of-epochs,
|
||||
{inputValue: number_of_epochs},
|
||||
--seed,
|
||||
{inputValue: seed},
|
||||
--batch-size,
|
||||
{inputValue: batch_size},
|
||||
--metric-names,
|
||||
{inputValue: metric_names},
|
||||
--optimizer-parameters,
|
||||
{inputValue: optimizer_parameters},
|
||||
--loss-function-parameters,
|
||||
{inputValue: loss_function_parameters},
|
||||
]
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
name: Transcode imagedataset tfrecord from csv
|
||||
description: |
|
||||
Transcodes CSV Data into TFRecord file of TFExamples.
|
||||
Args:
|
||||
csv_image_data_path (str):
|
||||
Path to the CSV image data. Data must include 'image_filepath' (Path to image file) and
|
||||
'image_label' (output for a prediction) fields.
|
||||
class_names (Sequence[str]):
|
||||
Sequence of strings of categories for classification corresponding to input data.
|
||||
tfrecord_image_data_path (str):
|
||||
Output path for the TFRecord image data. Data will be formatted as 'label' (encoded image
|
||||
label), and 'image_raw' (the binary string of the image data).
|
||||
inputs:
|
||||
- {name: csv_image_data_path, type: ImageDatasetCSV, description: Input path for the
|
||||
CSV image data}
|
||||
- {name: class_names, type: 'typing.List[str]', description: List of class names corresponding
|
||||
to the input image data}
|
||||
outputs:
|
||||
- {name: tfrecord_image_data_path, type: ImageDatasetTFRecord, description: Output
|
||||
path for the TFRecord image data}
|
||||
implementation:
|
||||
container:
|
||||
image: us-docker.pkg.dev/vertex-ai/ready-to-go-image-classification/image-components:v0.1
|
||||
# command is a list of strings (command-line arguments).
|
||||
# The YAML language has two syntaxes for lists and you can use either of them.
|
||||
# Here we use the "flow syntax" - comma-separated strings inside square brackets.
|
||||
command: [
|
||||
python3,
|
||||
# Path of the program inside the container
|
||||
/pipelines/component/src/transcoding_csv_component.py,
|
||||
--csv-image-data-path,
|
||||
{inputPath: csv_image_data_path},
|
||||
--tfrecord-image-data-path,
|
||||
{outputPath: tfrecord_image_data_path},
|
||||
--class-names,
|
||||
{inputValue: class_names},
|
||||
]
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
name: Transcode imagedataset tfrecord from jsonlines
|
||||
description: |
|
||||
Transcodes JSONL Data into TFRecord file of TFExamples.
|
||||
Args:
|
||||
jsonl_image_data_path (str):
|
||||
Input path for the JSONL image data
|
||||
Path to the JSONL image data. Each line corresponds to a JSON input describing an image.
|
||||
Schema follows AutoML image classification JSONL format
|
||||
https://cloud.google.com/vertex-ai/docs/image-data/classification/prepare-data#json-lines.
|
||||
class_names (Sequence[str]):
|
||||
Sequence of strings of categories for classification corresponding to input data.
|
||||
tfrecord_image_data_path (str):
|
||||
Output path for the TFRecord image data. Data will be formatted as 'label' (encoded image
|
||||
label), and 'image_raw' (the binary string of the image data).
|
||||
inputs:
|
||||
- {name: jsonl_image_data_path, type: ImageDatasetJsonLines, description: Input path
|
||||
for the JSONL image data}
|
||||
- {name: class_names, type: 'typing.List[str]', description: List of class names corresponding
|
||||
to the input image data}
|
||||
outputs:
|
||||
- {name: tfrecord_image_data_path, type: ImageDatasetTFRecord, description: Output
|
||||
path for the TFRecord image data}
|
||||
implementation:
|
||||
container:
|
||||
image: us-docker.pkg.dev/vertex-ai/ready-to-go-image-classification/image-components:v0.1
|
||||
# command is a list of strings (command-line arguments).
|
||||
# The YAML language has two syntaxes for lists and you can use either of them.
|
||||
# Here we use the "flow syntax" - comma-separated strings inside square brackets.
|
||||
command: [
|
||||
python3,
|
||||
# Path of the program inside the container
|
||||
/pipelines/component/src/transcoding_jsonl_component.py,
|
||||
--jsonl-image-data-path,
|
||||
{inputPath: jsonl_image_data_path},
|
||||
--tfrecord-image-data-path,
|
||||
{outputPath: tfrecord_image_data_path},
|
||||
--class-names,
|
||||
{inputValue: class_names},
|
||||
]
|
||||
+1507
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -1,3 +1,3 @@
|
||||
torch==1.8.1
|
||||
torch==1.13.1
|
||||
torchvision==0.9.1
|
||||
tensorboard==2.5.0
|
||||
+1
-11
@@ -31,17 +31,7 @@
|
||||
"source": [
|
||||
"# Deploying a PyTorch Text Classification Model on [Vertex AI](https://cloud.google.com/vertex-ai)\n",
|
||||
"\n",
|
||||
"**This is an Experimental release**, covered by the Pre-GA Offerings Terms of your Google Cloud Platform [Terms of Service](https://cloud.google.com/terms).\n",
|
||||
"\n",
|
||||
"Experiments are focused on validating a prototype and are not guaranteed to be released. They are not intended for production use or covered by any SLA, support obligation, or deprecation policy and might be subject to backward-incompatible changes.\n",
|
||||
"\n",
|
||||
"**Kindly drop us a note before you run any scale tests.**\n",
|
||||
"\n",
|
||||
"**Do not hesitate to contact vertexai-prediction-preview-feedback@google.com if you have any questions or run into any issues.**\n",
|
||||
"\n",
|
||||
"The usage of the product is free during the Experimental release period: you will still incur charges for other GCP products usage, such as storage.\n",
|
||||
"\n",
|
||||
"The projects need to be added to the allowlist in order to deploy PyTorch models using Vertex AI Prediction pre-built PyTorch images. If you are interested in the feature, please send an email to vertexai-prediction-preview-feedback@google.com to provide your project numbers OR project ids."
|
||||
"**Kindly reach out to Vertex AI before you run any scale tests or you have any questions.**\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
/notebooks/community/neo4j/graph_paysim.ipynb @benofben @laeg
|
||||
/notebooks/community/ml_ops/stage1/get_started_with_visionapi_and_vertex_datasets.ipynb @mansari
|
||||
/notebooks/community/pipelines/google_cloud_pipeline_components_bqml_pipeline_demand_forecasting.ipynb @inardini
|
||||
/notebooks/community/cohere/cohere_embedding_with_matching_engine.ipynb @stewart-co
|
||||
/notebooks/community/ml_ops/stage2/get_started_vertex_hpt_r_kernel.ipynb @fhirschmann
|
||||
/notebooks/community/ml_ops/stage2/get_started_vertex_training_r_using_r_kernel.ipynb @fhirschmann
|
||||
/notebooks/community/vertex-ai-samples/notebooks/community/model_registry/vertex_ai_model_registry_bqml_custom_model_versioning.ipynb @inardini
|
||||
@@ -37,3 +38,6 @@
|
||||
/notebooks/community/vizier/conversions_vertex_vizier_and_open_source_vizier.ipynb @halio-g
|
||||
/notebooks/community/experiments/vertex_ai_model_experimentation.ipynb @inardini @asobran
|
||||
/notebooks/community/pipelines/google_cloud_pipeline_components_bqml_pipeline_anomaly_detection.ipynb @inardini
|
||||
/notebooks/community/pipelines/google_cloud_pipeline_components_cloud_natural_language_pipeline.ipynb @Narwhalprime
|
||||
/notebooks/community/pipelines/google_cloud_pipeline_components_ready_to_go_text_classification_pipeline.ipynb @Narwhalprime
|
||||
/notebooks/community/feature_store/get_started_vertex_feature_store.ipynb @junkourata
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
# README
|
||||
|
||||
These are notebooks [Cohere](https://cohere.ai/) built in collaboration with Google. They demonstrate how to use Cohere's modeling API along with Vertex AI.
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -8,7 +8,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Copyright 2021 Google LLC\n",
|
||||
"# Copyright 2023 Google LLC\n",
|
||||
"#\n",
|
||||
"# Licensed under the Apache License, Version 2.0 (the \"License\");\n",
|
||||
"# you may not use this file except in compliance with the License.\n",
|
||||
@@ -24,6 +24,7 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "JAPoU8Sm5E6e"
|
||||
@@ -32,20 +33,28 @@
|
||||
"<table align=\"left\">\n",
|
||||
"\n",
|
||||
" <td>\n",
|
||||
" <a href=\"https://console.cloud.google.com/vertex-ai/notebooks/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/matching_engine/matching_engine_for_indexing.ipynb\">\n",
|
||||
" Run in Google Cloud Notebooks\n",
|
||||
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/matching_engine/matching_engine_for_indexing.ipynb\">\n",
|
||||
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\">\n",
|
||||
" Run in Colab\n",
|
||||
" </a>\n",
|
||||
" </td>\n",
|
||||
" <td>\n",
|
||||
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/matching_engine/matching_engine_for_indexing.ipynb\">\n",
|
||||
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/matching_engine/matching_engine_for_indexing.ipynb\">\n",
|
||||
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" 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/matching_engine/matching_engine_for_indexing.ipynb\">\n",
|
||||
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
|
||||
" Open in Vertex AI Workbench\n",
|
||||
" </a>\n",
|
||||
" </td> \n",
|
||||
"</table>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "tvgnzT1CKxrO"
|
||||
@@ -53,25 +62,49 @@
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This example demonstrates how to use the GCP ANN Service. It is a high scale, low latency solution, to find similar vectors (or more specifically \"embeddings\") for a large corpus. Moreover, it is a fully managed offering, further reducing operational overhead. It is built upon [Approximate Nearest Neighbor (ANN) technology](https://ai.googleblog.com/2020/07/announcing-scann-efficient-vector.html) developed by Google Research.\n",
|
||||
"\n",
|
||||
"### Dataset\n",
|
||||
"\n",
|
||||
"The dataset used for this tutorial is the [GloVe dataset](https://nlp.stanford.edu/projects/glove/).\n",
|
||||
"\n",
|
||||
"This example demonstrates how to use Vertex AI Matching Engine. It is a high scale, low latency solution, to find similar vectors (or more specifically \"embeddings\") for a large corpus. Moreover, it is a fully managed offering, further reducing operational overhead. It is built upon [Approximate Nearest Neighbor (ANN) technology](https://ai.googleblog.com/2020/07/announcing-scann-efficient-vector.html) developed by Google Research."
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "56e5f9699c6c"
|
||||
},
|
||||
"source": [
|
||||
"### Objective\n",
|
||||
"\n",
|
||||
"In this notebook, you will learn how to create Approximate Nearest Neighbor (ANN) Index, query against indexes, and validate the performance of the index. \n",
|
||||
"\n",
|
||||
"The steps performed include:\n",
|
||||
"\n",
|
||||
"* Create ANN Index and Brute Force Index\n",
|
||||
"* Create a Vertex AI Matching Engine Index and Brute Force Index\n",
|
||||
"* Create an IndexEndpoint with VPC Network\n",
|
||||
"* Deploy ANN Index and Brute Force Index\n",
|
||||
"* Perform online query\n",
|
||||
"* Compute recall\n",
|
||||
"\n",
|
||||
"* Deploy a Vertex AI Matching Engine Index and Brute Force Index\n",
|
||||
"* Perform online queries\n",
|
||||
"* Submit batch queries\n",
|
||||
"* Compute recall metric"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "0aaef374550b"
|
||||
},
|
||||
"source": [
|
||||
"### Dataset\n",
|
||||
"\n",
|
||||
"The dataset used for this tutorial is the [GloVe dataset](https://nlp.stanford.edu/projects/glove/)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "5e2eba58ad71"
|
||||
},
|
||||
"source": [
|
||||
"### Costs \n",
|
||||
"\n",
|
||||
"This tutorial uses billable components of Google Cloud:\n",
|
||||
@@ -87,6 +120,7 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "S5zc4kbEiYCm"
|
||||
@@ -94,79 +128,47 @@
|
||||
"source": [
|
||||
"## Before you begin\n",
|
||||
"\n",
|
||||
"* **Prepare a VPC network**. To reduce any network overhead that might lead to unnecessary increase in overhead latency, it is best to call the ANN endpoints from your VPC via a direct [VPC Peering](https://cloud.google.com/vertex-ai/docs/general/vpc-peering) connection. The following section describes how to setup a VPC Peering connection if you don't have one. This is a one-time initial setup task. You can also reuse existing VPC network and skip this section.\n",
|
||||
"* **WARNING:** The match service gRPC API (to create online queries against your deployed index) has to be executed in a Google Cloud Notebook instance that is created with the following requirements:\n",
|
||||
" * **In the same region as where your ANN service is deployed** (for example, if you set `REGION = \"us-central1\"` as same as the tutorial, the notebook instance has to be in `us-central1`).\n",
|
||||
" * **Make sure you select the VPC network you created for ANN service** (instead of using the \"default\" one). That is, you will have to create the VPC network below and then create a new notebook instance that uses that VPC. \n",
|
||||
" * If you run it in the colab or a Google Cloud Notebook instance in a different VPC network or region, the gRPC API will fail to peer the network (InactiveRPCError)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "lW2LneA5mmmP"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"PROJECT_ID = \"<your_project_id>\" # @param {type:\"string\"}\n",
|
||||
"NETWORK_NAME = \"ucaip-haystack-vpc-network\" # @param {type:\"string\"}\n",
|
||||
"PEERING_RANGE_NAME = \"ucaip-haystack-range\"\n",
|
||||
"### Set up your Google Cloud project\n",
|
||||
"\n",
|
||||
"# Create a VPC network\n",
|
||||
"! gcloud compute networks create {NETWORK_NAME} --bgp-routing-mode=regional --subnet-mode=auto --project={PROJECT_ID}\n",
|
||||
"**The following steps are required, regardless of your notebook environment.**\n",
|
||||
"\n",
|
||||
"# Add necessary firewall rules\n",
|
||||
"! gcloud compute firewall-rules create {NETWORK_NAME}-allow-icmp --network {NETWORK_NAME} --priority 65534 --project {PROJECT_ID} --allow icmp\n",
|
||||
"1. [Select or create a Google Cloud project](https://console.cloud.google.com/cloud-resource-manager). When you first create an account, you get a $300 free credit towards your compute/storage costs.\n",
|
||||
"\n",
|
||||
"! gcloud compute firewall-rules create {NETWORK_NAME}-allow-internal --network {NETWORK_NAME} --priority 65534 --project {PROJECT_ID} --allow all --source-ranges 10.128.0.0/9\n",
|
||||
"2. [Make sure that billing is enabled for your project](https://cloud.google.com/billing/docs/how-to/modify-project).\n",
|
||||
"\n",
|
||||
"! gcloud compute firewall-rules create {NETWORK_NAME}-allow-rdp --network {NETWORK_NAME} --priority 65534 --project {PROJECT_ID} --allow tcp:3389\n",
|
||||
"3. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com).\n",
|
||||
"\n",
|
||||
"! gcloud compute firewall-rules create {NETWORK_NAME}-allow-ssh --network {NETWORK_NAME} --priority 65534 --project {PROJECT_ID} --allow tcp:22\n",
|
||||
"\n",
|
||||
"# Reserve IP range\n",
|
||||
"! gcloud compute addresses create {PEERING_RANGE_NAME} --global --prefix-length=16 --network={NETWORK_NAME} --purpose=VPC_PEERING --project={PROJECT_ID} --description=\"peering range for uCAIP Haystack.\"\n",
|
||||
"\n",
|
||||
"# Set up peering with service networking\n",
|
||||
"! gcloud services vpc-peerings connect --service=servicenetworking.googleapis.com --network={NETWORK_NAME} --ranges={PEERING_RANGE_NAME} --project={PROJECT_ID}"
|
||||
"4. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "d3uj8x73nDX_"
|
||||
},
|
||||
"source": [
|
||||
"* Authentication: `$ gcloud auth login` rerun this in Google Cloud Notebook terminal when you are logged out and need the credential again."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "i7EUnXsZhAGF"
|
||||
"id": "4700b0e39c5d"
|
||||
},
|
||||
"source": [
|
||||
"### Installation\n",
|
||||
"\n",
|
||||
"Download and install the latest (preview) version of the Vertex SDK for Python."
|
||||
"Download and install the latest version of the Vertex AI SDK for Python."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "wyy5Lbnzg5fi"
|
||||
"id": "014470c6a8de"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"! pip install -U git+https://github.com/googleapis/python-aiplatform.git@main-test --user"
|
||||
"! pip install -U git+https://github.com/googleapis/python-aiplatform.git@main --user"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "irSMQn6gZ19l"
|
||||
"id": "cf00462144f7"
|
||||
},
|
||||
"source": [
|
||||
"Install the `h5py` to prepare sample dataset, and the `grpcio-tools` for querying against the index. "
|
||||
@@ -176,11 +178,15 @@
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "-h5sqwOEZ5Yq"
|
||||
"id": "3f3e45e5a1d1"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"! pip install -U grpcio-tools --user\n",
|
||||
"! pip install protobuf==3.20.*\n",
|
||||
"! pip install -U google-api-python-client==1.8.0 --user\n",
|
||||
"! pip install -U grpcio-tools==1.47.0 --user\n",
|
||||
"! pip install -U grpcio==1.47.0 --user\n",
|
||||
"! pip install -U grpcio-status==1.47.0 --user\n",
|
||||
"! pip install -U h5py --user"
|
||||
]
|
||||
},
|
||||
@@ -199,7 +205,7 @@
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "EzrelQZ22IZj"
|
||||
"id": "aa1d87bdc90b"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -215,79 +221,216 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "BF1j6f9HApxa"
|
||||
"id": "249da91c1011"
|
||||
},
|
||||
"source": [
|
||||
"### Set up your Google Cloud project\n",
|
||||
"### Set your project ID\n",
|
||||
"\n",
|
||||
"**The following steps are required, regardless of your notebook environment.**\n",
|
||||
"\n",
|
||||
"1. [Select or create a Google Cloud project](https://console.cloud.google.com/cloud-resource-manager).\n",
|
||||
"\n",
|
||||
"1. [Make sure that billing is enabled for your project](https://cloud.google.com/billing/docs/how-to/modify-project).\n",
|
||||
"\n",
|
||||
"1. [Enable the Vertex AI API and Compute Engine API, and Service Networking API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com,compute_component,servicenetworking.googleapis.com).\n",
|
||||
"\n",
|
||||
"1. Enter your project ID in the cell below. Then run the cell to make sure the\n",
|
||||
"Cloud SDK uses the right project for all the commands in this notebook.\n",
|
||||
"\n",
|
||||
"**Note**: Jupyter runs lines prefixed with `!` as shell commands, and it interpolates Python variables prefixed with `$` into these commands."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "WReHDGG5g0XY"
|
||||
},
|
||||
"source": [
|
||||
"#### Set your project ID\n",
|
||||
"\n",
|
||||
"**If you don't know your project ID**, you may be able to get your project ID using `gcloud`."
|
||||
"**If you don't know your project ID**, try the following:\n",
|
||||
"* Run `gcloud config list`.\n",
|
||||
"* Run `gcloud projects list`.\n",
|
||||
"* See the support page: [Locate the project ID](https://support.google.com/googleapi/answer/7014113)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "oM1iC_MfAts1"
|
||||
"id": "10e0d2ee8c45"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}\n",
|
||||
"\n",
|
||||
"PROJECT_ID = \"\"\n",
|
||||
"\n",
|
||||
"# Get your Google Cloud project ID from gcloud\n",
|
||||
"if not os.getenv(\"IS_TESTING\"):\n",
|
||||
" shell_output=!gcloud config list --format 'value(core.project)' 2>/dev/null\n",
|
||||
" PROJECT_ID = shell_output[0]\n",
|
||||
" print(\"Project ID: \", PROJECT_ID)"
|
||||
"# Set the project id\n",
|
||||
"! gcloud config set project {PROJECT_ID}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "qJYoRfYng0XZ"
|
||||
"id": "3fbfae3ff12a"
|
||||
},
|
||||
"source": [
|
||||
"Otherwise, set your project ID here."
|
||||
"### Set the region\n",
|
||||
"\n",
|
||||
"You can also change the `REGION` variable used by Vertex AI. Learn more about [Vertex AI regions](https://cloud.google.com/vertex-ai/docs/general/locations).\n",
|
||||
"* **WARNING:** \n",
|
||||
" * **Make sure to [choose a region where Vertex AI services are available](https://cloud.google.com/vertex-ai/docs/general/locations#available_regions).**\n",
|
||||
" * **If you use Vertex Workbench, the Notebook instance needs to be in the same region where your Vertex AI Matching Engine is deployed.** (for example, if you set `REGION = \"us-central1\"` as same as the tutorial, the notebook instance has to be in `us-central1`)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "riG_qUokg0XZ"
|
||||
"id": "71c3fd82024e"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"if PROJECT_ID == \"\" or PROJECT_ID is None:\n",
|
||||
" PROJECT_ID = \"<your_project_id>\" # @param {type:\"string\"}"
|
||||
"REGION = \"us-central1\" # @param {type: \"string\"}\n",
|
||||
"\n",
|
||||
"# Set the regions\n",
|
||||
"! gcloud config set ai_platform/region {REGION}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "60c5a0f69ad8"
|
||||
},
|
||||
"source": [
|
||||
"### Authenticate your Google Cloud account\n",
|
||||
"\n",
|
||||
"Depending on your Jupyter environment, you may have to manually authenticate. Follow the relevant instructions below."
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "d118c95af93f"
|
||||
},
|
||||
"source": [
|
||||
"**1. Vertex AI Workbench**\n",
|
||||
"* Do nothing as you are already authenticated."
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "3035286fcdda"
|
||||
},
|
||||
"source": [
|
||||
"**2. Local JupyterLab instance, uncomment and run:**"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "455882ec0f11"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# ! gcloud auth login"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "5097f3233d53"
|
||||
},
|
||||
"source": [
|
||||
"**3. Colab, uncomment and run:**"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "2b88e46ac2c8"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# from google.colab import auth\n",
|
||||
"# auth.authenticate_user()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "fcdbb8929927"
|
||||
},
|
||||
"source": [
|
||||
"**4. Service account or other**\n",
|
||||
"* See how to grant Cloud Storage permissions to your service account at https://cloud.google.com/storage/docs/gsutil/commands/iam#ch-examples."
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "7c6eef70dfdb"
|
||||
},
|
||||
"source": [
|
||||
"### Prepare a VPC network\n",
|
||||
"\n",
|
||||
"To reduce any network overhead that might lead to unnecessary increase in overhead latency, it is best to call the Vertex AI Matching Engine endpoints from your VPC via a direct [VPC Peering](https://cloud.google.com/vertex-ai/docs/general/vpc-peering) connection. The following section describes how to setup a VPC Peering connection if you don't have one. This is a one-time initial setup task. You can also reuse existing VPC network and skip this section.\n",
|
||||
"\n",
|
||||
"* **WARNING:** The match service gRPC API (to create online queries against your deployed index) has to be executed in a Google Cloud Notebook instance that is created with the following requirements:\n",
|
||||
" * **Make sure you select the VPC network you created for Vertex AI Matching Engine service** (instead of using the \"default\" one). That is, you will have to create the VPC network below and then create a new notebook instance that uses that VPC. \n",
|
||||
" * If you run it in the colab or a Google Cloud Notebook instance in a different VPC network or region, the gRPC API will fail to peer the network (InactiveRPCError)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "ab38a8cc634c"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"NETWORK_NAME = \"ucaip-haystack-vpc-network\" # @param {type:\"string\"}\n",
|
||||
"PEERING_RANGE_NAME = \"ucaip-haystack-range\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "ec6bf3199835"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Create a VPC network\n",
|
||||
"! gcloud compute networks create {NETWORK_NAME} --bgp-routing-mode=regional --subnet-mode=auto --project={PROJECT_ID}\n",
|
||||
"\n",
|
||||
"# Add necessary firewall rules\n",
|
||||
"! gcloud compute firewall-rules create {NETWORK_NAME}-allow-icmp --network {NETWORK_NAME} --priority 65534 --project {PROJECT_ID} --allow icmp\n",
|
||||
"\n",
|
||||
"! gcloud compute firewall-rules create {NETWORK_NAME}-allow-internal --network {NETWORK_NAME} --priority 65534 --project {PROJECT_ID} --allow all --source-ranges 10.128.0.0/9\n",
|
||||
"\n",
|
||||
"! gcloud compute firewall-rules create {NETWORK_NAME}-allow-rdp --network {NETWORK_NAME} --priority 65534 --project {PROJECT_ID} --allow tcp:3389\n",
|
||||
"\n",
|
||||
"! gcloud compute firewall-rules create {NETWORK_NAME}-allow-ssh --network {NETWORK_NAME} --priority 65534 --project {PROJECT_ID} --allow tcp:22\n",
|
||||
"\n",
|
||||
"# Reserve IP range\n",
|
||||
"! gcloud compute addresses create {PEERING_RANGE_NAME} --global --prefix-length=16 --network={NETWORK_NAME} --purpose=VPC_PEERING --project={PROJECT_ID} --description=\"peering range for uCAIP Haystack.\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "ddbace09fe81"
|
||||
},
|
||||
"source": [
|
||||
"Create the VPC Peering. If you are running this from Vertex AI Workbench it is possible you might need your notebook's instance service or user account to have the Service Networking Admin Role"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "d329aa3c54d3"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Set up peering with service networking\n",
|
||||
"! gcloud services vpc-peerings connect --service=servicenetworking.googleapis.com --network={NETWORK_NAME} --ranges={PEERING_RANGE_NAME} --project={PROJECT_ID}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "zgPO1eR3CYjk"
|
||||
@@ -297,13 +440,11 @@
|
||||
"\n",
|
||||
"**The following steps are required, regardless of your notebook environment.**\n",
|
||||
"\n",
|
||||
"Set the name of your Cloud Storage bucket below. It must be unique across all\n",
|
||||
"Create a storage bucket to store intermediate artifacts such as datasets. Set the name of your Cloud Storage bucket below. It must be unique across all\n",
|
||||
"Cloud Storage buckets.\n",
|
||||
"\n",
|
||||
"You may also change the `REGION` variable, which is used for operations\n",
|
||||
"throughout the rest of this notebook. Make sure to [choose a region where Vertex AI services are\n",
|
||||
"available](https://cloud.google.com/vertex-ai/docs/general/locations#available_regions). You may\n",
|
||||
"not use a Multi-Regional Storage bucket for training with Vertex AI."
|
||||
"* **WARNING:** \n",
|
||||
" * **You may not use a Multi-Regional Storage bucket for training with Vertex AI.**"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -314,8 +455,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"BUCKET_NAME = \"gs://[your-bucket-name]\" # @param {type:\"string\"}\n",
|
||||
"REGION = \"us-central1\" # @param {type:\"string\"}"
|
||||
"BUCKET_NAME = \"gs://[your-bucket-name-unique]\" # @param {type:\"string\"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -328,10 +468,14 @@
|
||||
"source": [
|
||||
"from datetime import datetime\n",
|
||||
"\n",
|
||||
"TIMESTAMP = datetime.now().strftime(\"%Y%m%d%H%M%S\")\n",
|
||||
"UUID = datetime.now().strftime(\"%Y%m%d%H%M%S\")\n",
|
||||
"\n",
|
||||
"if BUCKET_NAME == \"\" or BUCKET_NAME is None or BUCKET_NAME == \"gs://[your-bucket-name]\":\n",
|
||||
" BUCKET_NAME = \"gs://\" + PROJECT_ID + \"aip-\" + TIMESTAMP"
|
||||
"if (\n",
|
||||
" BUCKET_NAME == \"\"\n",
|
||||
" or BUCKET_NAME is None\n",
|
||||
" or BUCKET_NAME == \"gs://[your-bucket-name-unique]\"\n",
|
||||
"):\n",
|
||||
" BUCKET_NAME = \"gs://\" + PROJECT_ID + \"aip-\" + UUID"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -351,7 +495,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"! gsutil mb -l $REGION $BUCKET_NAME"
|
||||
"! gsutil mb -l $REGION -p $PROJECT_ID $BUCKET_NAME"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -416,10 +560,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"REGION = \"us-central1\"\n",
|
||||
"ENDPOINT = \"{}-aiplatform.googleapis.com\".format(REGION)\n",
|
||||
"NETWORK_NAME = \"ucaip-haystack-vpc-network\" # @param {type:\"string\"}\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"AUTH_TOKEN = !gcloud auth print-access-token\n",
|
||||
"PROJECT_NUMBER = !gcloud projects list --filter=\"PROJECT_ID:'{PROJECT_ID}'\" --format='value(PROJECT_NUMBER)'\n",
|
||||
@@ -429,10 +570,7 @@
|
||||
"\n",
|
||||
"print(\"ENDPOINT: {}\".format(ENDPOINT))\n",
|
||||
"print(\"PROJECT_ID: {}\".format(PROJECT_ID))\n",
|
||||
"print(\"REGION: {}\".format(REGION))\n",
|
||||
"\n",
|
||||
"!gcloud config set project {PROJECT_ID}\n",
|
||||
"!gcloud config set ai_platform/region {REGION}"
|
||||
"print(\"REGION: {}\".format(REGION))"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -523,12 +661,13 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "QuVl8DrWG8NS"
|
||||
},
|
||||
"source": [
|
||||
"Upload the training data to GCS."
|
||||
"Upload the training data to Google Cloud Storage"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -539,9 +678,9 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# NOTE: Everything in this GCS DIR will be DELETED before uploading the data.\n",
|
||||
"# NOTE: Everything in this Google Cloud Storage directory will be DELETED before uploading the data\n",
|
||||
"\n",
|
||||
"! gsutil rm -rf {BUCKET_NAME}/*"
|
||||
"! gsutil rm -raf {BUCKET_NAME}/** 2> /dev/null || true"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -567,21 +706,23 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "mglUPwHpJH98"
|
||||
},
|
||||
"source": [
|
||||
"## Create Indexes\n"
|
||||
"## Create the indexes\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "qhIBCQ7dDSbW"
|
||||
},
|
||||
"source": [
|
||||
"### Create ANN Index (for Production Usage)"
|
||||
"### Create Vertex AI Matching Engine index (for production usage)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -597,6 +738,16 @@
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "14e1ed031d66"
|
||||
},
|
||||
"source": [
|
||||
"Set constants"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -611,14 +762,15 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "svLYiDf0OD2G"
|
||||
},
|
||||
"source": [
|
||||
"Create the ANN index configuration:\n",
|
||||
"#### Create the Vertex AI Matching Engine index configuration\n",
|
||||
"\n",
|
||||
"Please read the documentation to understand the various configuration parameters that can be used to tune the index\n"
|
||||
"Please read the [documentation](https://cloud.google.com/vertex-ai/docs/matching-engine/configuring-indexes) to understand the various configuration parameters that can be used to tune the index"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -656,9 +808,9 @@
|
||||
" }\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"ann_index = {\n",
|
||||
"matching_engine_index = {\n",
|
||||
" \"display_name\": DISPLAY_NAME,\n",
|
||||
" \"description\": \"Glove 100 ANN index\",\n",
|
||||
" \"description\": \"Glove 100 Vertex AI Matching Engine Index\",\n",
|
||||
" \"metadata\": struct_pb2.Value(struct_value=metadata),\n",
|
||||
"}"
|
||||
]
|
||||
@@ -671,7 +823,9 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"ann_index = index_client.create_index(parent=PARENT, index=ann_index)"
|
||||
"matching_engine_index = index_client.create_index(\n",
|
||||
" parent=PARENT, index=matching_engine_index\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -686,7 +840,7 @@
|
||||
"# This will take ~45 min.\n",
|
||||
"\n",
|
||||
"while True:\n",
|
||||
" if ann_index.done():\n",
|
||||
" if matching_engine_index.done():\n",
|
||||
" break\n",
|
||||
" print(\"Poll the operation to create index...\")\n",
|
||||
" time.sleep(60)"
|
||||
@@ -700,17 +854,18 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"INDEX_RESOURCE_NAME = ann_index.result().name\n",
|
||||
"INDEX_RESOURCE_NAME = matching_engine_index.result().name\n",
|
||||
"INDEX_RESOURCE_NAME"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "kSsqZuyoA1SG"
|
||||
},
|
||||
"source": [
|
||||
"### Create Brute Force Index (for Ground Truth)\n",
|
||||
"### Create brute force index (for ground truth)\n",
|
||||
"\n",
|
||||
"The brute force index uses a naive brute force method to find the nearest neighbors. This method is not fast or efficient. Hence brute force indices are not recommended for production usage. They are to be used to find the \"ground truth\" set of neighbors, so that the \"ground truth\" set can be used to measure recall of the indices being tuned for production usage. To ensure an apples to apples comparison, the `distanceMeasureType` and `featureNormType`, `dimensions` of the brute force index should match those of the production indices being tuned.\n",
|
||||
"\n",
|
||||
@@ -725,8 +880,6 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from google.protobuf import *\n",
|
||||
"\n",
|
||||
"algorithmConfig = struct_pb2.Struct(\n",
|
||||
" fields={\"bruteForceConfig\": struct_pb2.Value(struct_value=struct_pb2.Struct())}\n",
|
||||
")\n",
|
||||
@@ -796,12 +949,13 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "mglUPwHpJH98"
|
||||
},
|
||||
"source": [
|
||||
"## Update Indexes\n",
|
||||
"## Update the indexes\n",
|
||||
"\n",
|
||||
"Create incremental data file.\n"
|
||||
]
|
||||
@@ -863,10 +1017,10 @@
|
||||
" }\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"ann_index = {\n",
|
||||
"matching_engine_index = {\n",
|
||||
" \"name\": INDEX_RESOURCE_NAME,\n",
|
||||
" \"display_name\": DISPLAY_NAME,\n",
|
||||
" \"description\": \"Glove 100 ANN index\",\n",
|
||||
" \"description\": \"Glove 100 Vertex AI Matching Engine Index\",\n",
|
||||
" \"metadata\": struct_pb2.Value(struct_value=metadata),\n",
|
||||
"}"
|
||||
]
|
||||
@@ -879,7 +1033,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"ann_index = index_client.update_index(index=ann_index)"
|
||||
"matching_engine_index = index_client.update_index(index=matching_engine_index)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -894,7 +1048,7 @@
|
||||
"# This will take ~45 min.\n",
|
||||
"\n",
|
||||
"while True:\n",
|
||||
" if ann_index.done():\n",
|
||||
" if matching_engine_index.done():\n",
|
||||
" break\n",
|
||||
" print(\"Poll the operation to update index...\")\n",
|
||||
" time.sleep(60)"
|
||||
@@ -908,17 +1062,18 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"INDEX_RESOURCE_NAME = ann_index.result().name\n",
|
||||
"INDEX_RESOURCE_NAME = matching_engine_index.result().name\n",
|
||||
"INDEX_RESOURCE_NAME"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "qV2xjAnDDObD"
|
||||
},
|
||||
"source": [
|
||||
"## Create an IndexEndpoint with VPC Network"
|
||||
"## Create an index endpoint with VPC network"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -997,21 +1152,23 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "np2cgVuuIe9k"
|
||||
},
|
||||
"source": [
|
||||
"## Deploy Indexes"
|
||||
"## Deploy the indexes"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "8Ew1UgcIIiJG"
|
||||
},
|
||||
"source": [
|
||||
"### Deploy ANN Index"
|
||||
"### Deploy a Vertex AI Matching Engine index"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1022,7 +1179,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"DEPLOYED_INDEX_ID = \"ann_glove_deployed\""
|
||||
"DEPLOYED_INDEX_ID = \"matching_engine_glove_deployed\""
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1033,13 +1190,23 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"deploy_ann_index = {\n",
|
||||
"deploy_matching_engine_index = {\n",
|
||||
" \"id\": DEPLOYED_INDEX_ID,\n",
|
||||
" \"display_name\": DEPLOYED_INDEX_ID,\n",
|
||||
" \"index\": INDEX_RESOURCE_NAME,\n",
|
||||
"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "cb6d956d7419"
|
||||
},
|
||||
"source": [
|
||||
"If errors occur with the next command wait some minutes for the index endpoint to be created and retry."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -1049,7 +1216,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"r = index_endpoint_client.deploy_index(\n",
|
||||
" index_endpoint=INDEX_ENDPOINT_NAME, deployed_index=deploy_ann_index\n",
|
||||
" index_endpoint=INDEX_ENDPOINT_NAME, deployed_index=deploy_matching_engine_index\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
@@ -1082,12 +1249,13 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "RNZnXmO5AhDO"
|
||||
},
|
||||
"source": [
|
||||
"### Deploy Brute Force Index"
|
||||
"### Deploy brute force index"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1158,12 +1326,13 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "6LCGvBNvBd8D"
|
||||
},
|
||||
"source": [
|
||||
"## Create Online Queries\n",
|
||||
"## Create online queries\n",
|
||||
"\n",
|
||||
"After you built your indexes, you may query against the deployed index through the online querying gRPC API (Match service) within the virtual machine instances from the same region (for example 'us-central1' in this tutorial). \n",
|
||||
"\n",
|
||||
@@ -1178,7 +1347,15 @@
|
||||
"\n",
|
||||
"* Compile the protocal buffer (see below)\n",
|
||||
"* Obtain the index endpoint\n",
|
||||
"* Use a code-generated stub to make the call, passing the parameter values"
|
||||
"* Use a code-generated stub to make the call, passing the parameter values\n",
|
||||
"\n",
|
||||
"### Troubleshooting connectivity issues\n",
|
||||
"\n",
|
||||
"In case you have connectivity errors please perform the following:\n",
|
||||
"\n",
|
||||
"* Verify that the index endpoint, index, and VPC are all in the same Google Cloud project\n",
|
||||
"* Verify that the index endpoint, index, and VPC are all in the same region and it is a valid (e.g. us-central1)\n",
|
||||
"* Verify the Network does not have a firewall rule which denies all egress connections. Else, disable this rule or overwrite it with another rule that allows connection to the index endpoint IP"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1351,12 +1528,13 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "8wXTSgz1Bl0x"
|
||||
},
|
||||
"source": [
|
||||
"Obtain the Private Endpoint: "
|
||||
"Obtain the private endpoint: "
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1521,12 +1699,13 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "_mNwdU9_B_Ez"
|
||||
},
|
||||
"source": [
|
||||
"### Batch Query\n",
|
||||
"## Submit a batch query\n",
|
||||
"\n",
|
||||
"You can run multiple queries in a single RPC call using the BatchMatch API:"
|
||||
]
|
||||
@@ -1764,18 +1943,20 @@
|
||||
"]\n",
|
||||
"\n",
|
||||
"batch_request = match_service_pb2.BatchMatchRequest()\n",
|
||||
"batch_request_ann = match_service_pb2.BatchMatchRequest.BatchMatchRequestPerIndex()\n",
|
||||
"batch_request_matching_engine = (\n",
|
||||
" match_service_pb2.BatchMatchRequest.BatchMatchRequestPerIndex()\n",
|
||||
")\n",
|
||||
"batch_request_brute_force = (\n",
|
||||
" match_service_pb2.BatchMatchRequest.BatchMatchRequestPerIndex()\n",
|
||||
")\n",
|
||||
"batch_request_ann.deployed_index_id = DEPLOYED_INDEX_ID\n",
|
||||
"batch_request_matching_engine.deployed_index_id = DEPLOYED_INDEX_ID\n",
|
||||
"batch_request_brute_force.deployed_index_id = DEPLOYED_BRUTE_FORCE_INDEX_ID\n",
|
||||
"for query in queries:\n",
|
||||
" batch_request_ann.requests.append(get_request(query, DEPLOYED_INDEX_ID))\n",
|
||||
" batch_request_matching_engine.requests.append(get_request(query, DEPLOYED_INDEX_ID))\n",
|
||||
" batch_request_brute_force.requests.append(\n",
|
||||
" get_request(query, DEPLOYED_BRUTE_FORCE_INDEX_ID)\n",
|
||||
" )\n",
|
||||
"batch_request.requests.append(batch_request_ann)\n",
|
||||
"batch_request.requests.append(batch_request_matching_engine)\n",
|
||||
"batch_request.requests.append(batch_request_brute_force)\n",
|
||||
"\n",
|
||||
"response = stub.BatchMatch(batch_request)\n",
|
||||
@@ -1783,14 +1964,15 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "_mNwdU9_B_Ez"
|
||||
},
|
||||
"source": [
|
||||
"### Compute Recall\n",
|
||||
"### Compute the recall metric\n",
|
||||
"\n",
|
||||
"Use deployed brute force Index as the ground truth to calculate the recall of ANN Index:"
|
||||
"Use the deployed brute force index as the ground truth to calculate the recall of the Vertex AI Matching Engine index:"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1835,6 +2017,7 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "TpV-iwP9qw9c"
|
||||
@@ -1844,7 +2027,18 @@
|
||||
"\n",
|
||||
"To clean up all Google Cloud resources used in this project, you can [delete the Google Cloud\n",
|
||||
"project](https://cloud.google.com/resource-manager/docs/creating-managing-projects#shutting_down_projects) you used for the tutorial.\n",
|
||||
"You can also manually delete resources that you created by running the following code."
|
||||
"\n",
|
||||
"Otherwise, you can delete the individual resources you created in this tutorial:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "390c331dc7d9"
|
||||
},
|
||||
"source": [
|
||||
"### Delete the Vertex AI Matching Engine resources"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1869,6 +2063,31 @@
|
||||
"source": [
|
||||
"index_endpoint_client.delete_index_endpoint(name=INDEX_ENDPOINT_NAME)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "ff14a85c85fb"
|
||||
},
|
||||
"source": [
|
||||
"### Delete the Google Cloud Storage bucket"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "68d4781faac4"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"\n",
|
||||
"delete_bucket = False\n",
|
||||
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
|
||||
" ! gsutil -m rm -r $BUCKET_NAME"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
||||
@@ -1333,7 +1333,6 @@
|
||||
"Next, you compile the pipeline and then exeute it. The pipeline takes the following parameters, which are passed as the dictionary `parameter_values`:\n",
|
||||
"\n",
|
||||
"- `display_name`: A human readable name for the pipeline job.\n",
|
||||
"- `import_file`: The Cloud Storage location to the dataset.\n",
|
||||
"- `worker_pool_specs`: The the machine and container, and auto-scaling requirements, as well as command line arguments.\n",
|
||||
"- `study_spec_metrics`: The metrics to optimize in the study trials.\n",
|
||||
"- `study_spec_parameters`: The parameters to tune."
|
||||
|
||||
@@ -1028,6 +1028,9 @@
|
||||
"deployment_resource_pool.dedicated_resources.min_replica_count = MIN_NODES\n",
|
||||
"deployment_resource_pool.dedicated_resources.max_replica_count = MAX_NODES\n",
|
||||
"deployment_resource_pool.dedicated_resources.machine_spec.machine_type = DEPLOY_COMPUTE\n",
|
||||
"if DEPLOY_NGPU:\n",
|
||||
" deployment_resource_pool.dedicated_resources.machine_spec.accelerator_type = DEPLOY_GPU\n",
|
||||
" deployment_resource_pool.dedicated_resources.machine_spec.accelerator_count = DEPLOY_NGPU\n",
|
||||
"\n",
|
||||
"request = aip_beta.CreateDeploymentResourcePoolRequest(\n",
|
||||
" parent=f\"projects/{PROJECT_ID}/locations/{REGION}\",\n",
|
||||
|
||||
+1
-1
@@ -198,7 +198,7 @@
|
||||
"if IS_WORKBENCH_NOTEBOOK:\n",
|
||||
" USER_FLAG = \"--user\"\n",
|
||||
"\n",
|
||||
"! pip3 install --upgrade tensorflow google-cloud-bigquery google-cloud-aiplatform {USER_FLAG} -q --no-warn-conflicts"
|
||||
"! pip3 install --upgrade tensorflow google-cloud-bigquery google-cloud-aiplatform \"shapely<2\" {USER_FLAG} -q --no-warn-conflicts"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
+6
-10
@@ -72,7 +72,7 @@
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"Anomaly detection is the identification of rare obesrvations which deviate significantly from the data using ML. Anomaly detection can be done in many ways. Supervised, unsupervised, graph-based. It is particularly important for certain industries like telecommunications, manufacturing, and financial services.\n",
|
||||
"Anomaly detection is the identification of rare observations which deviate significantly from the data using ML. Anomaly detection can be done in many ways. Supervised, unsupervised, graph-based. It is particularly important for certain industries like telecommunications, manufacturing, and financial services.\n",
|
||||
"\n",
|
||||
"For instance, in a manufacturing scenario, you may collect some sensor data to predict the number remaining cycles before engine failure (TTF). In this way, you can take actionable decisions about maintenance planning."
|
||||
]
|
||||
@@ -397,13 +397,12 @@
|
||||
"source": [
|
||||
"import os\n",
|
||||
"\n",
|
||||
"SRC_PATH = \"src\"\n",
|
||||
"KFP_COMPONENTS_PATH = \"components\"\n",
|
||||
"PIPELINES_PATH = \"pipelines\"\n",
|
||||
"TRAIN_PIPELINES_PATH = os.path.join(PIPELINES_PATH, \"train_pipelines\")\n",
|
||||
"TEST_PIPELINES_PATH = os.path.join(PIPELINES_PATH, \"test_pipelines\")\n",
|
||||
"\n",
|
||||
"! mkdir -m 777 -p {SRC_PATH} {KFP_COMPONENTS_PATH} {TRAIN_PIPELINES_PATH} {TEST_PIPELINES_PATH}"
|
||||
"! mkdir -m 777 -p {KFP_COMPONENTS_PATH} {TRAIN_PIPELINES_PATH} {TEST_PIPELINES_PATH}"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -425,14 +424,12 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from urllib.parse import urlparse\n",
|
||||
"\n",
|
||||
"PUBLIC_DATA_URI = (\n",
|
||||
" \" gs://cloud-samples-data/vertex-ai/pipeline-deployment/datasets/turbofan_anomaly\"\n",
|
||||
" \"gs://cloud-samples-data/vertex-ai/pipeline-deployment/datasets/turbofan_anomaly\"\n",
|
||||
")\n",
|
||||
"GCS_TRAIN_URI = urlparse(PUBLIC_DATA_URI)._replace(path=\"train_FD001.csv\").geturl()\n",
|
||||
"GCS_TEST_URI = urlparse(PUBLIC_DATA_URI)._replace(path=\"test_FD001.csv\").geturl()\n",
|
||||
"GCS_LABELS_URI = urlparse(PUBLIC_DATA_URI)._replace(path=\"RUL_FD001.csv\").geturl()"
|
||||
"GCS_TRAIN_URI = f\"{PUBLIC_DATA_URI}/train_FD001.csv\"\n",
|
||||
"GCS_TEST_URI = f\"{PUBLIC_DATA_URI}/test_FD001.csv\"\n",
|
||||
"GCS_LABELS_URI = f\"{PUBLIC_DATA_URI}/RUL_FD001.csv\""
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1478,7 +1475,6 @@
|
||||
"# Remove local resorces\n",
|
||||
"delete_local_resources = False\n",
|
||||
"if delete_local_resources:\n",
|
||||
" ! rm -rf {SRC_PATH}\n",
|
||||
" ! rm -rf {KFP_COMPONENTS_PATH}\n",
|
||||
" ! rm -rf {TRAIN_PIPELINES_PATH}\n",
|
||||
" ! rm -rf {TEST_PIPELINES_PATH}"
|
||||
|
||||
+95
-41
@@ -54,18 +54,20 @@
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "tvgnzT1CKxrO"
|
||||
"id": "239ba71252d3"
|
||||
},
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This notebook shows how to use `Vertex AI Pipelines` and `BigQuery ML pipeline components` to train and evaluate a demand forecasting model.\n",
|
||||
"\n",
|
||||
"### Dataset\n",
|
||||
"\n",
|
||||
"The dataset is a modified version of the dataset in [Build and visualize demand forecast predictions using Datastream, Dataflow, BigQuery ML, and Looker\n",
|
||||
"](https://cloud.google.com/architecture/build-visualize-demand-forecast-prediction-datastream-dataflow-bigqueryml-looker) solution architecture\n",
|
||||
"\n",
|
||||
"This notebook shows how to use `Vertex AI Pipelines` and `BigQuery ML pipeline components` to train and evaluate a demand forecasting model."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "25c28706c23e"
|
||||
},
|
||||
"source": [
|
||||
"### Objective\n",
|
||||
"\n",
|
||||
"In this tutorial, you learn how to train and evaluate a BigQuery ML model using Vertex AI Pipelines and BigQuery ML pipeline components. \n",
|
||||
@@ -87,8 +89,27 @@
|
||||
" - Generate the ARIMA Plus forecasts\n",
|
||||
" - Generate the ARIMA PLUS forecast explainations\n",
|
||||
"- Compile the pipeline.\n",
|
||||
"- Execute the pipeline.\n",
|
||||
"- Execute the pipeline."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "586acfa9b502"
|
||||
},
|
||||
"source": [
|
||||
"### Dataset\n",
|
||||
"\n",
|
||||
"The dataset is a modified version of the dataset in [Build and visualize demand forecast predictions using Datastream, Dataflow, BigQuery ML, and Looker\n",
|
||||
"](https://cloud.google.com/architecture/build-visualize-demand-forecast-prediction-datastream-dataflow-bigqueryml-looker) solution architecture\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "tvgnzT1CKxrO"
|
||||
},
|
||||
"source": [
|
||||
"### Costs \n",
|
||||
"\n",
|
||||
"This tutorial uses billable components of Google Cloud:\n",
|
||||
@@ -352,9 +373,8 @@
|
||||
"id": "06571eb4063b"
|
||||
},
|
||||
"source": [
|
||||
"#### Timestamp\n",
|
||||
"\n",
|
||||
"If you are in a live tutorial session, you might be using a shared test account or project. To avoid name collisions between users on resources created, you create a timestamp for each instance session, and append it onto the name of resources you create in this tutorial."
|
||||
"#### UUID\n",
|
||||
"If you are in a live tutorial session, you might be using a shared test account or project. To avoid name collisions between users on resources created, you create a uuid for each instance session, and append it onto the name of resources you create in this tutorial."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -365,9 +385,16 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from datetime import datetime\n",
|
||||
"import random\n",
|
||||
"import string\n",
|
||||
"\n",
|
||||
"TIMESTAMP = datetime.now().strftime(\"%Y%m%d%H%M%S\")"
|
||||
"\n",
|
||||
"# Generate a uuid of a specifed length(default=8)\n",
|
||||
"def generate_uuid(length: int = 8) -> str:\n",
|
||||
" return \"\".join(random.choices(string.ascii_lowercase + string.digits, k=length))\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"UUID = generate_uuid()"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -485,7 +512,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"if BUCKET_NAME == \"\" or BUCKET_NAME is None or BUCKET_NAME == \"[your-bucket-name]\":\n",
|
||||
" BUCKET_NAME = PROJECT_ID + \"-aip-\" + TIMESTAMP\n",
|
||||
" BUCKET_NAME = PROJECT_ID + \"-aip-\" + UUID\n",
|
||||
" BUCKET_URI = f\"gs://{BUCKET_NAME}\""
|
||||
]
|
||||
},
|
||||
@@ -706,6 +733,7 @@
|
||||
"KFP_COMPONENTS_PATH = \"components\"\n",
|
||||
"PIPELINES_PATH = \"pipelines\"\n",
|
||||
"\n",
|
||||
"! mkdir -m 777 -p {DATA_PATH}\n",
|
||||
"! mkdir -m 777 -p {KFP_COMPONENTS_PATH}\n",
|
||||
"! mkdir -m 777 -p {PIPELINES_PATH}"
|
||||
]
|
||||
@@ -771,7 +799,7 @@
|
||||
" --location={LOCATION} \\\n",
|
||||
" --source_format=CSV \\\n",
|
||||
" --skip_leading_rows=1\\\n",
|
||||
" fast_fresh.orders_{TIMESTAMP} \\\n",
|
||||
" fast_fresh.orders_{UUID} \\\n",
|
||||
" {RAW_DATA_URI} \\\n",
|
||||
" time_of_sale:DATETIME,order_id:INTEGER,product_name:STRING,price:NUMERIC,quantity:NUMERIC,payment_method:STRING,store_id:INTEGER,user_id:INTEGER"
|
||||
]
|
||||
@@ -782,7 +810,7 @@
|
||||
"id": "ZrgOD30o7HcL"
|
||||
},
|
||||
"source": [
|
||||
"## BQML Training Formalization\n",
|
||||
"## BigQuery ML Training Formalization\n",
|
||||
"\n",
|
||||
"In the next cells, you build the components and pipeline to train and evaluate the BQML demand forecasting model."
|
||||
]
|
||||
@@ -820,13 +848,13 @@
|
||||
"BQ_EVALUATE_MODEL_TABLE_PREFIX = \"orders_arima_model_evaluate\"\n",
|
||||
"BQ_FORECAST_TABLE_PREFIX = \"orders_arima_forecast\"\n",
|
||||
"BQ_EXPLAIN_FORECAST_TABLE_PREFIX = \"orders_arima_explain_forecast\"\n",
|
||||
"BQ_ORDERS_TABLE = f\"{BQ_ORDERS_TABLE_PREFIX}_{TIMESTAMP}\"\n",
|
||||
"BQ_TRAINING_TABLE = f\"{BQ_TRAINING_TABLE_PREFIX}_{TIMESTAMP}\"\n",
|
||||
"BQ_MODEL_TABLE = f\"{BQ_MODEL_TABLE_PREFIX}_{TIMESTAMP}\"\n",
|
||||
"BQ_EVALUATE_TS_TABLE = f\"{BQ_EVALUATE_TS_TABLE_PREFIX}_{TIMESTAMP}\"\n",
|
||||
"BQ_EVALUATE_MODEL_TABLE = f\"{BQ_EVALUATE_MODEL_TABLE_PREFIX}_{TIMESTAMP}\"\n",
|
||||
"BQ_FORECAST_TABLE = f\"{BQ_FORECAST_TABLE_PREFIX}_{TIMESTAMP}\"\n",
|
||||
"BQ_EXPLAIN_FORECAST_TABLE = f\"{BQ_EXPLAIN_FORECAST_TABLE_PREFIX}_{TIMESTAMP}\"\n",
|
||||
"BQ_ORDERS_TABLE = f\"{BQ_ORDERS_TABLE_PREFIX}_{UUID}\"\n",
|
||||
"BQ_TRAINING_TABLE = f\"{BQ_TRAINING_TABLE_PREFIX}_{UUID}\"\n",
|
||||
"BQ_MODEL_TABLE = f\"{BQ_MODEL_TABLE_PREFIX}_{UUID}\"\n",
|
||||
"BQ_EVALUATE_TS_TABLE = f\"{BQ_EVALUATE_TS_TABLE_PREFIX}_{UUID}\"\n",
|
||||
"BQ_EVALUATE_MODEL_TABLE = f\"{BQ_EVALUATE_MODEL_TABLE_PREFIX}_{UUID}\"\n",
|
||||
"BQ_FORECAST_TABLE = f\"{BQ_FORECAST_TABLE_PREFIX}_{UUID}\"\n",
|
||||
"BQ_EXPLAIN_FORECAST_TABLE = f\"{BQ_EXPLAIN_FORECAST_TABLE_PREFIX}_{UUID}\"\n",
|
||||
"\n",
|
||||
"BQ_TRAIN_CONFIGURATION = {\n",
|
||||
" \"destinationTable\": {\n",
|
||||
@@ -1022,7 +1050,7 @@
|
||||
"id": "pcSL1FHk69KT"
|
||||
},
|
||||
"source": [
|
||||
"### Build the BQML training pipeline\n",
|
||||
"### Build the BigQuery ML training pipeline\n",
|
||||
"\n",
|
||||
"Define your workflow using Kubeflow Pipelines DSL package. \n",
|
||||
"\n",
|
||||
@@ -1094,8 +1122,8 @@
|
||||
" location=location,\n",
|
||||
" ).set_display_name(\"get train data\")\n",
|
||||
"\n",
|
||||
" # Train the ARIMA PLUS model\n",
|
||||
" bq_arima_model_op = (\n",
|
||||
" # Run an ARIMA PLUS experiment\n",
|
||||
" bq_arima_model_exp_op = (\n",
|
||||
" BigqueryCreateModelJobOp(\n",
|
||||
" query=f\"\"\"\n",
|
||||
" -- create model table\n",
|
||||
@@ -1104,10 +1132,7 @@
|
||||
" MODEL_TYPE = \\'ARIMA_PLUS\\',\n",
|
||||
" TIME_SERIES_TIMESTAMP_COL = \\'hourly_timestamp\\',\n",
|
||||
" TIME_SERIES_DATA_COL = \\'total_sold\\',\n",
|
||||
" TIME_SERIES_ID_COL = [\\'product_name\\'],\n",
|
||||
" MODEL_REGISTRY = \\'vertex_ai\\',\n",
|
||||
" VERTEX_AI_MODEL_ID = \\'order_demand_forecasting\\',\n",
|
||||
" VERTEX_AI_MODEL_VERSION_ALIASES = [\\'staging\\']\n",
|
||||
" TIME_SERIES_ID_COL = [\\'product_name\\']\n",
|
||||
" ) AS\n",
|
||||
" SELECT\n",
|
||||
" hourly_timestamp,\n",
|
||||
@@ -1119,7 +1144,7 @@
|
||||
" project=project,\n",
|
||||
" location=location,\n",
|
||||
" )\n",
|
||||
" .set_display_name(\"train arima plus model\")\n",
|
||||
" .set_display_name(\"run arima+ model experiment\")\n",
|
||||
" .after(create_training_dataset_op)\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
@@ -1128,12 +1153,12 @@
|
||||
" BigqueryMLArimaEvaluateJobOp(\n",
|
||||
" project=project,\n",
|
||||
" location=location,\n",
|
||||
" model=bq_arima_model_op.outputs[\"model\"],\n",
|
||||
" model=bq_arima_model_exp_op.outputs[\"model\"],\n",
|
||||
" show_all_candidate_models=False,\n",
|
||||
" job_configuration_query=bq_evaluate_time_series_configuration,\n",
|
||||
" )\n",
|
||||
" .set_display_name(\"evaluate arima plus time series\")\n",
|
||||
" .after(bq_arima_model_op)\n",
|
||||
" .after(bq_arima_model_exp_op)\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" # Evaluate ARIMA Plus model\n",
|
||||
@@ -1141,12 +1166,12 @@
|
||||
" BigqueryEvaluateModelJobOp(\n",
|
||||
" project=project,\n",
|
||||
" location=location,\n",
|
||||
" model=bq_arima_model_op.outputs[\"model\"],\n",
|
||||
" model=bq_arima_model_exp_op.outputs[\"model\"],\n",
|
||||
" query_statement=f\"\"\"SELECT * FROM `{project}.{bq_dataset}.{bq_training_table}` WHERE split='TEST'\"\"\",\n",
|
||||
" job_configuration_query=bq_evaluate_model_configuration,\n",
|
||||
" )\n",
|
||||
" .set_display_name(\"evaluate arima plus model\")\n",
|
||||
" .after(bq_arima_model_op)\n",
|
||||
" .after(bq_arima_model_exp_op)\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" # Plot model metrics\n",
|
||||
@@ -1164,6 +1189,34 @@
|
||||
" < PERF_THRESHOLD,\n",
|
||||
" name=\"avg. mae good\",\n",
|
||||
" ):\n",
|
||||
" # Train the ARIMA PLUS model\n",
|
||||
" bq_arima_model_op = (\n",
|
||||
" BigqueryCreateModelJobOp(\n",
|
||||
" query=f\"\"\"\n",
|
||||
" -- create model table\n",
|
||||
" CREATE OR REPLACE MODEL `{project}.{bq_dataset}.{bq_model_table}`\n",
|
||||
" OPTIONS(\n",
|
||||
" MODEL_TYPE = \\'ARIMA_PLUS\\',\n",
|
||||
" TIME_SERIES_TIMESTAMP_COL = \\'hourly_timestamp\\',\n",
|
||||
" TIME_SERIES_DATA_COL = \\'total_sold\\',\n",
|
||||
" TIME_SERIES_ID_COL = [\\'product_name\\'],\n",
|
||||
" MODEL_REGISTRY = \\'vertex_ai\\',\n",
|
||||
" VERTEX_AI_MODEL_ID = \\'order_demand_forecasting\\',\n",
|
||||
" VERTEX_AI_MODEL_VERSION_ALIASES = [\\'staging\\']\n",
|
||||
" ) AS\n",
|
||||
" SELECT\n",
|
||||
" DATETIME_TRUNC(time_of_sale, HOUR) as hourly_timestamp,\n",
|
||||
" product_name,\n",
|
||||
" SUM(quantity) AS total_sold,\n",
|
||||
" FROM `{project}.{bq_dataset}.{bq_orders_table}`\n",
|
||||
" GROUP BY hourly_timestamp, product_name;\n",
|
||||
" \"\"\",\n",
|
||||
" project=project,\n",
|
||||
" location=location,\n",
|
||||
" )\n",
|
||||
" .set_display_name(\"train arima+ model\")\n",
|
||||
" .after(get_evaluation_model_metrics_op)\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" # Generate the ARIMA PLUS forecasts\n",
|
||||
" bq_arima_forecast_op = (\n",
|
||||
@@ -1224,7 +1277,7 @@
|
||||
"source": [
|
||||
"### Execute your pipeline\n",
|
||||
"\n",
|
||||
"Next, you execute the pipeline. It takes the following parameters which we set as default:\n",
|
||||
"Next, we execute the pipeline. It takes the following parameters which we set as default:\n",
|
||||
"\n",
|
||||
"- `bq_dataset`: The BigQuery dataset to train on.\n",
|
||||
"- `bq_orders_table` : The BigQuery table of raw data.\n",
|
||||
@@ -1266,7 +1319,7 @@
|
||||
"source": [
|
||||
"### View BigQuery ML training pipeline results\n",
|
||||
"\n",
|
||||
"Finally, you will view the artifact outputs of each task in the pipeline."
|
||||
"Finally, you view the artifact outputs of each task in the pipeline."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1342,8 +1395,8 @@
|
||||
"print(\"bigquery-ml-arima-evaluate-job\")\n",
|
||||
"artifacts = print_pipeline_output(bqml_pipeline, \"bigquery-ml-arima-evaluate-job\")\n",
|
||||
"print(\"\\n\\n\")\n",
|
||||
"print(\"get-model-evaluation-metrics\")\n",
|
||||
"artifacts = print_pipeline_output(bqml_pipeline, \"get-model-evaluation-metrics\")\n",
|
||||
"print(\"bigquery-evaluate-model-job\")\n",
|
||||
"artifacts = print_pipeline_output(bqml_pipeline, \"bigquery-evaluate-model-job\")\n",
|
||||
"print(\"\\n\\n\")\n",
|
||||
"print(\"bigquery-forecast-model-job\")\n",
|
||||
"artifacts = print_pipeline_output(bqml_pipeline, \"bigquery-forecast-model-job\")\n",
|
||||
@@ -1407,7 +1460,8 @@
|
||||
"\n",
|
||||
"# Remove local resorces\n",
|
||||
"! rm -rf {KFP_COMPONENTS_PATH}\n",
|
||||
"! rm -rf {PIPELINES_PATH}"
|
||||
"! rm -rf {PIPELINES_PATH}\n",
|
||||
"! rm -rf {DATA_PATH}"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
+870
@@ -0,0 +1,870 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "view-in-github"
|
||||
},
|
||||
"source": [
|
||||
"<a href=\"https://colab.research.google.com/github/Narwhalprime/vertex-ai-samples/blob/main/notebooks/community/pipelines/google_cloud_pipeline_components_cloud_natural_language_pipeline.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "1142fd18"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Copyright 2022 Google LLC\n",
|
||||
"#\n",
|
||||
"# Licensed under the Apache License, Version 2.0 (the \"License\");\n",
|
||||
"# you may not use this file except in compliance with the License.\n",
|
||||
"# You may obtain a copy of the License at\n",
|
||||
"#\n",
|
||||
"# https://www.apache.org/licenses/LICENSE-2.0\n",
|
||||
"#\n",
|
||||
"# Unless required by applicable law or agreed to in writing, software\n",
|
||||
"# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
|
||||
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
|
||||
"# See the License for the specific language governing permissions and\n",
|
||||
"# limitations under the License."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "BwO30Ag12YcB"
|
||||
},
|
||||
"source": [
|
||||
"# Vertex Pipelines: Cloud Natural Language model training pipeline\n",
|
||||
"<table align=\"left\">\n",
|
||||
"\n",
|
||||
" <td>\n",
|
||||
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/pipelines/google_cloud_pipeline_components_cloud_natural_language_pipeline.ipynb\">\n",
|
||||
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" 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/pipelines/google_cloud_pipeline_components_cloud_natural_language_pipeline.ipynb\">\n",
|
||||
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
|
||||
" View on GitHub\n",
|
||||
" </a>\n",
|
||||
" </td>\n",
|
||||
" <td>\n",
|
||||
" <a href=\"https://console.cloud.google.com/ai/platform/notebooks/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/natural_language/cloud_natural_language_pipeline.ipynb\">\n",
|
||||
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
|
||||
" Open in Vertex AI Workbench\n",
|
||||
" </a>\n",
|
||||
" </td>\n",
|
||||
"</table>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "tvgnzT1CKxrO"
|
||||
},
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"This notebook shows how to use [Google Cloud Pipeline Components SDK](https://cloud.google.com/vertex-ai/docs/pipelines/components-introduction) and additional components in this directory to run a machine learning pipeline in [Vertex AI Pipelines](https://cloud.google.com/vertex-ai/docs/pipelines/introduction) to train a TensorFlow text classification model.\n",
|
||||
"\n",
|
||||
"In this pipeline, the model training Docker image utilizes [TFHub](https://tfhub.dev/) models to perform state-of-the-art text classification training. The image is pre-built and ready to use, so no additional Docker setup is required."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "d975e698c9a4"
|
||||
},
|
||||
"source": [
|
||||
"### Objective\n",
|
||||
"\n",
|
||||
"In this tutorial, you learn how to construct an end-to-end training pipeine within Vertex AI pipelines that ingests a dataset, trains a text classification model on it, and outputs evaluation metrics.\n",
|
||||
"\n",
|
||||
"This tutorial uses the following Google Cloud ML services and resources:\n",
|
||||
"\n",
|
||||
"- Vertex AI Pipelines\n",
|
||||
"- Vertex AI Datasets\n",
|
||||
"\n",
|
||||
"The steps performed include:\n",
|
||||
"\n",
|
||||
"- Define Kubeflow pipeline components\n",
|
||||
"- Setup Kubeflow pipeline\n",
|
||||
"- Run pipeline on Vertex AI"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "08d289fa873f"
|
||||
},
|
||||
"source": [
|
||||
"## Dataset\n",
|
||||
"\n",
|
||||
"This notebook requires that the user has two datasets exported from Vertex AI [managed datasets](https://cloud.google.com/vertex-ai/docs/training/using-managed-datasets): one with train and validation data splits, and the other with test data used for evaluation. Please ensure no data is shared between the two datasets (in particular, no evaluation data should be part of the train or validation splits). To export a Vertex AI dataset, please follow the following public docs:\n",
|
||||
"* [Preparing data](https://cloud.google.com/vertex-ai/docs/text-data/classification/prepare-data)\n",
|
||||
"* [Creating a Vertex AI dataset](https://cloud.google.com/vertex-ai/docs/text-data/classification/create-dataset) from the above data\n",
|
||||
"* [Exporting dataset and its annotations](https://cloud.google.com/vertex-ai/docs/datasets/export-metadata-annotations); ensure the resulting export is located in a Google Cloud Storage (GCS) bucket you own. You may need to manually separate the test split data into its own file."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "aed92deeb4a0"
|
||||
},
|
||||
"source": [
|
||||
"## Costs\n",
|
||||
"\n",
|
||||
"This tutorial uses billable components of Google Cloud:\n",
|
||||
"\n",
|
||||
"* Vertex AI\n",
|
||||
"* Cloud Storage\n",
|
||||
"\n",
|
||||
"Learn about [Vertex AI\n",
|
||||
"pricing](https://cloud.google.com/vertex-ai/pricing) and [Cloud Storage\n",
|
||||
"pricing](https://cloud.google.com/storage/pricing), and use the [Pricing\n",
|
||||
"Calculator](https://cloud.google.com/products/calculator/)\n",
|
||||
"to generate a cost estimate based on your projected usage."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "setup_local"
|
||||
},
|
||||
"source": [
|
||||
"## Setup\n",
|
||||
"\n",
|
||||
"If you are using Colab or Google Vertex AI Workbench Notebooks, your environment already meets all the requirements to run this notebook. You can skip this step.\n",
|
||||
"\n",
|
||||
"***NOTE***: This notebook has been tested in the following environment:\n",
|
||||
"\n",
|
||||
"* Python version = 3.8\n",
|
||||
"\n",
|
||||
"Otherwise, make sure your environment meets this notebook's requirements. You need the following:\n",
|
||||
"\n",
|
||||
"- The Cloud Storage SDK\n",
|
||||
"- Python 3\n",
|
||||
"- virtualenv\n",
|
||||
"- Jupyter notebook running in a virtual environment with Python 3\n",
|
||||
"\n",
|
||||
"The Cloud Storage guide to [Setting up a Python development environment](https://cloud.google.com/python/setup) and the [Jupyter installation guide](https://jupyter.org/install) provide detailed instructions for meeting these requirements. The following steps provide a condensed set of instructions:\n",
|
||||
"\n",
|
||||
"1. [Install and initialize the SDK](https://cloud.google.com/sdk/docs/).\n",
|
||||
"\n",
|
||||
"2. [Install Python 3](https://cloud.google.com/python/setup#installing_python).\n",
|
||||
"\n",
|
||||
"3. [Install virtualenv](https://cloud.google.com/python/setup#installing_and_using_virtualenv) and create a virtual environment that uses Python 3. Activate the virtual environment.\n",
|
||||
"\n",
|
||||
"4. Activate that environment and run `pip3 install Jupyter` in a terminal shell to install Jupyter.\n",
|
||||
"\n",
|
||||
"5. Run `jupyter notebook` on the command line in a terminal shell to launch Jupyter.\n",
|
||||
"\n",
|
||||
"6. Open this notebook in the Jupyter Notebook Dashboard.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "568d5c16"
|
||||
},
|
||||
"source": [
|
||||
"### Install additional packages\n",
|
||||
"\n",
|
||||
"Run the following commands to setup the packages for this notebook. Note that the last code snippet in this section restarts your kernel in order to load the installs properly, so when initalizing this notebook from scratch, it is recommended to run up to that cell, then afterwards you may start running the cell after that."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "dac98aac"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Install using pip3\n",
|
||||
"!pip3 install -U tensorflow google-cloud-pipeline-components google-cloud-aiplatform kfp==1.8.16 \"shapely<2\" -q"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "alRWYgYTdz7P"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Version check\n",
|
||||
"# This has been tested with KFP 1.8.16\n",
|
||||
"! python3 -c \"import kfp; print('KFP SDK version: {}'.format(kfp.__version__))\"\n",
|
||||
"! python3 -c \"import google_cloud_pipeline_components; print('google_cloud_pipeline_components version: {}'.format(google_cloud_pipeline_components.__version__))\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "d0a15440"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"\n",
|
||||
"if not os.getenv(\"IS_TESTING\"):\n",
|
||||
" # Automatically restart kernel after installs\n",
|
||||
" import IPython\n",
|
||||
"\n",
|
||||
" app = IPython.Application.instance()\n",
|
||||
" app.kernel.do_shutdown(True)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "B9IYalYObAbY"
|
||||
},
|
||||
"source": [
|
||||
"## Before you begin\n",
|
||||
"\n",
|
||||
"### Set up your Google Cloud project\n",
|
||||
"\n",
|
||||
"**The following steps are required, regardless of your notebook environment.**\n",
|
||||
"\n",
|
||||
"1. [Select or create a Google Cloud project](https://console.cloud.google.com/cloud-resource-manager). When you first create an account, you get a $300 free credit towards your compute/storage costs.\n",
|
||||
"\n",
|
||||
"2. [Make sure that billing is enabled for your project](https://cloud.google.com/billing/docs/how-to/modify-project).\n",
|
||||
"\n",
|
||||
"3. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com,storage.googleapis.com).\n",
|
||||
"\n",
|
||||
"4. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "VA_kzAIIj2G_"
|
||||
},
|
||||
"source": [
|
||||
"### Authenticate your Google Cloud account\n",
|
||||
"\n",
|
||||
"**If you are using Vertex AI Workbench Notebooks**, your environment is already\n",
|
||||
"authenticated. Skip this step.\n",
|
||||
"\n",
|
||||
"**If you are using Colab**, run the cell below and follow the instructions\n",
|
||||
"when prompted to authenticate your account via oAuth.\n",
|
||||
"\n",
|
||||
"**Otherwise**, follow these steps:\n",
|
||||
"\n",
|
||||
"1. In the Cloud Console, go to the [**Create service account key**\n",
|
||||
" page](https://console.cloud.google.com/apis/credentials/serviceaccountkey).\n",
|
||||
"\n",
|
||||
"2. Click **Create service account**.\n",
|
||||
"\n",
|
||||
"3. In the **Service account name** field, enter a name, and\n",
|
||||
" click **Create**.\n",
|
||||
"\n",
|
||||
"4. In the **Grant this service account access to project** section, click the **Role** drop-down list. Type \"Vertex AI\"\n",
|
||||
"into the filter box, and select\n",
|
||||
" **Vertex AI Administrator**. Type \"Storage Object Admin\" into the filter box, and select **Storage Object Admin**.\n",
|
||||
"\n",
|
||||
"5. Click *Create*. A JSON file that contains your key downloads to your\n",
|
||||
"local environment.\n",
|
||||
"\n",
|
||||
"6. Enter the path to your service account key as the\n",
|
||||
"`GOOGLE_APPLICATION_CREDENTIALS` variable in the cell below and run the cell."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "PyQmSRbKA8r-"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# If you are running this notebook in Colab, run this cell and follow the\n",
|
||||
"# instructions to authenticate your GCP account. This provides access to your\n",
|
||||
"# Cloud Storage bucket and lets you submit training jobs and prediction\n",
|
||||
"# requests.\n",
|
||||
"\n",
|
||||
"import os\n",
|
||||
"import sys\n",
|
||||
"\n",
|
||||
"# If on Vertex AI Workbench, then don't execute this code\n",
|
||||
"IS_COLAB = \"google.colab\" in sys.modules\n",
|
||||
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
|
||||
" \"DL_ANACONDA_HOME\"\n",
|
||||
"):\n",
|
||||
" if \"google.colab\" in sys.modules:\n",
|
||||
" from google.colab import auth as google_auth\n",
|
||||
"\n",
|
||||
" google_auth.authenticate_user()\n",
|
||||
"\n",
|
||||
" # If you are running this notebook locally, replace the string below with the\n",
|
||||
" # path to your service account key and run this cell to authenticate your GCP\n",
|
||||
" # account.\n",
|
||||
" elif not os.getenv(\"IS_TESTING\"):\n",
|
||||
" %env GOOGLE_APPLICATION_CREDENTIALS ''"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "set_service_account"
|
||||
},
|
||||
"source": [
|
||||
"### Set project ID\n",
|
||||
"\n",
|
||||
"Set your project ID here. If you don't know this, the following snippet attempts to deterine this from your gcloud config. Please continue only if the notebook can see your desired project."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "AkqEd5Gin9mn"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"PROJECT_ID = \"your-project-id\" # @param {type:\"string\"}\n",
|
||||
"if PROJECT_ID == \"\" or PROJECT_ID is None or PROJECT_ID == \"[your-project-id]\":\n",
|
||||
" # Get your GCP project id from gcloud\n",
|
||||
" shell_output = !gcloud config list --format 'value(core.project)' 2>/dev/null\n",
|
||||
" PROJECT_ID = shell_output[0]\n",
|
||||
"print(\"Project ID:\", PROJECT_ID)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "OVO_gUqpFEP2"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!gcloud config set project $PROJECT_ID"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "a27d4cee"
|
||||
},
|
||||
"source": [
|
||||
"### Setup project information\n",
|
||||
"\n",
|
||||
"Enter information about your project and datasets here."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "7e9477a2"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"REGION = \"us\" # @param {type:\"string\"}\n",
|
||||
"LOCATION = \"us-central1\" # @param {type:\"string\"}\n",
|
||||
"TRAINING_DATA_LOCATION = \"gs://your-training-data-location\" # @param {type:\"string\"}\n",
|
||||
"TASK_TYPE = \"CLASSIFICATION\" # @param [\"CLASSIFICATION\", \"MULTILABEL_CLASSIFICATION\"]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "o-MZnHsimbOH"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Since we are training a custom model, we need to specify the list of possible\n",
|
||||
"# classes/labels.\n",
|
||||
"# e.g, [\"FirstClass\", \"SecondClass\"]\n",
|
||||
"# An additional class \"[UNK]\" will be added to the list indicating that none of\n",
|
||||
"# the specified labels are a match.\n",
|
||||
"CLASS_NAMES = [\"\"]\n",
|
||||
"\n",
|
||||
"# This is a list of GCS URIs; e.g., [\"gs://your-bucket-name-here/your-input-file.jsonl\"].\n",
|
||||
"TEST_DATA_URIS = [\"gs://your-bucket-name-here/your-input-file.jsonl\"]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "timestamp"
|
||||
},
|
||||
"source": [
|
||||
"#### UUID\n",
|
||||
"\n",
|
||||
"To avoid name collisions with other resources in your project, you can create a UUID with the code below and append it onto the name of the bucket(s) created in this notebook."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "wh9sgzemwLXE"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import random\n",
|
||||
"import string\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Generate a uuid of a specifed length(default=8)\n",
|
||||
"def generate_uuid(length: int = 8) -> str:\n",
|
||||
" return \"\".join(random.choices(string.ascii_lowercase + string.digits, k=length))\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"UUID = generate_uuid()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "bucket:mbsdk"
|
||||
},
|
||||
"source": [
|
||||
"### Create a Cloud Storage bucket\n",
|
||||
"\n",
|
||||
"**The following steps are required, regardless of your notebook environment.**\n",
|
||||
"\n",
|
||||
"When you initialize the Vertex AI SDK for Python, you specify a Cloud Storage staging bucket. The staging bucket is where all the data associated with your dataset and model resources are retained across sessions.\n",
|
||||
"\n",
|
||||
"Set the name of your Cloud Storage bucket below. Bucket names must be globally unique across all Google Cloud projects, including those outside of your organization."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "bucket"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"BUCKET_NAME = \"[your-bucket-name]\" # @param {type:\"string\"}\n",
|
||||
"BUCKET_URI = f\"gs://{BUCKET_NAME}\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "autoset_bucket"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"if BUCKET_NAME == \"\" or BUCKET_NAME is None or BUCKET_NAME == \"[your-bucket-name]\":\n",
|
||||
" BUCKET_NAME = PROJECT_ID + \"aip-\" + UUID\n",
|
||||
" BUCKET_URI = \"gs://\" + BUCKET_NAME"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "create_bucket"
|
||||
},
|
||||
"source": [
|
||||
"**Only if your bucket doesn't already exist**: Run the following cell to create your Cloud Storage bucket."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "dO0NV93IwLXF"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!gsutil mb -l $REGION $BUCKET_URI"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "validate_bucket"
|
||||
},
|
||||
"source": [
|
||||
"Finally, validate access to your Cloud Storage bucket by examining its contents:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "Hg5f2oKBwLXG"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!gsutil ls -al $BUCKET_URI"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "EuFETRptyKXc"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from google.cloud import aiplatform\n",
|
||||
"\n",
|
||||
"aiplatform.init(project=PROJECT_ID, staging_bucket=BUCKET_URI)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "f3a09765"
|
||||
},
|
||||
"source": [
|
||||
"## Create training pipeline"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "89bb4a50"
|
||||
},
|
||||
"source": [
|
||||
"### Import libraries"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "0f361e65"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from google_cloud_pipeline_components.aiplatform import ModelBatchPredictOp\n",
|
||||
"from google_cloud_pipeline_components.experimental import natural_language\n",
|
||||
"from google_cloud_pipeline_components.experimental.evaluation import (\n",
|
||||
" GetVertexModelOp, ModelEvaluationClassificationOp,\n",
|
||||
" TargetFieldDataRemoverOp)\n",
|
||||
"from kfp import components\n",
|
||||
"from kfp.v2 import compiler, dsl"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "d33c87e4-2ada-4b87-bf75-064247f3162d"
|
||||
},
|
||||
"source": [
|
||||
"### Define constants"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "36ceb9f8"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Worker pool specs\n",
|
||||
"TRAINING_MACHINE_TYPE = \"n1-highmem-8\"\n",
|
||||
"ACCELERATOR_TYPE = \"NVIDIA_TESLA_T4\"\n",
|
||||
"ACCELERATOR_COUNT = 1\n",
|
||||
"EVAL_MACHINE_TYPE = \"n1-highmem-8\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "zAaMJKrhAe5L"
|
||||
},
|
||||
"source": [
|
||||
"## Define components\n",
|
||||
"\n",
|
||||
"This pipeline is composed from the following components:\n",
|
||||
"\n",
|
||||
"- **train-tfhub-model** - Trains a new Tensorflow model using TFHub layers from pre-built Docker image\n",
|
||||
"- **upload-tensorflow-model-to-google-cloud-vertex-ai** - Uploads resulting model to Vertex AI model registry\n",
|
||||
"- **get-vertex-model** - Gets model that has just been uploaded as an artifact in pipeline\n",
|
||||
"- **convert-dataset-export-for-batch-predict** - Preprocessing component that takes the test dataset exported from Vertex datasets and converts it to a simpler compatible one that is readable from the batch predict component\n",
|
||||
"- **target-field-data-remover** - Removes the target field (i.e., label) in the test dataset for the downstream batch predict component\n",
|
||||
"- **model-batch-predict** - Performs a batch prediction job\n",
|
||||
"- **model-evaluation-classification** - Calculates the evaluation metrics from the above batch predict job and exports the metrics artifact\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "DKe2iQNKgpKG"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Load upload TF model component\n",
|
||||
"upload_tensorflow_model_to_vertex_op = components.load_component_from_url(\n",
|
||||
" \"https://raw.githubusercontent.com/Ark-kun/pipeline_components/c6a8b67d1ada2cc17665c99ff6b410df588bee28/components/google-cloud/Vertex_AI/Models/Upload_Tensorflow_model/workaround_for_buggy_KFPv2_compiler/component.yaml\"\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "TEnh9Pcx6Xfi"
|
||||
},
|
||||
"source": [
|
||||
"### Define the pipeline\n",
|
||||
"\n",
|
||||
"The pipeline performs the following steps:\n",
|
||||
"- Trains new text classification model\n",
|
||||
"- Uploads model to Vertex AI Model Registry\n",
|
||||
"- Performs preprocessing steps on test dataset export: formats data for batch predcition, removes target field\n",
|
||||
"- Performs batch prediction on preprocessed test data\n",
|
||||
"- Evaluates performance of model based on batch prediction output"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "2a67cde8"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"@dsl.pipeline(name=\"text-classification-model\")\n",
|
||||
"def pipeline():\n",
|
||||
" train_task = natural_language.TrainTextClassificationOp()(\n",
|
||||
" project=PROJECT_ID,\n",
|
||||
" location=LOCATION,\n",
|
||||
" machine_type=TRAINING_MACHINE_TYPE,\n",
|
||||
" accelerator_type=ACCELERATOR_TYPE,\n",
|
||||
" accelerator_count=ACCELERATOR_COUNT,\n",
|
||||
" input_data_path=TRAINING_DATA_LOCATION,\n",
|
||||
" input_format=\"jsonl\",\n",
|
||||
" natural_language_task_type=TASK_TYPE,\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" upload_task = upload_tensorflow_model_to_vertex_op(\n",
|
||||
" model=train_task.outputs[\"model_output\"]\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" get_model_task = GetVertexModelOp(\n",
|
||||
" model_resource_name=upload_task.outputs[\"model_name\"]\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" classification_type = (\n",
|
||||
" \"multilabel\" if TASK_TYPE == \"MULTILABEL_CLASSIFICATION\" else \"multiclass\"\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" convert_dataset_task = natural_language.ConvertDatasetExportForBatchPredictOp(\n",
|
||||
" file_paths=TEST_DATA_URIS, classification_type=classification_type\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" target_field_remover_task = TargetFieldDataRemoverOp(\n",
|
||||
" project=PROJECT_ID,\n",
|
||||
" location=LOCATION,\n",
|
||||
" root_dir=BUCKET_URI,\n",
|
||||
" gcs_source_uris=convert_dataset_task.outputs[\"output_files\"],\n",
|
||||
" target_field_name=\"labels\",\n",
|
||||
" instances_format=\"jsonl\",\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" # Note: ModelBatchPredictOp doesn't support accelerators currently.\n",
|
||||
" batch_predict_task = ModelBatchPredictOp(\n",
|
||||
" project=PROJECT_ID,\n",
|
||||
" location=LOCATION,\n",
|
||||
" model=get_model_task.outputs[\"model\"],\n",
|
||||
" job_display_name=\"nl-batch-predict-evaluation\",\n",
|
||||
" gcs_source_uris=target_field_remover_task.outputs[\"gcs_output_directory\"],\n",
|
||||
" instances_format=\"jsonl\",\n",
|
||||
" predictions_format=\"jsonl\",\n",
|
||||
" gcs_destination_output_uri_prefix=BUCKET_URI,\n",
|
||||
" machine_type=EVAL_MACHINE_TYPE,\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" # Note: Because we're running a custom training pipeline, the model source\n",
|
||||
" # is detected as Custom and thus it doesn't use AutoML NL's default settings\n",
|
||||
" # and fails if class_labels is excluded.\n",
|
||||
" ModelEvaluationClassificationOp(\n",
|
||||
" project=PROJECT_ID,\n",
|
||||
" location=LOCATION,\n",
|
||||
" root_dir=BUCKET_URI,\n",
|
||||
" class_labels=CLASS_NAMES + [\"[UNK]\"],\n",
|
||||
" predictions_gcs_source=batch_predict_task.outputs[\"gcs_output_directory\"],\n",
|
||||
" predictions_format=\"jsonl\",\n",
|
||||
" prediction_label_column=\"prediction.displayNames\",\n",
|
||||
" prediction_score_column=\"prediction.confidences\",\n",
|
||||
" ground_truth_gcs_source=convert_dataset_task.outputs[\"output_files\"],\n",
|
||||
" ground_truth_format=\"jsonl\",\n",
|
||||
" target_field_name=\"labels\",\n",
|
||||
" classification_type=TASK_TYPE,\n",
|
||||
" )"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "3211ba19"
|
||||
},
|
||||
"source": [
|
||||
"### Compile the pipeline"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "c368c73f"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"compiler.Compiler().compile(pipeline, \"nl_pipeline.json\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "l_Vxwz5cdF5f"
|
||||
},
|
||||
"source": [
|
||||
"Running the above line will generate a file locally or in Colab's directory."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "ax0jOxIaholy"
|
||||
},
|
||||
"source": [
|
||||
"### Run the pipeline\n",
|
||||
"\n",
|
||||
"This sends a create pipeline job request to Vertex Pipelines. Note that this task run synchronously and may take a while to complete.\n",
|
||||
"\n",
|
||||
"You may view the progress of the job at any time by clicking on the generated links (after \"View Pipeline Job\" in the console output of the cell below). Once the pipeline finishes, you may examine the artifacts produced from this pipeline."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "Wfs7QOSxhp_n"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"job = aiplatform.PipelineJob(\n",
|
||||
" display_name=\"nl_pipeline\",\n",
|
||||
" template_path=\"nl_pipeline.json\",\n",
|
||||
" location=LOCATION,\n",
|
||||
" enable_caching=True,\n",
|
||||
" parameter_values={},\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"job.run()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "UIyGPaihWJWn"
|
||||
},
|
||||
"source": [
|
||||
"Once the pipeline successfully finishes, go to the pipeline and examine the resulting metrics artifacts for the results. Otherwise, refer to the failing step(s) in the pipeline to determine the cause of any errors."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "OoexTJTy9jnH"
|
||||
},
|
||||
"source": [
|
||||
"## View model evaluation results\n",
|
||||
"\n",
|
||||
"To check the results of evaluation after pipeline execution, find the \"model-evaluation-classification\" subdirectory in the Cloud Storage bucket created by this pipeline. You may also run the following to directly output the contents of the metrics file:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "h9EqPCQF9lN9"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import tensorflow as tf\n",
|
||||
"\n",
|
||||
"EVAL_TASK_NAME = \"model-evaluation-classification\"\n",
|
||||
"PROJECT_NUMBER = job.gca_resource.name.split(\"/\")[1]\n",
|
||||
"for _ in range(len(job.gca_resource.job_detail.task_details)):\n",
|
||||
" TASK_ID = job.gca_resource.job_detail.task_details[_].task_id\n",
|
||||
" EVAL_METRICS = (\n",
|
||||
" BUCKET_URI\n",
|
||||
" + \"/\"\n",
|
||||
" + PROJECT_NUMBER\n",
|
||||
" + \"/\"\n",
|
||||
" + job.name\n",
|
||||
" + \"/\"\n",
|
||||
" + EVAL_TASK_NAME\n",
|
||||
" + \"_\"\n",
|
||||
" + str(TASK_ID)\n",
|
||||
" + \"/executor_output.json\"\n",
|
||||
" )\n",
|
||||
" if tf.io.gfile.exists(EVAL_METRICS):\n",
|
||||
" ! gsutil cat $EVAL_METRICS"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "TpV-iwP9qw9c"
|
||||
},
|
||||
"source": [
|
||||
"## Cleaning up\n",
|
||||
"\n",
|
||||
"To clean up the resources used by this pipeline, run the command below:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "sx_vKniMq9ZX"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Delete GCS bucket.\n",
|
||||
"!gsutil -m rm -r {BUCKET_URI}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "UMuyzrnZLoUa"
|
||||
},
|
||||
"source": [
|
||||
"# Next steps\n",
|
||||
"\n",
|
||||
"For an alternate approach, please check out the [\"ready-to-go\" text classification pipeline](https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/community/pipelines/google_cloud_pipeline_components_ready_to_go_text_classification_pipeline.ipynb). This pipeline exposes the model logic for further customization if needed, and adds an additional pipeline step to deploy the model to enable online predictions."
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"colab": {
|
||||
"collapsed_sections": [
|
||||
"d975e698c9a4",
|
||||
"08d289fa873f",
|
||||
"d33c87e4-2ada-4b87-bf75-064247f3162d",
|
||||
"3211ba19",
|
||||
"TpV-iwP9qw9c",
|
||||
"UMuyzrnZLoUa"
|
||||
],
|
||||
"name": "google_cloud_pipeline_components_cloud_natural_language_pipeline.ipynb",
|
||||
"toc_visible": true
|
||||
},
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"name": "python3"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 0
|
||||
}
|
||||
+1208
File diff suppressed because it is too large
Load Diff
+1750
File diff suppressed because it is too large
Load Diff
+1506
File diff suppressed because one or more lines are too long
@@ -112,7 +112,7 @@ def benchmark(
|
||||
|
||||
results = []
|
||||
for qps in qps_list:
|
||||
num_requests = max(qps * duration_sec, 10)
|
||||
num_requests = int(max(qps * duration_sec, 10))
|
||||
requests_for_qps = list(
|
||||
itertools.islice(itertools.cycle(requests), num_requests)
|
||||
)
|
||||
|
||||
+1569
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,987 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "18ebbd838e32"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Copyright 2023 Google LLC\n",
|
||||
"#\n",
|
||||
"# Licensed under the Apache License, Version 2.0 (the \"License\");\n",
|
||||
"# you may not use this file except in compliance with the License.\n",
|
||||
"# You may obtain a copy of the License at\n",
|
||||
"#\n",
|
||||
"# https://www.apache.org/licenses/LICENSE-2.0\n",
|
||||
"#\n",
|
||||
"# Unless required by applicable law or agreed to in writing, software\n",
|
||||
"# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
|
||||
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
|
||||
"# See the License for the specific language governing permissions and\n",
|
||||
"# limitations under the License."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "219f1b1fe8fe"
|
||||
},
|
||||
"source": [
|
||||
"# Deploy and host a Stable Diffusion model on Vertex AI\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "JAPoU8Sm5E6e"
|
||||
},
|
||||
"source": [
|
||||
"<table align=\"left\">\n",
|
||||
"\n",
|
||||
" <td>\n",
|
||||
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/vertex_endpoints/torchserve/dreambooth_stablediffusion.ipynb\">\n",
|
||||
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" 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/vertex_endpoints/torchserve/dreambooth_stablediffusion.ipynb\">\n",
|
||||
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" 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/vertex_endpoints/torchserve/dreambooth_stablediffusion.ipynb\">\n",
|
||||
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
|
||||
" Open in Vertex AI Workbench\n",
|
||||
" </a>\n",
|
||||
" </td>\n",
|
||||
"</table>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "fce05a8186d6"
|
||||
},
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This notebook demonstrates how to deploy and host a fine-tuned [Stable Diffusion 1.5](https://huggingface.co/runwayml/stable-diffusion-v1-5) model on Vertex AI. For hosting, you use the PyTorch 3 container built for Vertex AI with [TorchServe](https://pytorch.org/serve/index.html)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "c76216b03fec"
|
||||
},
|
||||
"source": [
|
||||
"### Objective\n",
|
||||
"\n",
|
||||
"In this tutorial, you learn how to host and deploy a Stable Diffusion 1.5 model on Vertex AI.\n",
|
||||
"\n",
|
||||
"This tutorial uses the following Google Cloud ML services:\n",
|
||||
"\n",
|
||||
"+ Vertex AI `Model` resource\n",
|
||||
"+ Vertex AI `Endpoint` resource\n",
|
||||
"\n",
|
||||
"The steps performed include:\n",
|
||||
"\n",
|
||||
"+ Create a `torchserve` handler for responding to prediction requests.\n",
|
||||
"+ Upload a Stable Diffusion 1.5 model on a prebuilt PyTorch container in Vertex AI.\n",
|
||||
"+ Deploy a model to a Vertex AI Endpoint.\n",
|
||||
"+ Send requests to the endpoint and parse the responses using Vertex AI Prediction service."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "c6deba5a8557"
|
||||
},
|
||||
"source": [
|
||||
"### Model\n",
|
||||
"\n",
|
||||
"This notebook uses a collection of model artifacts fine-tuned to generate images of a small dog. These are the same images used in the original [DreamBooth paper](https://dreambooth.github.io/)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "911dc651ea9c"
|
||||
},
|
||||
"source": [
|
||||
"### Costs\n",
|
||||
"\n",
|
||||
"This tutorial uses billable components of Google Cloud:\n",
|
||||
"\n",
|
||||
"* Vertex AI models\n",
|
||||
"* Vertex AI endpoints\n",
|
||||
"* Vertex AI prediction\n",
|
||||
"* Cloud Storage\n",
|
||||
"* (Optionally) Vertex AI Workbench\n",
|
||||
"\n",
|
||||
"Learn about [Vertex AI pricing](https://cloud.google.com/vertex-ai/pricing) and [Cloud Storage pricing](https://cloud.google.com/storage/pricing), and use the [Pricing Calculator](https://cloud.google.com/products/calculator/) to generate a cost estimate based on your projected usage."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "0d36bd3d53fa"
|
||||
},
|
||||
"source": [
|
||||
"## Hardware requirements\n",
|
||||
"\n",
|
||||
"This notebook requires that you use a GPU with a sufficient amount of VRAM available. It was tested on a `NVIDIA Tesla A100 GPU` with 85 GB of VRAM. Run the following cell to ensure that you have the correct hardware configuration."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "3dd4022552e5"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!nvidia-smi --query-gpu=name,memory.total,memory.free --format=\"csv,noheader\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "a782627e5f73"
|
||||
},
|
||||
"source": [
|
||||
"### Create a user-managed notebook on Vertex AI\n",
|
||||
"\n",
|
||||
"If you are using Vertex AI Workbench, you can create a notebook with the correct configuration by doing the following:\n",
|
||||
"\n",
|
||||
"+ Go to [Vertex AI Workbench](https://console.cloud.google.com/vertex-ai/workbench/user-managed) in the Google Cloud Console.\n",
|
||||
"+ Click **New Notebook** and then click **PyTorch 1.13** > **With 1 NVIDIA T4**.\n",
|
||||
"+ In the **New notebook** dialog box, click **Advanced Options**. The **Create a user-managed notebook** page opens up.\n",
|
||||
"+ In the **Create a user-managed notebook** page, do the following:\n",
|
||||
" * In the **Notebook name** box, type a name for your notebook, for example \"my-stablediffusion-nb\".\n",
|
||||
" * In the **Machine type** drop-down, select **A2 highgpu** > **a2-highgpu-1g**.\n",
|
||||
" * In the **GPU type** drop-down, select **NVIDIA Tesla A100**.\n",
|
||||
" * Check the box next to **Install NVIDIA GPU driver automatically for me**\n",
|
||||
" * Expand **Disk(s)** and do the following:\n",
|
||||
" - Under **Boot disk type**, select **SSD Persistent Disk**.\n",
|
||||
" - Under **Data disk type**, select **SSD Persistent Disk**.\n",
|
||||
" * Click **Create**."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "FAPoU8Sm5E6e"
|
||||
},
|
||||
"source": [
|
||||
"<div style=\"background:#feefe3; padding:5px; color:#aa0000\">\n",
|
||||
"<strong>Caution:</strong> Using a Vertex AI Workbench notebook with the above configuration can increase your costs significantly. You can estimate your costs using the <a href=\"https://cloud.google.com/products/calculator\"><u>costs calculator</u></a>.</div>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "0bb4201cc99a"
|
||||
},
|
||||
"source": [
|
||||
"## Installation\n",
|
||||
"\n",
|
||||
"Install the following packages required to execute this notebook.\n",
|
||||
"\n",
|
||||
"**Note**: You might need to change the version of PyTorch (`torch`) installed by `pip`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "9c769df171a6"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%%writefile requirements.txt\n",
|
||||
"diffusers\n",
|
||||
"ftfy\n",
|
||||
"google-cloud-aiplatform\n",
|
||||
"gradio\n",
|
||||
"ninja\n",
|
||||
"tensorboard==1.15.0\n",
|
||||
"torch\n",
|
||||
"torchaudio\n",
|
||||
"torchvision\n",
|
||||
"torchserve\n",
|
||||
"torch-model-archiver\n",
|
||||
"torch-workflow-archiver\n",
|
||||
"transformers"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "e46804ac90d8"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%pip install -r requirements.txt"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "58707a750154"
|
||||
},
|
||||
"source": [
|
||||
"### Colab only: Uncomment the following cell to restart the kernel."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "77c11549298a"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Automatically restart kernel after installs so that your environment can access the new packages\n",
|
||||
"# import IPython\n",
|
||||
"\n",
|
||||
"# app = IPython.Application.instance()\n",
|
||||
"# app.kernel.do_shutdown(True)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "294df346a918"
|
||||
},
|
||||
"source": [
|
||||
"## Before you begin"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "BF1j6f9HApxa"
|
||||
},
|
||||
"source": [
|
||||
"### Set up your Google Cloud project\n",
|
||||
"\n",
|
||||
"**The following steps are required, regardless of your notebook environment.**\n",
|
||||
"\n",
|
||||
"1. [Select or create a Google Cloud project](https://console.cloud.google.com/cloud-resource-manager). When you first create an account, you get a $300 free credit towards your compute/storage costs.\n",
|
||||
"\n",
|
||||
"2. [Make sure that billing is enabled for your project](https://cloud.google.com/billing/docs/how-to/modify-project).\n",
|
||||
"\n",
|
||||
"3. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com).\n",
|
||||
"\n",
|
||||
"4. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "WReHDGG5g0XY"
|
||||
},
|
||||
"source": [
|
||||
"#### Set your project ID\n",
|
||||
"\n",
|
||||
"**If you don't know your project ID**, try the following:\n",
|
||||
"* Run `gcloud config list`.\n",
|
||||
"* Run `gcloud projects list`.\n",
|
||||
"* See the support page: [Locate the project ID](https://support.google.com/googleapi/answer/7014113)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "oM1iC_MfAts1"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}\n",
|
||||
"\n",
|
||||
"# Set the project id\n",
|
||||
"! gcloud config set project {PROJECT_ID}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "region"
|
||||
},
|
||||
"source": [
|
||||
"#### Region\n",
|
||||
"\n",
|
||||
"You can also change the `REGION` variable used by Vertex AI. Learn more about [Vertex AI regions](https://cloud.google.com/vertex-ai/docs/general/locations)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "region"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"REGION = \"us-central1\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "sBCra4QMA2wR"
|
||||
},
|
||||
"source": [
|
||||
"### Authenticate your Google Cloud account\n",
|
||||
"\n",
|
||||
"Depending on your Jupyter environment, you may have to manually authenticate. Follow the relevant instructions below."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "74ccc9e52986"
|
||||
},
|
||||
"source": [
|
||||
"**1. Vertex AI Workbench**\n",
|
||||
"* Do nothing as you are already authenticated."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "de775a3773ba"
|
||||
},
|
||||
"source": [
|
||||
"**2. Local JupyterLab instance, uncomment and run:**"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "254614fa0c46"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# ! gcloud auth login"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "ef21552ccea8"
|
||||
},
|
||||
"source": [
|
||||
"**3. Colab, uncomment and run:**"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "603adbbf0532"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# from google.colab import auth\n",
|
||||
"# auth.authenticate_user()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "f6b2ccc891ed"
|
||||
},
|
||||
"source": [
|
||||
"**4. Service account or other**\n",
|
||||
"* See how to grant Cloud Storage permissions to your service account at https://cloud.google.com/storage/docs/gsutil/commands/iam#ch-examples."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "cb5c4ca3e851"
|
||||
},
|
||||
"source": [
|
||||
"### Import libraries"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "7348591eda51"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import base64\n",
|
||||
"import math\n",
|
||||
"\n",
|
||||
"import torch\n",
|
||||
"from diffusers import StableDiffusionPipeline\n",
|
||||
"from google.cloud import aiplatform\n",
|
||||
"from IPython import display\n",
|
||||
"from PIL import Image\n",
|
||||
"from torch import autocast"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "697566b5f660"
|
||||
},
|
||||
"source": [
|
||||
"## Optional: View model inferences\n",
|
||||
"\n",
|
||||
"Before uploading the model to Vertex AI, you can review the expected output from the model. The model used in this notebook is available for your use and can be downloaded from Cloud Storage. This download may take a few minutes to complete."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "d63df8d91215"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!gsutil -m cp gs://cloud-samples-data/vertex-ai/model-deployment/models/stable-diffusion/model_artifacts.zip \\\n",
|
||||
" ."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "89d613ae9573"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!unzip model_artifacts.zip"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "9192ea4f3b57"
|
||||
},
|
||||
"source": [
|
||||
"### Create new images\n",
|
||||
"\n",
|
||||
"With everything in place, you can now generate new images from the Stable Diffusion model. First you must load your model into a `StableDiffusionPipeline`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "cd1f30223b79"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"model_path = \"model_artifacts\"\n",
|
||||
"\n",
|
||||
"pipe = StableDiffusionPipeline.from_pretrained(\n",
|
||||
" model_path, torch_dtype=torch.float16\n",
|
||||
").to(\"cuda\")\n",
|
||||
"\n",
|
||||
"g_cuda = None"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "dd91520f58cf"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"g_cuda = torch.Generator(device=\"cuda\")\n",
|
||||
"seed = 52362\n",
|
||||
"g_cuda.manual_seed(seed)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "1e9c5d734b9f"
|
||||
},
|
||||
"source": [
|
||||
"With the model loaded into a `StableDiffusionPipeline`, you can now generate results (inferences) from the model. Each set of inference requires an input (called a [prompt](https://learnprompting.org/)) that specifies what the model should create.\n",
|
||||
"\n",
|
||||
"You can also vary other inputs into the model, as shown in the following cell."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "a28b73de55ce"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"prompt = \"photo of examplePup dog in a Monet style\"\n",
|
||||
"\n",
|
||||
"num_samples = 4\n",
|
||||
"num_batches = 1\n",
|
||||
"num_columns = 2\n",
|
||||
"guidance_scale = 10\n",
|
||||
"num_inference_steps = 50\n",
|
||||
"height = 512\n",
|
||||
"width = 512"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "11a7bb79de59"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def image_grid(imgs, cols):\n",
|
||||
" total = len(imgs)\n",
|
||||
" rows = math.ceil(total / cols)\n",
|
||||
"\n",
|
||||
" w, h = imgs[0].size\n",
|
||||
" grid = Image.new(\"RGB\", size=(cols * w, rows * h))\n",
|
||||
" grid_w, grid_h = grid.size\n",
|
||||
"\n",
|
||||
" for i, img in enumerate(imgs):\n",
|
||||
" grid.paste(img, box=(i % cols * w, i // cols * h))\n",
|
||||
" return grid\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"all_images = []\n",
|
||||
"for _ in range(num_batches):\n",
|
||||
" with autocast(\"cuda\"):\n",
|
||||
" images = pipe(\n",
|
||||
" [prompt] * num_samples,\n",
|
||||
" height=height,\n",
|
||||
" width=width,\n",
|
||||
" num_inference_steps=num_inference_steps,\n",
|
||||
" guidance_scale=guidance_scale,\n",
|
||||
" ).images\n",
|
||||
" all_images.extend(images)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"grid = image_grid(all_images, num_columns)\n",
|
||||
"grid"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "bbc72963ff88"
|
||||
},
|
||||
"source": [
|
||||
"## Deploy the model to Vertex AI\n",
|
||||
"\n",
|
||||
"You can host your Stable Diffusion 1.5 model on a Vertex AI endpoint where you can get inferences from it online. Uploading your model is a four step process: \n",
|
||||
"\n",
|
||||
"1. Create a custom TorchServe handler.\n",
|
||||
"1. Upload the model artifacts onto Cloud Storage.\n",
|
||||
"2. Create a Vertex AI model with the model artifacts and a prebuilt PyTorch container image.\n",
|
||||
"3. Deploy the Vertex AI model onto an endpoint."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "eafbb0e0-40e6-43a0-a38e-edc54323da51"
|
||||
},
|
||||
"source": [
|
||||
"### Create the custom TorchServe handler\n",
|
||||
"\n",
|
||||
"The model deployed to Vertex AI uses [TorchServe](https://pytorch.org/serve/) to handle requests and return responses from the model. You must create a custom TorchServe handler to include in with the model artifacts uploaded to Vertex AI.\n",
|
||||
"\n",
|
||||
"The handler file should be included in the directory with the other model artifacts."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "94567a87-9d74-4c87-a749-306ddaf01b61"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%%writefile model_artifacts/handler.py\n",
|
||||
"\n",
|
||||
"\"\"\"Customized handler for Stable Diffusion 1.5.\"\"\"\n",
|
||||
"import base64\n",
|
||||
"import logging\n",
|
||||
"from io import BytesIO\n",
|
||||
"\n",
|
||||
"import torch\n",
|
||||
"from diffusers import EulerDiscreteScheduler\n",
|
||||
"from diffusers import StableDiffusionPipeline\n",
|
||||
"from ts.torch_handler.base_handler import BaseHandler\n",
|
||||
"\n",
|
||||
"logger = logging.getLogger(__name__)\n",
|
||||
"model_id = 'runwayml/stable-diffusion-v1-5'\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class ModelHandler(BaseHandler):\n",
|
||||
"\n",
|
||||
" def __init__(self):\n",
|
||||
" self.initialized = False\n",
|
||||
" self.map_location = None\n",
|
||||
" self.device = None\n",
|
||||
" self.use_gpu = True\n",
|
||||
" self.store_avg = True\n",
|
||||
" self.pipe = None\n",
|
||||
"\n",
|
||||
" def initialize(self, context):\n",
|
||||
" \"\"\"Initializes the pipe.\"\"\"\n",
|
||||
" properties = context.system_properties\n",
|
||||
" gpu_id = properties.get('gpu_id')\n",
|
||||
"\n",
|
||||
" self.map_location, self.device, self.use_gpu = \\\n",
|
||||
" ('cuda', torch.device('cuda:' + str(gpu_id)),\n",
|
||||
" True) if torch.cuda.is_available() else \\\n",
|
||||
" ('cpu', torch.device('cpu'), False)\n",
|
||||
"\n",
|
||||
" # Use the Euler scheduler here instead\n",
|
||||
" scheduler = EulerDiscreteScheduler.from_pretrained(model_id,\n",
|
||||
" subfolder='scheduler')\n",
|
||||
" pipe = StableDiffusionPipeline.from_pretrained(model_id,\n",
|
||||
" scheduler=scheduler,\n",
|
||||
" torch_dtype=torch.float16)\n",
|
||||
" pipe = pipe.to('cuda')\n",
|
||||
" # Uncomment the following line to reduce the GPU memory usage.\n",
|
||||
" # pipe.enable_attention_slicing()\n",
|
||||
" self.pipe = pipe\n",
|
||||
"\n",
|
||||
" self.initialized = True\n",
|
||||
"\n",
|
||||
" def preprocess(self, requests):\n",
|
||||
" \"\"\"Noting to do here.\"\"\"\n",
|
||||
" logger.info('requests: %s', requests)\n",
|
||||
" return requests\n",
|
||||
"\n",
|
||||
" def inference(self, preprocessed_data, *args, **kwargs):\n",
|
||||
" \"\"\"Run the inference.\"\"\"\n",
|
||||
" images = []\n",
|
||||
" for pd in preprocessed_data:\n",
|
||||
" prompt = pd['prompt']\n",
|
||||
" images.extend(self.pipe(prompt).images)\n",
|
||||
" return images\n",
|
||||
"\n",
|
||||
" def postprocess(self, output_batch):\n",
|
||||
" \"\"\"Converts the images to base64 string.\"\"\"\n",
|
||||
" postprocessed_data = []\n",
|
||||
" for op in output_batch:\n",
|
||||
" fp = BytesIO()\n",
|
||||
" op.save(fp, format='JPEG')\n",
|
||||
" postprocessed_data.append(base64.b64encode(fp.getvalue()).decode('utf-8'))\n",
|
||||
" fp.close()\n",
|
||||
" return postprocessed_data\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "6ace1dac0af0"
|
||||
},
|
||||
"source": [
|
||||
"After creating the handler file, you must package the handler as a model archiver (MAR) file. The output file must be named 'model.mar'."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "67707f95d440"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!torch-model-archiver \\\n",
|
||||
" -f \\\n",
|
||||
" --model-name model \\\n",
|
||||
" --version 1.0 \\\n",
|
||||
" --handler model_artifacts/handler.py \\\n",
|
||||
" --export-path model_artifacts"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "ffab030f4bc8"
|
||||
},
|
||||
"source": [
|
||||
"### Upload the model artifacts to Cloud Storage\n",
|
||||
"\n",
|
||||
"Create a new folder in your Cloud Storage bucket to hold the model artifacts"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "MzGDU7TWdts_"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"BUCKET_NAME = \"your-bucket-name-unique\" # @param {type:\"string\"}\n",
|
||||
"BUCKET_URI = f\"gs://{BUCKET_NAME}/\"\n",
|
||||
"FULL_GCS_PATH = f\"{BUCKET_URI}model_artifacts\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "-EcIXiGsCePi"
|
||||
},
|
||||
"source": [
|
||||
"**Only if your bucket doesn't already exist**: Run the following cell to create your Cloud Storage bucket."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "NIq7R4HZCfIc"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"! gsutil mb -l $REGION -p $PROJECT_ID $BUCKET_URI"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "971232e28657"
|
||||
},
|
||||
"source": [
|
||||
"Next, upload the model archive file and your trained Stable Diffusion 1.5 model to the folder on Cloud Storage."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "ef6baf44c808"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!gsutil cp -r model_artifacts $BUCKET_URI"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "402370ca9396"
|
||||
},
|
||||
"source": [
|
||||
"### Create the Vertex AI model\n",
|
||||
"\n",
|
||||
"Once you've uploaded the model artifacts into a Cloud Storage bucket, you can create a new Vertex AI model. This notebook uses the [Vertex AI SDK](https://cloud.google.com/vertex-ai/docs/start/use-vertex-ai-python-sdk) to create the model."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "b6c58a74a0fd"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"PYTORCH_PREDICTION_IMAGE_URI = (\n",
|
||||
" \"us-docker.pkg.dev/vertex-ai/prediction/pytorch-gpu.1-12:latest\"\n",
|
||||
")\n",
|
||||
"APP_NAME = \"my-stable-diffusion\"\n",
|
||||
"VERSION = 1\n",
|
||||
"MODEL_DISPLAY_NAME = \"stable_diffusion_1_5-unique\"\n",
|
||||
"MODEL_DESCRIPTION = \"stable_diffusion_1_5 container\"\n",
|
||||
"ENDPOINT_DISPLAY_NAME = f\"{APP_NAME}-endpoint\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "07c3503a1a2e"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"aiplatform.init(project=PROJECT_ID, location=REGION, staging_bucket=BUCKET_NAME)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "FAPoU8Sm5E6e"
|
||||
},
|
||||
"source": [
|
||||
"<div style=\"background:#e3effe; padding:5px; color:#0000aa\">\n",
|
||||
"<strong>Note:</strong> The next cell fails if you haven't <a href=\"https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com\"><u>enabled the Vertex API</u></a>.</div>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "a776324dd16f"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"model = aiplatform.Model.upload(\n",
|
||||
" display_name=MODEL_DISPLAY_NAME,\n",
|
||||
" description=MODEL_DESCRIPTION,\n",
|
||||
" serving_container_image_uri=PYTORCH_PREDICTION_IMAGE_URI,\n",
|
||||
" artifact_uri=FULL_GCS_PATH,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"model.wait()\n",
|
||||
"\n",
|
||||
"print(model.display_name)\n",
|
||||
"print(model.resource_name)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "0fbc3d371574"
|
||||
},
|
||||
"source": [
|
||||
"### Deploy the model to an endpoint\n",
|
||||
"\n",
|
||||
"To get online preductions from your Stable Diffusion 2.0 model, you must [deploy it to a Vertex AI endpoint](https://cloud.google.com/vertex-ai/docs/predictions/overview). You can again use the Vertex AI SDK to create the endpoint and deploy your model."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "ab29f0a770cb"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"endpoint = aiplatform.Endpoint.create(display_name=ENDPOINT_DISPLAY_NAME)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "25f703df88c7"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"model.deploy(\n",
|
||||
" endpoint=endpoint,\n",
|
||||
" deployed_model_display_name=MODEL_DISPLAY_NAME,\n",
|
||||
" machine_type=\"n1-standard-8\",\n",
|
||||
" accelerator_type=\"NVIDIA_TESLA_P100\",\n",
|
||||
" accelerator_count=1,\n",
|
||||
" traffic_percentage=100,\n",
|
||||
" deploy_request_timeout=1200,\n",
|
||||
" sync=True,\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "c9fc560df0a9"
|
||||
},
|
||||
"source": [
|
||||
"The previous cell, which deploys your model to the endpoint, can take a while to complete. If the previous cell times out before returning, your endpoint might still be successfully deployed to an endpoint. Check the [Cloud Console](https://console.cloud.google.com/vertex-ai/endpoints) to verify the results.\n",
|
||||
"\n",
|
||||
"You can also extend the time to wait for deployment by changing the `deploy_request_timeout` argument passed to `model.deploy()`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "88a5304dfdc9"
|
||||
},
|
||||
"source": [
|
||||
"## Get online predictions\n",
|
||||
"\n",
|
||||
"Finally, with your Stable Diffusion 1.5 model deployed to a Vertex AI endpoint, you can now get online predictions from it. Using the Vertex AI SDK, you only need a few lines of code to get an inference."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "0d6bc4aa34d6"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"instances = [{\"prompt\": \"An examplePup dog with a baseball jersey.\"}]\n",
|
||||
"response = endpoint.predict(instances=instances)\n",
|
||||
"\n",
|
||||
"with open(\"img5.jpg\", \"wb\") as g:\n",
|
||||
" g.write(base64.b64decode(response.predictions[0]))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "65bafefda60c"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"display.Image(\"img5.jpg\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "TpV-iwP9qw9c"
|
||||
},
|
||||
"source": [
|
||||
"## Cleaning up\n",
|
||||
"\n",
|
||||
"To clean up all Google Cloud resources used in this project, you can [delete the Google Cloud\n",
|
||||
"project](https://cloud.google.com/resource-manager/docs/creating-managing-projects#shutting_down_projects) you used for the tutorial.\n",
|
||||
"\n",
|
||||
"Otherwise, you can delete the individual resources you created in this tutorial:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "sx_vKniMq9ZX"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"\n",
|
||||
"# Delete endpoint resource\n",
|
||||
"endpoint.undeploy_all()\n",
|
||||
"endpoint.delete()\n",
|
||||
"\n",
|
||||
"# Delete model resource\n",
|
||||
"model.delete()\n",
|
||||
"\n",
|
||||
"# Delete Cloud Storage objects that were created\n",
|
||||
"delete_bucket = False\n",
|
||||
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
|
||||
" ! gsutil -m rm -r $BUCKET_URI"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"colab": {
|
||||
"name": "dreambooth_stablediffusion.ipynb",
|
||||
"toc_visible": true
|
||||
},
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"name": "python3"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 0
|
||||
}
|
||||
@@ -74,7 +74,9 @@
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"{TODO: Include a paragraph or two explaining what this example demonstrates, who should be interested in it, and what you need to know before you get started.}"
|
||||
"{TODO: Include a paragraph or two explaining what this example demonstrates, who should be interested in it, and what you need to know before you get started.}\n",
|
||||
"\n",
|
||||
"Learn more about [web-doc-title](linkback-to-webdoc-page). {TODO: if more than one primary feature, add tag/linkback for each one}"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -12,6 +12,10 @@
|
||||
--errors-codes: A list of error codes to report errors. Otherwise, all errors are reported.
|
||||
--errors-csv: Report errors in CSV format
|
||||
|
||||
# options for automatic fixing
|
||||
--fix: Automatic fix
|
||||
--fix-codes: A list of fix codes to fix. Otherwise, all fix codes are enabled.
|
||||
|
||||
# index generatation
|
||||
--repo: Generate index in markdown format
|
||||
--web: Generate index in HTML format
|
||||
@@ -19,6 +23,7 @@
|
||||
--desc: Add description to index
|
||||
--steps: Add steps to index
|
||||
--uses: Add "resources" used to index
|
||||
--linkback: Add linkback to index
|
||||
|
||||
Format of CSV file for notebooks to review:
|
||||
|
||||
@@ -61,6 +66,8 @@ parser.add_argument('--uses', dest='uses', action='store_true',
|
||||
default=False, help='Output uses (resources)')
|
||||
parser.add_argument('--steps', dest='steps', action='store_true',
|
||||
default=False, help='Ouput steps')
|
||||
parser.add_argument('--linkback', dest='linkback', action='store_true',
|
||||
default=False, help='Ouput linkback')
|
||||
parser.add_argument('--web', dest='web', action='store_true',
|
||||
default=False, help='Output format in HTML')
|
||||
parser.add_argument('--repo', dest='repo', action='store_true',
|
||||
@@ -109,13 +116,14 @@ class ErrorCode(Enum):
|
||||
# Costs cell required
|
||||
# Check for required Vertex and optional BQ and Dataflow
|
||||
ERROR_OVERVIEW_NOTFOUND = 10,
|
||||
ERROR_OBJECTIVE_NOTFOUND = 11,
|
||||
ERROR_OBJECTIVE_MISSING_DESC = 12,
|
||||
ERROR_OBJECTIVE_MISSING_USES = 13,
|
||||
ERROR_OBJECTIVE_MISSING_STEPS = 14,
|
||||
ERROR_DATASET_NOTFOUND = 15,
|
||||
ERROR_COSTS_NOTFOUND = 16,
|
||||
ERROR_COSTS_MISSING = 17,
|
||||
ERROR_LINKBACK_NOTFOUND = 11,
|
||||
ERROR_OBJECTIVE_NOTFOUND = 12,
|
||||
ERROR_OBJECTIVE_MISSING_DESC = 13,
|
||||
ERROR_OBJECTIVE_MISSING_USES = 14,
|
||||
ERROR_OBJECTIVE_MISSING_STEPS = 15,
|
||||
ERROR_DATASET_NOTFOUND = 16,
|
||||
ERROR_COSTS_NOTFOUND = 17,
|
||||
ERROR_COSTS_MISSING = 18,
|
||||
|
||||
# Installation cell
|
||||
# Installation cell required
|
||||
@@ -126,34 +134,34 @@ class ErrorCode(Enum):
|
||||
# option {USER_FLAG} required
|
||||
# installation code cell not match template
|
||||
# all packages must be installed as a single pip3
|
||||
ERROR_INSTALLATION_NOTFOUND = 18,
|
||||
ERROR_INSTALLATION_HEADING = 19,
|
||||
ERROR_INSTALLATION_CODE_NOTFOUND = 20,
|
||||
ERROR_INSTALLATION_PIP3 = 21,
|
||||
ERROR_INSTALLATION_QUIET = 22,
|
||||
ERROR_INSTALLATION_USER_FLAG = 23,
|
||||
ERROR_INSTALLATION_CODE_TEMPLATE = 24,
|
||||
ERROR_INSTALLATION_SINGLE_PIP3 = 25,
|
||||
ERROR_INSTALLATION_NOTFOUND = 19,
|
||||
ERROR_INSTALLATION_HEADING = 20,
|
||||
ERROR_INSTALLATION_CODE_NOTFOUND = 21,
|
||||
ERROR_INSTALLATION_PIP3 = 22,
|
||||
ERROR_INSTALLATION_QUIET = 23,
|
||||
ERROR_INSTALLATION_USER_FLAG = 24,
|
||||
ERROR_INSTALLATION_CODE_TEMPLATE = 25,
|
||||
ERROR_INSTALLATION_SINGLE_PIP3 = 26,
|
||||
|
||||
# Restart kernel cell
|
||||
# Restart code cell required
|
||||
# Restart code cell not found
|
||||
ERROR_RESTART_NOTFOUND = 23,
|
||||
ERROR_RESTART_CODE_NOTFOUND = 24,
|
||||
ERROR_RESTART_NOTFOUND = 27,
|
||||
ERROR_RESTART_CODE_NOTFOUND = 28,
|
||||
|
||||
# Before you begin cell
|
||||
# Before you begin cell required
|
||||
# Before you begin cell incomplete
|
||||
ERROR_BEFOREBEGIN_NOTFOUND = 25,
|
||||
ERROR_BEFOREBEGIN_INCOMPLETE = 26,
|
||||
ERROR_BEFOREBEGIN_NOTFOUND = 29,
|
||||
ERROR_BEFOREBEGIN_INCOMPLETE = 30,
|
||||
|
||||
# Set Project ID
|
||||
# Set project ID cell required
|
||||
# Set project ID code cell not found
|
||||
# Set project ID not match template
|
||||
ERROR_PROJECTID_NOTFOUND = 27,
|
||||
ERROR_PROJECTID_CODE_NOTFOUND = 28,
|
||||
ERROR_PROJECTID_TEMPLATE = 29,
|
||||
ERROR_PROJECTID_NOTFOUND = 31,
|
||||
ERROR_PROJECTID_CODE_NOTFOUND = 32,
|
||||
ERROR_PROJECTID_TEMPLATE = 33,
|
||||
|
||||
# Technical Writer Rules
|
||||
ERROR_TWRULE_TODO = 51,
|
||||
@@ -182,7 +190,21 @@ def parse_dir(directory: str) -> int:
|
||||
"""
|
||||
exit_code = 0
|
||||
|
||||
sorted_entries = []
|
||||
entries = os.scandir(directory)
|
||||
for entry in entries:
|
||||
|
||||
inserted = False
|
||||
for ix in range(len(sorted_entries)):
|
||||
if entry.name < sorted_entries[ix].name:
|
||||
sorted_entries.insert(ix, entry)
|
||||
inserted = True
|
||||
break
|
||||
|
||||
if not inserted:
|
||||
sorted_entries.append(entry)
|
||||
|
||||
entries = sorted_entries
|
||||
for entry in entries:
|
||||
if entry.is_dir():
|
||||
if entry.name[0] == '.':
|
||||
@@ -191,13 +213,65 @@ def parse_dir(directory: str) -> int:
|
||||
continue
|
||||
exit_code += parse_dir(entry.path)
|
||||
elif entry.name.endswith('.ipynb'):
|
||||
exit_code += parse_notebook(entry.path, tag=directory.split('/')[-1], linkback=None, rules=rules)
|
||||
tag = directory.split('/')[-1]
|
||||
if tag == 'automl':
|
||||
tag = 'AutoML'
|
||||
elif tag == 'bigquery_ml':
|
||||
tag = 'BigQuery ML'
|
||||
elif tag == 'custom':
|
||||
tag = 'Vertex AI Training'
|
||||
elif tag == 'experiments':
|
||||
tag = 'Vertex AI Experiments'
|
||||
elif tag == 'explainable_ai':
|
||||
tag = 'Vertex Explainable AI'
|
||||
elif tag == 'feature_store':
|
||||
tag = 'Vertex AI Feature Store'
|
||||
elif tag == 'matching_engine':
|
||||
tag = 'Vertex AI Matching Engine'
|
||||
elif tag == 'migration':
|
||||
tag = 'CAIP to Vertex AI migration'
|
||||
elif tag == 'ml_metadata':
|
||||
tag = 'Vertex ML Metadata'
|
||||
elif tag == 'model_evaluation':
|
||||
tag = 'Vertex AI Model Evaluation'
|
||||
elif tag == 'model_monitoring':
|
||||
tag = 'Vertex AI Model Monitoring'
|
||||
elif tag == 'model_registry':
|
||||
tag = 'Vertex AI Model Registry'
|
||||
elif tag == 'pipelines':
|
||||
tag = 'Vertex AI Pipelines'
|
||||
elif tag == 'prediction':
|
||||
tag = 'Vertex AI Prediction'
|
||||
elif tag == 'pytorch':
|
||||
tag = 'Vertex AI Training'
|
||||
elif tag == 'reduction_server':
|
||||
tag = 'Vertex AI Reduction Server'
|
||||
elif tag == 'sdk':
|
||||
tag = 'Vertex AI SDK'
|
||||
elif tag == 'structured_data':
|
||||
tag = 'AutoML / BQML'
|
||||
elif tag == 'tabnet':
|
||||
tag = 'Vertex AI TabNet'
|
||||
elif tag == 'tabular_workflows':
|
||||
tag = 'AutoML Tabular Workflows'
|
||||
elif tag == 'tensorboard':
|
||||
tag = 'Vertex AI TensorBoard'
|
||||
elif tag == 'training':
|
||||
tag = 'Vertex AI Training'
|
||||
elif tag == 'vizier':
|
||||
tag = 'Vertex AI Vizier'
|
||||
|
||||
# special case
|
||||
if 'workbench' in directory:
|
||||
tag = 'Vertex AI Workbench'
|
||||
|
||||
exit_code += parse_notebook(entry.path, tags=[tag], linkback=None, rules=rules)
|
||||
|
||||
return exit_code
|
||||
|
||||
|
||||
def parse_notebook(path: str,
|
||||
tag: str,
|
||||
tags: List,
|
||||
linkback: str,
|
||||
rules: List) -> int:
|
||||
"""
|
||||
@@ -205,8 +279,9 @@ def parse_notebook(path: str,
|
||||
and notebook authoring requirements.
|
||||
|
||||
path: The path to the notebook.
|
||||
tag: The associated tag
|
||||
tags: The associated tags
|
||||
linkback: A link back to the web docs
|
||||
rules: The cell rules to apply
|
||||
|
||||
Returns the number of errors
|
||||
"""
|
||||
@@ -218,9 +293,20 @@ def parse_notebook(path: str,
|
||||
|
||||
# Automatic Index Generation
|
||||
if objective.desc != '':
|
||||
if overview.linkbacks:
|
||||
linkbacks = overview.linkbacks
|
||||
else:
|
||||
if linkback:
|
||||
linkbacks = [linkback]
|
||||
else:
|
||||
linkbacks = []
|
||||
|
||||
if overview.tags:
|
||||
tags = overview.tags
|
||||
|
||||
add_index(path,
|
||||
tag,
|
||||
linkback,
|
||||
tags,
|
||||
linkbacks,
|
||||
title.title,
|
||||
objective.desc,
|
||||
objective.uses,
|
||||
@@ -512,9 +598,23 @@ class OverviewRule(NotebookRule):
|
||||
"""
|
||||
Parse the overview cell
|
||||
"""
|
||||
self.linkbacks = []
|
||||
self.tags = []
|
||||
|
||||
cell = notebook.get()
|
||||
if not cell['source'][0].startswith("## Overview"):
|
||||
return notebook.report_error(ErrorCode.ERROR_OVERVIEW_NOTFOUND, "Overview section not found")
|
||||
|
||||
last_line = cell['source'][-1]
|
||||
if last_line.startswith('Learn more about ['):
|
||||
for more in last_line.split('[')[1:]:
|
||||
tag = more.split(']')[0]
|
||||
linkback = more.split('(')[1].split(')')[0]
|
||||
self.tags.append(tag)
|
||||
self.linkbacks.append(linkback)
|
||||
else:
|
||||
return notebook.report_error(ErrorCode.ERROR_LINKBACK_NOTFOUND, "Linkback missing in overview section")
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -542,6 +642,10 @@ class ObjectiveRule(NotebookRule):
|
||||
in_steps = False
|
||||
|
||||
for line in cell['source'][1:]:
|
||||
# TOC anchor
|
||||
if line.startswith('<a name='):
|
||||
continue
|
||||
|
||||
if line.startswith('This tutorial uses'):
|
||||
in_desc = False
|
||||
in_steps = False
|
||||
@@ -578,16 +682,39 @@ class ObjectiveRule(NotebookRule):
|
||||
# check for italic font setting
|
||||
if ch == '*' and sline[1] != ' ':
|
||||
in_steps = False
|
||||
# special case
|
||||
elif sline.startswith('* Prediction Service'):
|
||||
in_steps = False
|
||||
else:
|
||||
self.steps += line
|
||||
elif ch == '#':
|
||||
in_steps = False
|
||||
|
||||
|
||||
if self.desc == '':
|
||||
ret = notebook.report_error(ErrorCode.ERROR_OBJECTIVE_MISSING_DESC, "Objective section missing desc")
|
||||
else:
|
||||
self.desc = self.desc.lstrip()
|
||||
sentences = self.desc.split('.')
|
||||
|
||||
bracket = False
|
||||
paren = False
|
||||
sentences = ""
|
||||
for _ in range(len(self.desc)):
|
||||
if self.desc[_] == '[':
|
||||
bracket = True
|
||||
continue
|
||||
elif self.desc[_] == ']':
|
||||
bracket = False
|
||||
continue
|
||||
elif self.desc[_] == '(':
|
||||
paren = True
|
||||
elif self.desc[_] == ')':
|
||||
paren = False
|
||||
continue
|
||||
|
||||
if not paren:
|
||||
sentences += self.desc[_]
|
||||
sentences = sentences.split('.')
|
||||
if len(sentences) > 1:
|
||||
self.desc = sentences[0] + '.\n'
|
||||
if self.desc.startswith('In this tutorial, you learn') or self.desc.startswith('In this notebook, you learn'):
|
||||
@@ -607,7 +734,7 @@ class ObjectiveRule(NotebookRule):
|
||||
ret = notebook.report_error(ErrorCode.ERROR_OBJECTIVE_MISSING_STEPS, "Objective section missing steps list")
|
||||
|
||||
notebook.costs = self.costs
|
||||
ret = True
|
||||
return ret
|
||||
|
||||
|
||||
class RecommendationsRule(NotebookRule):
|
||||
@@ -972,8 +1099,8 @@ class TextTWRule(TextRule):
|
||||
|
||||
|
||||
def add_index(path: str,
|
||||
tag: str,
|
||||
linkback: str,
|
||||
tags: List,
|
||||
linkbacks: List,
|
||||
title : str,
|
||||
desc: str,
|
||||
uses: str,
|
||||
@@ -986,15 +1113,15 @@ def add_index(path: str,
|
||||
Add a discoverability index for this notebook
|
||||
|
||||
path: The path to the notebook
|
||||
tag: The tag (if any) for the notebook
|
||||
tags: The tags (if any) for the notebook
|
||||
title: The H1 title for the notebook
|
||||
desc:
|
||||
uses:
|
||||
steps:
|
||||
git_link:
|
||||
colab_link:
|
||||
workbench_link:
|
||||
linkback:
|
||||
desc: The notebook description
|
||||
uses: The resources/services used by the notebook
|
||||
steps: The steps specified by the notebook
|
||||
git_link: The link to the notebook in the git repo
|
||||
colab_link: Link to launch notebook in Colab
|
||||
workbench_link: Link to launch notebook in Workbench
|
||||
linkbacks: The linkbacks per tag
|
||||
"""
|
||||
global last_tag
|
||||
|
||||
@@ -1004,43 +1131,65 @@ def add_index(path: str,
|
||||
title = title.split(':')[-1].strip()
|
||||
title = title[0].upper() + title[1:]
|
||||
if args.web:
|
||||
title = title.replace('`', '')
|
||||
title = replace_cl(title.replace('`', ''))
|
||||
|
||||
print(' <tr>')
|
||||
print(' <td>')
|
||||
tags = tag.split(',')
|
||||
for tag in tags:
|
||||
tag = replace_cl(tag)
|
||||
print(f' {tag.strip()}<br/>\n')
|
||||
print(' </td>')
|
||||
print(' <td>')
|
||||
print(f' {title}<br/>\n')
|
||||
print(f' <b>{title}</b>. ')
|
||||
if args.desc:
|
||||
desc = desc.replace('`', '')
|
||||
print(f' {desc}<br/>\n')
|
||||
if linkback:
|
||||
text = ''
|
||||
for tag in tags:
|
||||
text += tag.strip() + ' '
|
||||
|
||||
print(f' Learn more about <a src="https://cloud.google.com/{linkback}">{text}</a><br/>\n')
|
||||
desc = replace_cl(desc.replace('`', ''))
|
||||
print('<br/>')
|
||||
print(f' {desc}\n')
|
||||
|
||||
|
||||
if args.linkback and linkbacks:
|
||||
num = len(tags)
|
||||
for _ in range(num):
|
||||
if linkbacks[_].startswith("vertex-ai"):
|
||||
print(f' Learn more about <a href="https://cloud.google.com/{linkbacks[_]}" target="_blank">{replace_cl(tags[_])}</a>.\n')
|
||||
else:
|
||||
print(f' Learn more about <a href="{linkbacks[_]}" target="_blank">{replace_cl(tags[_])}</a>.\n')
|
||||
|
||||
if args.steps:
|
||||
print("<devsite-expandable>\n")
|
||||
print(' <p class="showalways">Tutorial steps</p>\n')
|
||||
print(' <ul>\n')
|
||||
|
||||
if ":" in steps:
|
||||
steps = steps.split(':')[1].replace('*', '').replace('-', '').strip().split('\n')
|
||||
else:
|
||||
steps = []
|
||||
|
||||
for step in steps:
|
||||
print(f' <li>{replace_cl(step)}</li>\n')
|
||||
print(' </ul>\n')
|
||||
print("</devsite-expandable>\n")
|
||||
|
||||
print(' </td>')
|
||||
print(' <td>')
|
||||
if colab_link:
|
||||
print(f' <a src="{colab_link}">Colab</a><br/>\n')
|
||||
print(f' <a href="{colab_link}" target="_blank" class="external" track-type="notebookTutorial" track-name="colabLink">Colab</a><br/>\n')
|
||||
if git_link:
|
||||
print(f' <a src="{git_link}">GitHub</a><br/>\n')
|
||||
print(f' <a href="{git_link}" target="_blank" class="external" track-type="notebookTutorial" track-name="gitHubLink">GitHub</a><br/>\n')
|
||||
if workbench_link:
|
||||
print(f' <a src="{workbench_link}">Vertex AI Workbench</a><br/>\n')
|
||||
print(f' <a href="{workbench_link}" target="_blank" class="external" track-type="notebookTutorial" track-name="workbenchLink">Vertex AI Workbench</a><br/>\n')
|
||||
print(' </td>')
|
||||
print(' </tr>\n')
|
||||
elif args.repo:
|
||||
tags = tag.split(',')
|
||||
if tags != last_tag and tag != '':
|
||||
last_tag = tags
|
||||
flat_list = ''
|
||||
for item in tags:
|
||||
flat_list += item.replace("'", '') + ' '
|
||||
print(f"\n### {flat_list}\n")
|
||||
try:
|
||||
if tags != last_tag and tag != '':
|
||||
last_tag = tags
|
||||
flat_list = ''
|
||||
for item in tags:
|
||||
flat_list += item.replace("'", '') + ' '
|
||||
print(f"\n### {flat_list}\n")
|
||||
except:
|
||||
pass
|
||||
print(f"\n[{title}]({git_link})\n")
|
||||
|
||||
print("```")
|
||||
@@ -1052,7 +1201,84 @@ def add_index(path: str,
|
||||
|
||||
if args.steps:
|
||||
print(steps.rstrip() + '\n')
|
||||
|
||||
print("```\n")
|
||||
|
||||
if args.linkback and linkbacks:
|
||||
num = len(tags)
|
||||
for _ in range(num):
|
||||
if linkbacks[_].startswith("vertex-ai"):
|
||||
print(f' Learn more about [{tags[_]}]({linkbacks[_]}).\n')
|
||||
else:
|
||||
print(f' Learn more about [{tags[_]}]({linkbacks[_]}).\n')
|
||||
|
||||
def replace_cl(text : str ) -> str:
|
||||
'''
|
||||
Replace product names with CL substitution variables
|
||||
'''
|
||||
substitutions = {
|
||||
#'AutoML Tabular Workflow': '{{automl_name}} Tabular Workflow',
|
||||
#'AutoML Tables': '{{automl_tables_name}}',
|
||||
#'AutoML Tabular': '{{automl_tables_name}}',
|
||||
#'AutoML Vision': '{automl_vision_name}}',
|
||||
#'AutoML Image': '{automl_vision_name}}',
|
||||
'AutoML': '{{automl_name}}',
|
||||
|
||||
'BigQuery ML': '{{bigqueryml_name}}',
|
||||
'BQML': '{{bigqueryml_name}}',
|
||||
'BigQuery': '{{bigquery_name}}',
|
||||
'BQ': '{{bigquery_name}}',
|
||||
|
||||
'Vertex Dataset': '{{vertex_ai_name}} Dataset',
|
||||
'Vertex Model': '{{vertex_ai_name}} Model',
|
||||
'Vertex Endpoint': '{{vertex_ai_name}} Endpoint',
|
||||
'Vertex Model Registry': '{{vertex_model_registry_name}}',
|
||||
'Vertex AI Model Registry': '{{vertex_model_registry_name}}',
|
||||
'Vertex Training': '{{vertex_training_name}}',
|
||||
'Vertex AI Training': '{{vertex_training_name}}',
|
||||
'Vertex Prediction': '{{vertex_prediction_name}}',
|
||||
'Vertex AI Prediction': '{{vertex_prediction_name}}',
|
||||
'Vertex TensorBoard': '{{vertex_tensorboard_name}}',
|
||||
'Vertex AI TensorBoard': '{{vertex_tensorboard_name}}',
|
||||
'TensorBoard': '{{vertex_tensorboard_name}}',
|
||||
'Tensorboard': '{{vertex_tensorboard_name}}',
|
||||
'Vertex ML Metadata': '{{vertex_metadata_name}}',
|
||||
'Vertex Pipelines': '{{vertex_pipelines_name}}',
|
||||
'Vertex AI Pipelines': '{{vertex_pipelines_name}}',
|
||||
'Vertex AI Data Labeling': '{{vertex_data_labeling_name}}',
|
||||
'Vertex AI Experiments': '{{vertex_experiments_name}}',
|
||||
'Vertex Experiments': '{{vertex_experiments_name}}',
|
||||
'Vertex AI Matching Engine': '{{vertex_matching_engine_name}}',
|
||||
'Vertex Matching Engine': '{{vertex_matching_engine_name}}',
|
||||
'Vertex Model Monitoring': '{{vertex_model_monitoring_name}}',
|
||||
'Vertex AI Model Monitoring': '{{vertex_model_monitoring_name}}',
|
||||
'Vertex Feature Store': '{{vertex_featurestore_name}}',
|
||||
'Vertex AI Feature Store': '{{vertex_featurestore_name}}',
|
||||
'Vertex Vizier': '{{vertex_vizier_name}}',
|
||||
'Vertex AI Vizier': '{{vertex_vizier_name}}',
|
||||
'Vertex Explainable AI': '{{vertex_xai_name}}',
|
||||
'NAS': '{{vertex_nas_name}',
|
||||
'Vertex AI Neural Architectural Search': '{{vertex_nas_name}}',
|
||||
'Vertex Workbench': '{{vertex_workbench_name}}',
|
||||
'Vertex AI Workbench': '{{vertex_workbench_name}}',
|
||||
'Vertex AI Edge Manager': '{{vertex_edge_manager_name}}',
|
||||
'Vertex SDK': '{{vertex_sdk_name}}',
|
||||
'Vertex AI SDK': '{{vertex_sdk_name}}',
|
||||
'Vertex AI': '{{vertex_ai_name}}',
|
||||
|
||||
'Cloud Storage': '{{storage_name}}',
|
||||
'GCS': '{{storage_name}}',
|
||||
'GCP': '{{gcp_name}}',
|
||||
'TensorFlow Enterprise': '{{tf4gcp_name}}',
|
||||
'TensorFlow': '{{tensorflow_name}}',
|
||||
}
|
||||
|
||||
for key, value in substitutions.items():
|
||||
if key in text:
|
||||
text = text.replace(key, value)
|
||||
|
||||
return text
|
||||
|
||||
|
||||
|
||||
# Instantiate the rules
|
||||
@@ -1084,21 +1310,32 @@ rules = [ copyright, notices, title, links, testenv, table, overview, objective,
|
||||
]
|
||||
|
||||
if args.web:
|
||||
print('<style>')
|
||||
print('table, th, td {')
|
||||
print(' border: 1px solid black;')
|
||||
print(' padding-left:10px')
|
||||
print('}')
|
||||
print('</style>')
|
||||
print('<table>')
|
||||
print(' <th>Vertex AI Feature</th>')
|
||||
print(' <th>Description</th>')
|
||||
print(' <th>Open in</th>')
|
||||
print(' <thead>')
|
||||
print(' <tr>')
|
||||
print(' <th width="180px">Services</th>')
|
||||
print(' <th>Description</th>')
|
||||
print(' <th width="80px">Open in</th>')
|
||||
print(' </tr>')
|
||||
print(' </thead>')
|
||||
print(' <tbody class="list">')
|
||||
|
||||
if args.notebook_dir:
|
||||
if not os.path.isdir(args.notebook_dir):
|
||||
print("Error: not a directory:", args.notebook_dir)
|
||||
print(f"Error: not a directory: {args.notebook_dir}", file=sys.stderr)
|
||||
exit(1)
|
||||
exit_code = parse_dir(args.notebook_dir)
|
||||
elif args.notebook:
|
||||
if not os.path.isfile(args.notebook):
|
||||
print("Error: not a notebook:", args.notebook)
|
||||
print(f"Error: not a notebook: {args.notebook}", file=sys.stderr)
|
||||
exit(1)
|
||||
exit_code = parse_notebook(args.notebook, tag='', linkback=None, rules=rules)
|
||||
exit_code = parse_notebook(args.notebook, tags=[], linkback=None, rules=rules)
|
||||
elif args.notebook_file:
|
||||
if not os.path.isfile(args.notebook_file):
|
||||
print("Error: file does not exist", args.notebook_file)
|
||||
@@ -1111,18 +1348,19 @@ elif args.notebook_file:
|
||||
if heading:
|
||||
heading = False
|
||||
else:
|
||||
tag = row[0]
|
||||
tags = row[0].split(',')
|
||||
notebook = row[1]
|
||||
try:
|
||||
linkback = row[2]
|
||||
except:
|
||||
linkback = None
|
||||
exit_code += parse_notebook(notebook, tag=tag, linkback=linkback, rules=rules)
|
||||
exit_code += parse_notebook(notebook, tags=tags, linkback=linkback, rules=rules)
|
||||
else:
|
||||
print("Error: must specify a directory or notebook")
|
||||
print("Error: must specify a directory or notebook", file=sys.stderr)
|
||||
exit(1)
|
||||
|
||||
if args.web:
|
||||
print(' </tbody>\n')
|
||||
print('</table>\n')
|
||||
|
||||
exit(exit_code)
|
||||
|
||||
@@ -23,7 +23,62 @@
|
||||
- Incorrect examples: "Let's update the field", "We'll update the field", "The user should update the field"
|
||||
- **Googlers**: Please follow our [branding guidelines](http://goto/cloud-branding).
|
||||
|
||||
### Code
|
||||
|
||||
## Authoring guidelines
|
||||
|
||||
### Focus
|
||||
|
||||
Notebooks for official are expected to be narrow focused, which highlight a subset of features of a Vertex AI product/service.
|
||||
The product/feature is to be highlighted in the Overview section. For example:
|
||||
|
||||
```
|
||||
This tutorial demonstrates using Vertex AI Training to train an XGBoost model using a XGBoost pre-built training container.
|
||||
```
|
||||
|
||||
In the above example, the Vertex AI product/service is `Vertex AI Training` and the feature is `XGBoost pre-built training container`.
|
||||
|
||||
### Scope
|
||||
|
||||
Notebooks for official are expected to be narrow in scope, without extra extraneous steps. For example, if the notebook is about training, we discourage ending the notebook with deploying the model and doing an online/batch prediction. On the later, we recommend a separate notebook about prediction that uses a pretrained model.
|
||||
|
||||
#### Training
|
||||
|
||||
Notebooks for training should be constructed as follows:
|
||||
|
||||
1. If the training script(s) are small, embed them in the notebook and use %writefile to store them locally.
|
||||
2. If the training script(s) are large, store them in our public bucket: gs://cloud-samples-data/vertex-ai/dataset-management/script, and use !wgets to retrieve and store the script locally.
|
||||
3. Train the model using the Vertex AI SDK methods for custom training.
|
||||
4. Preferrable have the service upload the trained model to the Vertex AI Model Registry.
|
||||
4. Have the script do an evaluation.
|
||||
5. Retrieve the evaluation metrics and attach them as an artifact to the corresponding entry in the Model Registry.
|
||||
6. Optionally, download the model artifacts and test locally -- i.e., make a local prediction request.
|
||||
|
||||
#### Evaluation
|
||||
|
||||
Notebooks for evaluation should be constructed as follows:
|
||||
|
||||
1. Use a pretrained model from a public repository.
|
||||
2. Upload the pretrained model to the Vertex AI Model Registry.
|
||||
3. Perform a model evaluation.
|
||||
4. Review the model evaluation.
|
||||
4. Attach the model evaluation to the corresponding entry in the Model Registry.
|
||||
|
||||
#### Prediction
|
||||
|
||||
Notebooks for prediction should be constructed as follows:
|
||||
|
||||
1. Use a pretrained model from a public repository.
|
||||
2. If relevant, attach a serving function to the model artifacts.
|
||||
3. Upload the pretrained model to the Vertex AI Model Registry.
|
||||
4. For online:<br/>
|
||||
A. Deploy the model.<br/>
|
||||
B. Perform an online prediction.</br>
|
||||
C. Review the result.
|
||||
5. For batch:<br/>
|
||||
A. Perform a batch prediction.</br/>
|
||||
B. Review the result.
|
||||
|
||||
## Code
|
||||
|
||||
- Put all your installs and imports in a setup section.
|
||||
- Save the notebook with the Table of Contents open.
|
||||
@@ -31,7 +86,7 @@
|
||||
- Follow the [Google Python Style guide](https://github.com/google/styleguide/blob/gh-pages/pyguide.md) and write readable code.
|
||||
- Keep cells small (max ~20 lines).
|
||||
|
||||
## TensorFlow code style
|
||||
### TensorFlow code style
|
||||
|
||||
Use the highest level API that gets the job done (unless the goal is to demonstrate the low level API). For example, when using Tensorflow:
|
||||
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
tag,notebook,doc
|
||||
"AutoML, Text data",official/automl/automl-text-classification.ipynb,vertex-ai/docs/text-data/classification/train-model
|
||||
"AutoML, Text data",official/automl/sdk_automl_text_entity_extraction_online.ipynb,
|
||||
"AutoML, Text data",official/automl/sdk_automl_text_sentiment_analysis_online.ipynb,
|
||||
"AutoML, Tabular data",official/automl/sdk_automl_tabular_forecasting_batch.ipynb,vertex-ai/docs/tabular-data/forecasting/tutorials-samples
|
||||
"AutoML, Tabular Data",official/automl/automl_tabular_on_vertex_pipelines.ipynb,vertex-ai/docs/tabular-data/tabular-workflows/e2e-automl
|
||||
"AutoML, Tabular Data",official/automl/sdk_automl_tabular_regression_batch_bq.ipynb,
|
||||
"AutoML, Tabular Data",official/automl/sdk_automl_tabular_regression_batch_bq.ipynb,
|
||||
"AutoML, Forecasting",official/automl/automl_forecasting_bqml_arima_plus_comparison.ipynb,vertex-ai/docs/tabular-data/forecasting-arima/overview
|
||||
"AutoML, Forecasting",official/automl/sdk_automl_tabular_forecasting_batch.ipynb,
|
||||
"AutoML, Image data",official/automl/sdk_automl_text_sentiment_analysis_online.ipynb,
|
||||
"AutoML, Video data",official/automl/sdk_automl_text_sentiment_analysis_online.ipynb,
|
||||
"AutoML, Video data",official/automl/sdk_automl_video_classification_batch.ipynb,
|
||||
"AutoML, Video data",official/automl/sdk_automl_video_object_tracking_batch.ipynb,
|
||||
"AutoML, Video data",official/sdk/SDK_AutoML_Video_Classification.ipynb,
|
||||
"BigQuery, Vertex AI Workbench",official/workbench/exploratory_data_analysis/explore_data_in_bigquery_with_workbench.ipynb,
|
||||
"BigQuery ML, Vertex AI Model Registry, Batch prediction",official/model_registry/bqml_vertexai_model_registry.ipynb,
|
||||
"BigQuery ML, Vertex AI Model Registry, Online prediction",official/bigquery_ml/bqml-online-prediction.ipynb,
|
||||
"BigQuery ML",official/structured_data/rapid_prototyping_bqml_automl.ipynb,
|
||||
Custom Training,official/custom/sdk-custom-image-classification-batch.ipynb,
|
||||
Custom Training,official/custom/sdk-custom-image-classification-online.ipynb,
|
||||
Custom Training,official/custom/SDK_Custom_Container_Prediction.ipynb,
|
||||
"Custom Training, BiqQuery dataset",official/custom/custom-tabular-bq-managed-dataset.ipynb,
|
||||
"Custom Training, TensorBoard",official/custom/custom-tabular-bq-managed-dataset.ipynb,
|
||||
"Custom Training, TensorBoard",official/tensorboard/tensorboard_custom_training_with_custom_container.ipynb,
|
||||
"Custom Training, TensorBoard",official/tensorboard/tensorboard_custom_training_with_prebuilt_container.ipynb
|
||||
"Custom Training, Managed dataset",official/sdk/SDK_Custom_Training_Python_Package_Managed_Text_Dataset_Tensorflow_Serving_Container.ipynb,
|
||||
"Custom Training, Distributed",official/training/multi_node_ddp_gloo_vertex_training_with_custom_container.ipynb,
|
||||
"Custom Training, Distributed",official/training/multi_node_ddp_nccl_vertex_training_with_custom_container.ipynb
|
||||
Vertex AI Experiments,official/experiments/comparing_pipeline_runs.ipynb,
|
||||
Vertex AI Experiments,official/experiments/build_model_experimentation_lineage_with_prebuild_code.ipynb,
|
||||
Vertex AI Experiments,official/experiments/comparing_local_trained_models.ipynb,
|
||||
"Vertex Explainable AI, Tabular data",official/explainable_ai/sdk_automl_tabular_binary_classification_batch_explain.ipynb,vertex-ai/docs/explainable-ai/overview
|
||||
"Vertex Explainable AI, Tabular data",official/explainable_ai/sdk_automl_tabular_classification_online_explain.ipynb,vertex-ai/docs/explainable-ai/overview
|
||||
"Vertex Explainable AI, Image data",official/explainable_ai/sdk_custom_image_classification_batch_explain.ipynb,vertex-ai/docs/explainable-ai/overview
|
||||
"Vertex Explainable AI, Tabular data",official/explainable_ai/sdk_custom_tabular_regression_batch_explain.ipynb,vertex-ai/docs/explainable-ai/overview
|
||||
"Vertex Explainable AI, Tabular data",official/explainable_ai/sdk_custom_tabular_regression_online_explain.ipynb,vertex-ai/docs/explainable-ai/overview
|
||||
Vertex ML Metadata,official/ml_metadata/sdk-metric-parameter-tracking-for-custom-jobs.ipynb,
|
||||
"Vertex Explainable AI, Image data",official/explainable_ai/sdk_custom_image_classification_online_explain.ipynb,vertex-ai/docs/explainable-ai/overview
|
||||
Vertex AI Feature Store,official/feature_store/sdk-feature-store.ipynb,
|
||||
Vertex AI Feature Store,official/feature_store/sdk-feature-store-pandas.ipynb,
|
||||
Vertex AI Matching Engine,official/matching_engine/sdk_matching_engine_for_indexing.ipynb,
|
||||
Vertex ML Metadata,official/ml_metadata/sdk-metric-parameter-tracking-for-custom-jobs.ipynb,
|
||||
Vertex ML Metadata,official/ml_metadata/sdk-metric-parameter-tracking-for-locally-trained-models.ipynb,
|
||||
"Vertex ML Metadata, Vertex AI Pipelines",official/ml_metadata/sdk-metric-parameter-tracking-for-locally-trained-models.ipynb,
|
||||
"Vertex AI Model Evaluation, AutoML",official/model_evaluation/automl_tabular_classification_model_evaluation.ipynb,
|
||||
"Vertex AI Model Evaluation, AutoML",official/model_evaluation/automl_tabular_regression_model_evaluation.ipynb,
|
||||
"Vertex AI Model Evaluation, AutoML",official/model_evaluation/automl_text_classification_model_evaluation.ipynb,
|
||||
"Vertex AI Model Evaluation, AutoML",official/model_evaluation/automl_video_classification_model_evaluation.ipynb,
|
||||
"Vertex AI Model Evaluation, Custom Training",official/model_evaluation/custom_tabular_regression_model_evaluation.ipynb,
|
||||
Model Monitoring,official/model_monitoring/model_monitoring.ipynb,
|
||||
Vertex AI Pipelines,official/pipelines/pipelines_intro_kfp.ipynb,
|
||||
Vertex AI Pipelines,official/pipelines/control_flow_kfp.ipynb,
|
||||
Vertex AI Pipelines,official/pipelines/metrics_viz_run_compare_kfp.ipynb,
|
||||
Vertex AI Pipelines,official/pipelines/lightweight_functions_component_io_kfp.ipynb,
|
||||
"Vertex AI Pipelines Image data",official/pipelines/google_cloud_pipeline_components_automl_images.ipynb,
|
||||
"Vertex AI Pipelines, Tabular data",official/pipelines/automl_tabular_classification_beans.ipynb,
|
||||
"Vertex AI Pipelines, Tabular data",official/pipelines/google_cloud_pipeline_components_automl_tabular.ipynb,
|
||||
"Vertex AI Pipelines, Tabular data",official/pipelines/google_cloud_pipeline_components_dataproc_tabular.ipynb,
|
||||
"Vertex AI Pipelines, Text data",official/pipelines/google_cloud_pipeline_components_automl_text.ipynb,
|
||||
"Vertex AI Pipelines, Text data",official/pipelines/google_cloud_pipeline_components_bqml_text.ipynb,
|
||||
Vertex AI Pipelines,official/pipelines/custom_model_training_and_batch_prediction.ipynb,
|
||||
Vertex AI Pipelines,official/pipelines/google_cloud_pipeline_components_model_train_upload_deploy.ipynb,
|
||||
Vertex AI Pipelines,official/pipelines/google_cloud_pipeline_components_model_upload_predict_evaluate.ipynb,
|
||||
"Vertex AI Training, Reduction Server, PyTorch",official/reduction_server/pytorch_distributed_training_reduction_server.ipynb,
|
||||
"Tabular Workflows, Vertex AI TabNet",official/tabnet/tabnet_vertex_tutorial.ipynb,
|
||||
"Tabular Workflows, Vertex AI TabNet, Vertex Explainablee AI",official/tabnet/ai-explanations-tabnet-algorithm.ipynb,
|
||||
"Tabular Workflows, Vertex AI TabNet, Vertex AI Pipelines",official/tabular_workflows/tabnet_on_vertex_pipelines.ipynb,
|
||||
"Tabular Workflows, Vertex AI Wide and Deep",official/tabular_workflows/wide_and_deep_on_vertex_pipelines.ipynb,
|
||||
Vertex AI Vizier,official/vizier/gapic-vizier-multi-objective-optimization.ipynb,vertex-ai/docs/vizier/using-vizier
|
||||
|
@@ -29,17 +29,15 @@
|
||||
/pipelines/google_cloud_pipelines_dataproc_tabular @inardini
|
||||
/automl/automl_forecasting_bqml_arima_plus_comparison.ipynb @TheMichaelHu
|
||||
/automl/automl_tabular_on_vertex_pipelines.ipynb @helinwang
|
||||
/custom/custom_training_tensorboard_profiler.ipynb @itseric
|
||||
/custom/custom_training_tensorboard_profiler.ipynb @gericdong
|
||||
/custom/get_started_with_vertex_endpoint_and_shared_vm.ipynb @andrewferlitsch
|
||||
/workbench/spark/spark_sample_notebook.ipynb @bradmiro
|
||||
/workbench/spark/spark_ml.ipynb @bradmiro
|
||||
/model_registry/bqml_vertexai_model_registry.ipynb @soheilazangeneh
|
||||
/workbench/exploratory_data_analysis/explore_data_in_bigquery_with_workbench.ipynb @alokpattani
|
||||
/model_evaluation/automl_tabular_classification_model_evaluation.ipynb @soheilazangeneh
|
||||
/model_evaluation/automl_tabular_regression_model_evaluation.ipynb @soheilazangeneh
|
||||
/tabular_workflows/tabnet_on_vertex_pipelines.ipynb @sakagarwal
|
||||
/tabular_workflows/wide_and_deep_on_vertex_pipelines.ipynb @sakagarwal
|
||||
/tabular_workflows/prophet_on_vertex_pipelines.ipynb @TheMichaelHu
|
||||
/model_evaluation/custom_tabular_classification_model_evaluation.ipynb @soheilazangeneh
|
||||
/sdk/SDK_FBProphet_Forecasting_Online.ipynb @brianchunkang
|
||||
/automl/sdk_automl_forecasting_hierarchical_batch.ipynb @ivanmkc
|
||||
/prediction/custom_batch_prediction_feature_filter.ipynb @soheilazangeneh
|
||||
/feature_store/feature_store_streaming_ingestion_sdk.ipynb @soheilazangeneh
|
||||
/pipelines/Train_tabular_models_with_many_frameworks_and_import_to_Vertex_AI_using_Pipelines @Ark-kun
|
||||
/experiments/get_started_with_vertex_experiments_autologging.ipynb @inardini
|
||||
@@ -4,441 +4,3 @@ The official notebooks are a collection of curated and non-curated notebooks aut
|
||||
|
||||
The official notebooks are organized by Google Cloud Vertex AI services.
|
||||
|
||||
## Manifest of Curated Notebooks
|
||||
|
||||
### AutoML Text data
|
||||
|
||||
|
||||
[Create, train, and deploy an AutoML text classification model](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/automl-text-classification.ipynb)
|
||||
|
||||
Learn how to use `AutoML` to train a text classification model.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
* Create a `Vertex AI Dataset`.
|
||||
* Train an `AutoML` text classification `Model` resource.
|
||||
* Obtain the evaluation metrics for the `Model` resource.
|
||||
* Create an `Endpoint` resource.
|
||||
* Deploy the `Model` resource to the `Endpoint` resource.
|
||||
* Make an online prediction
|
||||
* Make a batch prediction
|
||||
|
||||
### AutoML Tabular data
|
||||
|
||||
|
||||
[AutoML tabular forecasting model for batch prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_tabular_forecasting_batch.ipynb)
|
||||
|
||||
Learn how to create an `AutoML` tabular forecasting model from a Python script, and then do a batch prediction using the Vertex AI SDK.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a `Vertex AI Dataset` resource.
|
||||
- Train an `AutoML` tabular forecasting `Model` resource.
|
||||
- Obtain the evaluation metrics for the `Model` resource.
|
||||
- Make a batch prediction.
|
||||
|
||||
### BigQuery ML Vertex AI Model Registry Batch prediction
|
||||
|
||||
|
||||
[Deploy BiqQuery ML Model on Vertex AI Model Registry and make predictions](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/model-registry/bqml-vertexai-model-registry.ipynb)
|
||||
|
||||
Learn how to use `Vertex AI Model Registry` with `BigQuery ML` and make batch predictions:
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Train a model with `BigQuery ML`
|
||||
- Upload the model to `Vertex AI Model Registry`
|
||||
- Create a `Vertex AI Endpoint` resource
|
||||
- Deploy the `Model` resource to the `Endpoint` resource
|
||||
- Make `prediction` requests to the model endpoint
|
||||
- Run `batch prediction` job on the `Model` resource
|
||||
|
||||
|
||||
### BigQuery ML Vertex AI Model Registry Online prediction
|
||||
|
||||
|
||||
[Online prediction with BigQuery ML](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/bigquery_ml/bqml-online-prediction.ipynb)
|
||||
|
||||
Learn how to train and deploy a churn prediction model for real-time inference, with the data in BigQuery and model trained using BigQuery ML, registered to Vertex AI Model Registry, and deployed to an endpoint on Vertex AI for online predictions.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Using Python & SQL to query the public data in BigQuery
|
||||
- Preparing the data for modeling
|
||||
- Training a classification model using BigQuery ML and registering it to Vertex AI Model Registry
|
||||
- Inspecting the model on Vertex AI Model Registry
|
||||
- Deploying the model to an endpoint on Vertex AI
|
||||
- Making sample online predictions to the model endpoint
|
||||
|
||||
|
||||
### Custom Training
|
||||
|
||||
|
||||
[Custom training and batch prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/custom/sdk-custom-image-classification-batch.ipynb)
|
||||
|
||||
Learn to use `Vertex AI Training` to create a custom trained model and use `Vertex AI Batch Prediction` to do a batch prediction on the trained model.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a `Vertex AI` custom job for training a TensorFlow model.
|
||||
- Upload the trained model artifacts as a `Model` resource.
|
||||
- Make a batch prediction.
|
||||
|
||||
[Custom training and online prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/custom/sdk-custom-image-classification-online.ipynb)
|
||||
|
||||
Learn to use `Vertex AI Training` to create a custom-trained model from a Python script in a Docker container, and learn to use `Vertex AI Prediction` to do a prediction on the deployed model by sending data.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a `Vertex AI` custom job for training a TensorFlow model.
|
||||
- Upload the trained model artifacts to a `Model` resource.
|
||||
- Create a serving `Endpoint` resource.
|
||||
- Deploy the `Model` resource to a serving `Endpoint` resource.
|
||||
- Make a prediction.
|
||||
- Undeploy the `Model` resource.
|
||||
|
||||
### Tabular Data
|
||||
|
||||
|
||||
[Compare Vertex AI Forecasting and BigQuery ML ARIMA_PLUS](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/automl_forecasting_bqml_arima_plus_comparison.ipynb)
|
||||
|
||||
Learn how to create an BQML ARIMA_PLUS model using a training [Vertex AI Pipeline](https://cloud.
|
||||
|
||||
The steps performed are:
|
||||
|
||||
- Train the BQML ARIMA_PLUS model.
|
||||
- View BQML model evaluation.
|
||||
- Make a batch prediction with the BQML model.
|
||||
- Create a Vertex AI `Dataset` resource.
|
||||
- Train the Vertex AI Forecasting model.
|
||||
- View the Model evaluation.
|
||||
- Make a batch prediction with the Model.
|
||||
|
||||
|
||||
### AutoML Tabular Data
|
||||
|
||||
|
||||
[AutoML Tabular Pipeline](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/automl_tabular_on_vertex_pipelines.ipynb)
|
||||
|
||||
Learn how to create two regression models using [Vertex Pipelines](https://cloud.
|
||||
|
||||
The steps performed are:
|
||||
|
||||
- Create a training pipeline that reduces the search space from the default to save time.
|
||||
- Create a training pipeline that reuses the architecture search results from the previous pipeline to save time.
|
||||
|
||||
### Vertex AI Experiments
|
||||
|
||||
|
||||
[Compare pipeline runs with Vertex AI Experiments](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/experiments/comparing_pipeline_runs.ipynb)
|
||||
|
||||
Learn how to use `Vertex AI Experiments` to log a pipeline job and compare different pipeline jobs.
|
||||
|
||||
|
||||
|
||||
[Build Vertex AI Experiment lineage for custom training](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/experiments/build_model_experimentation_lineage_with_prebuild_code.ipynb)
|
||||
|
||||
Learn how to integrate preprocessing code in a Vertex AI experiments.
|
||||
|
||||
|
||||
|
||||
[Track parameters and metrics for locally trained models](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/experiments/comparing_local_trained_models.ipynb)
|
||||
|
||||
Learn how to use Vertex AI Experiments to compare and evaluate model experiments.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- log the model parameters
|
||||
- log the loss and metrics on every epoch to TensorBoard
|
||||
- log the evaluation metrics
|
||||
|
||||
|
||||
### Vertex AI Feature Store
|
||||
|
||||
|
||||
[Online and Batch predictions using Vertex AI Feature Store](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/feature_store/sdk-feature-store.ipynb)
|
||||
|
||||
Learn how to use `Vertex AI Feature Store` to import feature data, and to access the feature data for both online serving and offline tasks, such as training.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create featurestore, entity type, and feature resources.
|
||||
- Import feature data into `Vertex AI Feature Store` resource.
|
||||
- Serve online prediction requests using the imported features.
|
||||
- Access imported features in offline jobs, such as training jobs.
|
||||
|
||||
### Matching Engine
|
||||
|
||||
|
||||
[Create Vertex AI Matching Engine index](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/matching_engine/sdk_matching_engine_for_indexing.ipynb)
|
||||
|
||||
Learn how to create Approximate Nearest Neighbor (ANN) Index, query against indexes, and validate the performance of the index.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
* Create ANN Index and Brute Force Index
|
||||
* Create an IndexEndpoint with VPC Network
|
||||
* Deploy ANN Index and Brute Force Index
|
||||
* Perform online query
|
||||
* Compute recall
|
||||
|
||||
|
||||
### Model Monitoring
|
||||
|
||||
|
||||
[Vertex AI Model Monitoring with Explainable AI Feature Attributions](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/model_monitoring/model_monitoring.ipynb)
|
||||
|
||||
Learn to use the `Vertex AI Model Monitoring` service to detect drift and anomalies in prediction requests from a deployed `Vertex AI Model` resource.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Upload a pre-trained model as a `Vertex AI Model` resource.
|
||||
- Create an `Vertex AI Endpoint` resource.
|
||||
- Deploy the `Model` resource to the `Endpoint` resource.
|
||||
- Configure the `Endpoint` resource for model monitoring.
|
||||
- Initialize the baseline distribution for model monitoring.
|
||||
- Generate synthetic prediction requests.
|
||||
- Understand how to interpret the statistics, visualizations, other data reported by the model monitoring feature.
|
||||
|
||||
### Vertex AI Pipelines
|
||||
|
||||
|
||||
[Lightweight Python function-based components, and component I/O](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/lightweight_functions_component_io_kfp.ipynb)
|
||||
|
||||
Learn to use the KFP SDK to build lightweight Python function-based components, and then you learn to use `Vertex AI Pipelines` to execute the pipeline.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Build Python function-based KFP components.
|
||||
- Construct a KFP pipeline.
|
||||
- Pass *Artifacts* and *parameters* between components, both by path reference and by value.
|
||||
- Use the `kfp.dsl.importer` method.
|
||||
- Compile the KFP pipeline.
|
||||
- Execute the KFP pipeline using `Vertex AI Pipelines`
|
||||
|
||||
### Vertex AI Pipelines Image data
|
||||
|
||||
|
||||
[AutoML image classification pipelines using google-cloud-pipeline-components](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/google_cloud_pipeline_components_automl_images.ipynb)
|
||||
|
||||
Learn how to use `Vertex AI Pipelines` and `Google Cloud Pipeline Components` to build an `AutoML` image classification model.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a KFP pipeline:
|
||||
- Create a `Dataset` resource.
|
||||
- Train an AutoML image classification `Model` resource.
|
||||
- Create an `Endpoint` resource.
|
||||
- Deploys the `Model` resource to the `Endpoint` resource.
|
||||
- Compile the KFP pipeline.
|
||||
- Execute the KFP pipeline using `Vertex AI Pipelines`
|
||||
|
||||
|
||||
|
||||
### Vertex AI Pipelines Tabular data
|
||||
|
||||
|
||||
[AutoML Tabular pipelines using google-cloud-pipeline-components](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/automl_tabular_classification_beans.ipynb)
|
||||
|
||||
Learn to use `Vertex AI Pipelines` and `Google Cloud Pipeline Components` to build an `AutoML` tabular classification model.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a KFP pipeline:
|
||||
- Create a `Dataset` resource.
|
||||
- Train an AutoML tabular classification `Model` resource.
|
||||
- Create an `Endpoint` resource.
|
||||
- Deploys the `Model` resource to the `Endpoint` resource.
|
||||
- Compile the KFP pipeline.
|
||||
- Execute the KFP pipeline using `Vertex AI Pipelines`
|
||||
|
||||
|
||||
|
||||
[AutoML tabular regression pipelines using google-cloud-pipeline-components](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/google_cloud_pipeline_components_automl_tabular.ipynb)
|
||||
|
||||
Learn to use `Vertex AI Pipelines` and `Google Cloud Pipeline Components` to build an `AutoML` tabular regression model.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a KFP pipeline:
|
||||
- Create a `Dataset` resource.
|
||||
- Train an AutoML tabular regression `Model` resource.
|
||||
- Create an `Endpoint` resource.
|
||||
- Deploys the `Model` resource to the `Endpoint` resource.
|
||||
- Compile the KFP pipeline.
|
||||
- Execute the KFP pipeline using `Vertex AI Pipelines`
|
||||
|
||||
|
||||
|
||||
### Vertex AI Pipelines Text data
|
||||
|
||||
|
||||
[AutoML text classification pipelines using google-cloud-pipeline-components](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/google_cloud_pipeline_components_automl_text.ipynb)
|
||||
|
||||
Learn to use `Vertex AI Pipelines` and `Google Cloud Pipeline Components` to build an `AutoML` text classification model.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a KFP pipeline:
|
||||
- Create a `Dataset` resource.
|
||||
- Train an AutoML text classification `Model` resource.
|
||||
- Create an `Endpoint` resource.
|
||||
- Deploys the `Model` resource to the `Endpoint` resource.
|
||||
- Compile the KFP pipeline.
|
||||
- Execute the KFP pipeline using `Vertex AI Pipelines`
|
||||
|
||||
|
||||
|
||||
### Vertex AI Pipelines
|
||||
|
||||
|
||||
[Custom training with pre-built Google Cloud Pipeline Components](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/custom_model_training_and_batch_prediction.ipynb)
|
||||
|
||||
Learn to use `Vertex AI Pipelines` and `Google Cloud Pipeline Components` to build a custom model.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a KFP pipeline:
|
||||
- Train a custom model.
|
||||
- Upload the trained model as a `Model` resource.
|
||||
- Create an `Endpoint` resource.
|
||||
- Deploy the `Model` resource to the `Endpoint` resource.
|
||||
- Make a batch prediction request.
|
||||
|
||||
|
||||
|
||||
[Pipeline control structures using the KFP SDK](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/control_flow_kfp.ipynb)
|
||||
|
||||
Learn how to use the KFP SDK to build pipelines that use loops and conditionals, including nested examples.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a KFP pipeline:
|
||||
- Use control flow components
|
||||
- Compile the KFP pipeline.
|
||||
- Execute the KFP pipeline using `Vertex AI Pipelines`
|
||||
|
||||
[Metrics visualization and run comparison using the KFP SDK](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/metrics_viz_run_compare_kfp.ipynb)
|
||||
|
||||
Learn how to use the KFP SDK to build pipelines that generate evaluation metrics.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create KFP components:
|
||||
- Generate ROC curve and confusion matrix visualizations for classification results
|
||||
- Write metrics
|
||||
- Create KFP pipelines.
|
||||
- Execute KFP pipelines
|
||||
- Compare metrics across pipeline runs
|
||||
|
||||
[Pipelines introduction for KFP](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/pipelines/pipelines_intro_kfp.ipynb)
|
||||
|
||||
Learn how to use the KFP SDK to build pipelines that generate evaluation metrics.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Define and compile a `Vertex AI` pipeline.
|
||||
- Specify which service account to use for a pipeline run.
|
||||
|
||||
### Vertex AI Vizier
|
||||
|
||||
|
||||
[Optimizing multiple objectives with Vertex AI Vizier](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/vizier/gapic-vizier-multi-objective-optimization.ipynb)
|
||||
|
||||
Learn how to use `Vertex AI Vizier` to optimize a multi-objective study.
|
||||
|
||||
|
||||
|
||||
### Vertex Explainable AI Tabular data
|
||||
|
||||
|
||||
[AutoML training tabular binary classification model for batch explanation](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_automl_tabular_binary_classification_batch_explain.ipynb)
|
||||
|
||||
Learn to use `AutoML` to create a tabular binary classification model from a Python script, and then learn to use `Vertex AI Batch Prediction` to make predictions with explanations.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a `Vertex Dataset` resource.
|
||||
- Train an `AutoML` tabular binary classification model.
|
||||
- View the model evaluation metrics for the trained model.
|
||||
- Make a batch prediction request with explainability.
|
||||
|
||||
|
||||
* Prediction Service: Does an on-demand prediction for the entire set of instances (i.e., one or more data items) and returns the results in real-time.
|
||||
|
||||
* Batch Prediction Service: Does a queued (batch) prediction for the entire set of instances in the background and stores the results in a Cloud Storage bucket when ready.
|
||||
|
||||
[AutoML training tabular classification model for online explanation](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_automl_tabular_classification_online_explain.ipynb)
|
||||
|
||||
Learn how to use `AutoML` to create a tabular binary classification model from a Python script, and then learn to use `Vertex AI Online Prediction` to make online predictions with explanations.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a `Vertex Dataset` resource.
|
||||
- Train an `AutoML` tabular binary classification model.
|
||||
- View the model evaluation metrics for the trained model.
|
||||
- Create a serving `Endpoint` resource.
|
||||
- Deploy the `Model` resource to a serving `Endpoint` resource.
|
||||
- Make an online prediction request with explainability.
|
||||
- Undeploy the `Model` resource.
|
||||
|
||||
### Vertex Explainable AI Image data
|
||||
|
||||
|
||||
[Custom training image classification model for batch prediction with explainabilty](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_custom_image_classification_batch_explain.ipynb)
|
||||
|
||||
Learn to use `Vertex AI Training and Explainable AI` to create a custom image classification model with explanations, and then you learn to use `Vertex AI Batch Prediction` to make a batch prediction request with explanations.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a `Vertex AI` custom job for training a TensorFlow model.
|
||||
- View the model evaluation for the trained model.
|
||||
- Set explanation parameters for when the model is deployed.
|
||||
- Upload the trained model artifacts and explanation parameters as a `Model` resource.
|
||||
- Make a batch prediction with explanations.
|
||||
|
||||
[Custom training image classification model for online prediction with explainabilty](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_custom_image_classification_online_explain.ipynb)
|
||||
|
||||
Learn how to use `Vertex AI Training and Explainable AI` to create a custom image classification model with explanations, and then you learn to use `Vertex AI Prediction` to make an online prediction request with explanations.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a `Vertex AI` custom job for training a TensorFlow model.
|
||||
- View the model evaluation for the trained model.
|
||||
- Set explanation parameters for when the model is deployed.
|
||||
- Upload the trained model artifacts and explanations as a `Model` resource.
|
||||
- Create a serving `Endpoint` resource.
|
||||
- Deploy the `Model` resource to a serving `Endpoint` resource.
|
||||
- Make a prediction with explanation.
|
||||
- Undeploy the `Model` resource.
|
||||
|
||||
### Vertex Explainable AI Tabular data
|
||||
|
||||
|
||||
[Custom training tabular regression model for batch prediction with explainabilty](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_custom_tabular_regression_batch_explain.ipynb)
|
||||
|
||||
Learn how to use `Vertex AI Training and Explainable AI` to create a custom image classification model with explanations, and then you learn to use `Vertex AI Batch Prediction` to make a batch prediction request with explanations.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a `Vertex AI` custom job for training a TensorFlow model.
|
||||
- View the model evaluation for the trained model.
|
||||
- Set explanation parameters for when the model is deployed.
|
||||
- Upload the trained model artifacts and explanations as a `Model` resource.
|
||||
- Make a batch prediction with explanations.
|
||||
|
||||
### Vertex ML Metadata
|
||||
|
||||
|
||||
[Track parameters and metrics for custom training jobs](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/ml_metadata/sdk-metric-parameter-tracking-for-custom-jobs.ipynb)
|
||||
|
||||
Learn how to use Vertex AI SDK for Python to:
|
||||
|
||||
The steps performed include:
|
||||
- Track training parameters and prediction metrics for a custom training job.
|
||||
- Extract and perform analysis for all parameters and metrics within an Experiment.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
[AutoML Tabular Training and Prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/automl-tabular-classification.ipynb)
|
||||
|
||||
[AutoML Tabular training and prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/automl-tabular-classification.ipynb)
|
||||
|
||||
```
|
||||
Learn how to train and make predictions on an AutoML model based on a tabular dataset.
|
||||
@@ -13,6 +14,8 @@ The steps performed include the following:
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Classification for tabular data](https://cloud.google.com/vertex-ai/docs/tabular-data/classification-regression/overview).
|
||||
|
||||
|
||||
[Create, train, and deploy an AutoML text classification model](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/automl-text-classification.ipynb)
|
||||
|
||||
@@ -31,11 +34,86 @@ The steps performed include:
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Classification for text data](https://cloud.google.com/vertex-ai/docs/training-overview#classification_for_text).
|
||||
|
||||
[AutoML training video classification model for batch prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_video_classification_batch.ipynb)
|
||||
|
||||
[Compare Vertex AI Forecasting and BigQuery ML ARIMA_PLUS](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/automl_forecasting_bqml_arima_plus_comparison.ipynb)
|
||||
|
||||
```
|
||||
Learn how to create an AutoML video classification model from a Python script, and then do a batch prediction using the Vertex AI SDK.
|
||||
Learn how to create an BigQuery ML ARIMA_PLUS model using a training Vertex AI Pipeline from Google Cloud Pipeline Components , and then do a batch prediction using the corresponding prediction pipeline.
|
||||
|
||||
The steps performed are:
|
||||
|
||||
- Train the BigQuery ML ARIMA_PLUS model.
|
||||
- View BigQuery ML model evaluation.
|
||||
- Make a batch prediction with the BigQuery ML model.
|
||||
- Create a Vertex AI `Dataset` resource.
|
||||
- Train the Vertex AI Forecasting model.
|
||||
- View the Model evaluation.
|
||||
- Make a batch prediction with the Model.
|
||||
|
||||
```
|
||||
|
||||
Learn more about [BQML ARIMA+ forecasting for tabular data](https://cloud.google.com/vertex-ai/docs/tabular-data/forecasting-arima/overview).
|
||||
|
||||
|
||||
[AutoML Tabular Workflow pipelines](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/automl_tabular_on_vertex_pipelines.ipynb)
|
||||
|
||||
```
|
||||
Learn how to create two regression models using Vertex AI Pipelines downloaded from Google Cloud Pipeline Components .
|
||||
|
||||
The steps performed are:
|
||||
|
||||
- Create a training pipeline that reduces the search space from the default to save time.
|
||||
- Create a training pipeline that reuses the architecture search results from the previous pipeline to save time.
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Tabular Workflow for E2E AutoML](https://cloud.google.com/vertex-ai/docs/tabular-data/tabular-workflows/e2e-automl).
|
||||
|
||||
|
||||
[Get started with AutoML Training](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/get_started_automl_training.ipynb)
|
||||
|
||||
```
|
||||
Learn how to use `AutoML` for training with `Vertex AI`.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Train an image model
|
||||
- Export the image model as an edge model
|
||||
- Train a tabular model
|
||||
- Export the tabular model as a cloud model
|
||||
- Train a text model
|
||||
- Train a video model
|
||||
|
||||
```
|
||||
|
||||
Learn more about [AutoML training](https://cloud.google.com/vertex-ai/docs/training-overview).
|
||||
|
||||
|
||||
[AutoML training hierarchical forecasting for batch prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_forecasting_hierarchical_batch.ipynb)
|
||||
|
||||
```
|
||||
In this tutorial, you create an AutoML hierarchical forecasting model and deploy it for batch prediction using the Vertex AI SDK for Python.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a Vertex AI `TimeSeriesDataset` resource.
|
||||
- Train the model.
|
||||
- View the model evaluation.
|
||||
- Deploy the `Model` resource to a serving `Endpoint` resource.
|
||||
- Make a prediction.
|
||||
- Undeploy the `Model`.
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Hierarchical forecasting for tabular data](https://cloud.google.com/vertex-ai/docs/tabular-data/forecasting/hierarchical).
|
||||
|
||||
|
||||
[AutoML training image object detection model for batch prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_image_object_detection_batch.ipynb)
|
||||
|
||||
```
|
||||
In this tutorial, you create an AutoML image object detection model from a Python script, and then do a batch prediction using the Vertex AI SDK.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
@@ -46,22 +124,7 @@ The steps performed include:
|
||||
|
||||
```
|
||||
|
||||
|
||||
[AutoML training text entity extraction model for online prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_text_entity_extraction_online.ipynb)
|
||||
|
||||
```
|
||||
Learn how to create an AutoML text entity extraction model and deploy for online prediction from a Python script using the Vertex SDK.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a Vertex `Dataset` resource.
|
||||
- Train the model.
|
||||
- View the model evaluation.
|
||||
- Deploy the `Model` resource to a serving `Endpoint` resource.
|
||||
- Make a prediction.
|
||||
- Undeploy the `Model`.
|
||||
|
||||
```
|
||||
Learn more about [Object detection for image data](https://cloud.google.com/vertex-ai/docs/training-overview#object_detection_for_images).
|
||||
|
||||
|
||||
[AutoML tabular forecasting model for batch prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_tabular_forecasting_batch.ipynb)
|
||||
@@ -78,32 +141,64 @@ The steps performed include:
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Forecasting for tabular data](https://cloud.google.com/vertex-ai/docs/tabular-data/forecasting/overview).
|
||||
|
||||
[AutoML training video action recognition model for batch prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_video_action_recognition_batch.ipynb)
|
||||
|
||||
[AutoML training tabular regression model for batch prediction using BigQuery](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_tabular_regression_batch_bq.ipynb)
|
||||
|
||||
```
|
||||
Learn how to create an AutoML video action recognition model from a Python script, and then do a batch prediction using the Vertex AI SDK.
|
||||
Learn how to create an AutoML tabular regression model and deploy it for batch prediction using the Vertex AI SDK for Python.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a `Vertex AI Dataset` resource.
|
||||
- Create a Vertex AI `Dataset` resource.
|
||||
- Train the model.
|
||||
- View the model evaluation.
|
||||
- Make a batch prediction.
|
||||
```
|
||||
|
||||
|
||||
[AutoML Tabular Pipeline](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/automl_tabular_on_vertex_pipelines.ipynb)
|
||||
- Deploy the `Model` resource to a serving `Endpoint` resource.
|
||||
- Make a prediction.
|
||||
- Undeploy the `Model`.
|
||||
|
||||
```
|
||||
Learn how to create two regression models using [Vertex Pipelines](https://cloud.
|
||||
|
||||
The steps performed are:
|
||||
Learn more about [Regression for tabular data](https://cloud.google.com/vertex-ai/docs/tabular-data/classification-regression/overview).
|
||||
|
||||
- Create a training pipeline that reduces the search space from the default to save time.
|
||||
- Create a training pipeline that reuses the architecture search results from the previous pipeline to save time.
|
||||
|
||||
[AutoML training tabular regression model for online prediction using BigQuery](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_tabular_regression_online_bq.ipynb)
|
||||
|
||||
```
|
||||
Learn how to create an AutoML tabular regression model and deploy for online prediction from a Python script using the Vertex AI SDK.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a Vertex `Dataset` resource.
|
||||
- Train the model.
|
||||
- View the model evaluation.
|
||||
- Deploy the `Model` resource to a serving `Endpoint` resource.
|
||||
- Make a prediction.
|
||||
- Undeploy the `Model`.
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Regression for tabular data](https://cloud.google.com/vertex-ai/docs/tabular-data/classification-regression/overview).
|
||||
|
||||
|
||||
[AutoML training text entity extraction model for online prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_text_entity_extraction_online.ipynb)
|
||||
|
||||
```
|
||||
Learn how to create an AutoML text entity extraction model and deploy for online prediction from a Python script using the Vertex AI SDK.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a Vertex `Dataset` resource.
|
||||
- Train the model.
|
||||
- View the model evaluation.
|
||||
- Deploy the `Model` resource to a serving `Endpoint` resource.
|
||||
- Make a prediction.
|
||||
- Undeploy the `Model`.
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Entity extraction for text data](https://cloud.google.com/vertex-ai/docs/training-overview#entity_extraction_for_text).
|
||||
|
||||
|
||||
[Training an AutoML text sentiment analysis model for online predictions](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_text_sentiment_analysis_online.ipynb)
|
||||
@@ -123,41 +218,42 @@ The steps performed include:
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Sentiment analysis for text data](https://cloud.google.com/vertex-ai/docs/training-overview#sentiment_analysis_for_text).
|
||||
|
||||
[Compare Vertex AI Forecasting and BigQuery ML ARIMA_PLUS](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/automl_forecasting_bqml_arima_plus_comparison.ipynb)
|
||||
|
||||
[AutoML training video action recognition model for batch prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_video_action_recognition_batch.ipynb)
|
||||
|
||||
```
|
||||
Learn how to create an BigQuery ML ARIMA_PLUS model using a training [Vertex AI Pipeline](https://cloud.
|
||||
Learn how to create an AutoML video action recognition model from a Python script, and then do a batch prediction using the Vertex AI SDK.
|
||||
|
||||
The steps performed are:
|
||||
The steps performed include:
|
||||
|
||||
- Train the BigQuery ML ARIMA_PLUS model.
|
||||
- View BigQuery ML model evaluation.
|
||||
- Make a batch prediction with the BigQuery ML model.
|
||||
- Create a Vertex AI `Dataset` resource.
|
||||
- Train the Vertex AI Forecasting model.
|
||||
- View the Model evaluation.
|
||||
- Make a batch prediction with the Model.
|
||||
- Create a `Vertex AI Dataset` resource.
|
||||
- Train the model.
|
||||
- View the model evaluation.
|
||||
- Make a batch prediction.
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Action recognition for video data](https://cloud.google.com/vertex-ai/docs/training-overview#action_recognition_for_videos).
|
||||
|
||||
[AutoML training tabular regression model for online prediction using BigQuery](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_tabular_regression_online_bq.ipynb)
|
||||
|
||||
[AutoML training video classification model for batch prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_video_classification_batch.ipynb)
|
||||
|
||||
```
|
||||
Learn how to create an AutoML tabular regression model and deploy for online prediction from a Python script using the Vertex AI SDK.
|
||||
Learn how to create an AutoML video classification model from a Python script, and then do a batch prediction using the Vertex AI SDK.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a Vertex `Dataset` resource.
|
||||
- Train the model.
|
||||
- View the model evaluation.
|
||||
- Deploy the `Model` resource to a serving `Endpoint` resource.
|
||||
- Make a prediction.
|
||||
- Undeploy the `Model`.
|
||||
- Make a batch prediction.
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Classification for video data](https://cloud.google.com/vertex-ai/docs/training-overview#classification_for_videos).
|
||||
|
||||
|
||||
[AutoML training video object tracking model for batch prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_video_object_tracking_batch.ipynb)
|
||||
|
||||
@@ -170,21 +266,8 @@ The steps performed include:
|
||||
- Train the model.
|
||||
- View the model evaluation.
|
||||
- Make a batch prediction.
|
||||
```
|
||||
|
||||
|
||||
[AutoML training tabular regression model for batch prediction using BigQuery](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_tabular_regression_batch_bq.ipynb)
|
||||
|
||||
```
|
||||
Learn how to create an AutoML tabular regression model and deploy it for batch prediction using the Vertex AI SDK for Python.
|
||||
|
||||
The steps performed include:
|
||||
Learn more about [Object tracking for video data](https://cloud.google.com/vertex-ai/docs/training-overview#object_tracking_for_videos).
|
||||
|
||||
- Create a Vertex AI `Dataset` resource.
|
||||
- Train the model.
|
||||
- View the model evaluation.
|
||||
- Deploy the `Model` resource to a serving `Endpoint` resource.
|
||||
- Make a prediction.
|
||||
- Undeploy the `Model`.
|
||||
|
||||
```
|
||||
@@ -63,7 +63,9 @@
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use the Vertex AI Python client library to train and deploy a tabular classification model for online prediction.\n",
|
||||
"\n",
|
||||
"**Note**: you may incur charges for training, prediction, storage, or usage of other Google Cloud products in connection with testing this SDK."
|
||||
"**Note**: you may incur charges for training, prediction, storage, or usage of other Google Cloud products in connection with testing this SDK.\n",
|
||||
"\n",
|
||||
"Learn more about [Classification for tabular data](https://cloud.google.com/vertex-ai/docs/tabular-data/classification-regression/overview)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -68,7 +68,9 @@
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This notebook walks you through the major phases of building and using an AutoML text classification model on [Vertex AI](https://cloud.google.com/vertex-ai/docs/). \n"
|
||||
"This notebook walks you through the major phases of building and using an AutoML text classification model on [Vertex AI](https://cloud.google.com/vertex-ai/docs/). \n",
|
||||
"\n",
|
||||
"Learn more about [Classification for text data](https://cloud.google.com/vertex-ai/docs/training-overview#classification_for_text)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -61,7 +61,9 @@
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"In this tutorial, you take on the role of a store planner who must determine how much inventory they will need to order for each of their products and stores for November 2019. You accomplish this by training forecasting models using historical sales data. You start with a baseline model using BigQuery ML (BQML) [ARIMA_PLUS](https://cloud.google.com/bigquery-ml/docs/reference/standard-sql/bigqueryml-syntax-create-time-series) and then compare it against a [Vertex AI Forecasting](https://cloud.google.com/vertex-ai/docs/tabular-data/forecasting/overview) model."
|
||||
"In this tutorial, you take on the role of a store planner who must determine how much inventory they will need to order for each of their products and stores for November 2019. You accomplish this by training forecasting models using historical sales data. You start with a baseline model using BigQuery ML (BQML) [ARIMA_PLUS](https://cloud.google.com/bigquery-ml/docs/reference/standard-sql/bigqueryml-syntax-create-time-series) and then compare it against a [Vertex AI Forecasting](https://cloud.google.com/vertex-ai/docs/tabular-data/forecasting/overview) model.\n",
|
||||
"\n",
|
||||
"Learn more about [BQML ARIMA+ forecasting for tabular data](https://cloud.google.com/vertex-ai/docs/tabular-data/forecasting-arima/overview)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -61,7 +61,9 @@
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"In this tutorial, you will use two Vertex AI Tabular Workflows pipelines to train AutoML models using different configurations. You will see how `get_automl_tabular_pipeline_and_parameters` gives you the ability to customize the default AutoML Tabular pipeline, and how `get_skip_architecture_search_pipeline_and_parameters` allows you to reduce the training time and cost for an AutoML model by using the tuning results from a previous pipeline run."
|
||||
"In this tutorial, you will use two Vertex AI Tabular Workflows pipelines to train AutoML models using different configurations. You will see how `get_automl_tabular_pipeline_and_parameters` gives you the ability to customize the default AutoML Tabular pipeline, and how `get_skip_architecture_search_pipeline_and_parameters` allows you to reduce the training time and cost for an AutoML model by using the tuning results from a previous pipeline run.\n",
|
||||
"\n",
|
||||
"Learn more about [Tabular Workflow for E2E AutoML](https://cloud.google.com/vertex-ai/docs/tabular-data/tabular-workflows/e2e-automl)."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -168,7 +170,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install -U google-cloud-pipeline-components -q"
|
||||
"!pip install -U google-cloud-pipeline-components==1.0.25 -q"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -331,7 +333,10 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"REGION = \"[your-region]\" # @param {type: \"string\"}"
|
||||
"REGION = \"us-central1\" # @param {type: \"string\"}\n",
|
||||
"\n",
|
||||
"if REGION == \"[your-region]\":\n",
|
||||
" REGION = \"us-central1\""
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -377,8 +382,11 @@
|
||||
"import os\n",
|
||||
"import sys\n",
|
||||
"\n",
|
||||
"# If on Google Cloud Notebook, then don't execute this code\n",
|
||||
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\"):\n",
|
||||
"# If on Vertex AI Workbench, then don't execute this code\n",
|
||||
"IS_COLAB = \"google.colab\" in sys.modules\n",
|
||||
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
|
||||
" \"DL_ANACONDA_HOME\"\n",
|
||||
"):\n",
|
||||
" if \"google.colab\" in sys.modules:\n",
|
||||
" from google.colab import auth as google_auth\n",
|
||||
"\n",
|
||||
@@ -386,10 +394,9 @@
|
||||
"\n",
|
||||
" # If you are running this notebook locally, replace the string below with the\n",
|
||||
" # path to your service account key and run this cell to authenticate your GCP\n",
|
||||
" # account. Alternatively, you may edit this notebook to authenticate using\n",
|
||||
" # gcloud.\n",
|
||||
" # account.\n",
|
||||
" elif not os.getenv(\"IS_TESTING\"):\n",
|
||||
" %env GOOGLE_APPLICATION_CREDENTIALS ''"
|
||||
" %env GOOGLE_APPLICATION_CREDENTIALS '[your-service-account-key-path]'"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -476,6 +483,77 @@
|
||||
"! gsutil ls -al $BUCKET_URI"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "44accda192d5"
|
||||
},
|
||||
"source": [
|
||||
"#### Service Account\n",
|
||||
"\n",
|
||||
"You use a service account to create Vertex AI Pipeline jobs. If you do not want to use your project's Compute Engine service account, set `SERVICE_ACCOUNT` to another service account ID."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "e0c9c4f84849"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"SERVICE_ACCOUNT = \"[your-service-account]\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "604ae09ab6d3"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"if (\n",
|
||||
" SERVICE_ACCOUNT == \"\"\n",
|
||||
" or SERVICE_ACCOUNT is None\n",
|
||||
" or SERVICE_ACCOUNT == \"[your-service-account]\"\n",
|
||||
"):\n",
|
||||
" # Get your service account from gcloud\n",
|
||||
" if not IS_COLAB:\n",
|
||||
" shell_output = !gcloud auth list 2>/dev/null\n",
|
||||
" SERVICE_ACCOUNT = shell_output[2].replace(\"*\", \"\").strip()\n",
|
||||
"\n",
|
||||
" else: # IS_COLAB:\n",
|
||||
" shell_output = ! gcloud projects describe $PROJECT_ID\n",
|
||||
" project_number = shell_output[-1].split(\":\")[1].strip().replace(\"'\", \"\")\n",
|
||||
" SERVICE_ACCOUNT = f\"{project_number}-compute@developer.gserviceaccount.com\"\n",
|
||||
"\n",
|
||||
" print(\"Service Account:\", SERVICE_ACCOUNT)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "d1ecb60964d5"
|
||||
},
|
||||
"source": [
|
||||
"#### Set service account access for Vertex AI Pipelines\n",
|
||||
"Run the following commands to grant your service account access to read and write pipeline artifacts in the bucket that you created in the previous step. You only need to run this step once per service account."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "a592f0a380c2"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"! gsutil iam ch serviceAccount:{SERVICE_ACCOUNT}:roles/storage.objectCreator $BUCKET_URI\n",
|
||||
"\n",
|
||||
"! gsutil iam ch serviceAccount:{SERVICE_ACCOUNT}:roles/storage.objectViewer $BUCKET_URI"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
@@ -834,6 +912,7 @@
|
||||
"\n",
|
||||
"job.run()\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"pipeline_task_details = job.gca_resource.job_detail.task_details\n",
|
||||
"\n",
|
||||
"if export_additional_model_without_custom_ops:\n",
|
||||
@@ -875,6 +954,7 @@
|
||||
"stage_1_tuner_task = get_task_detail(\n",
|
||||
" pipeline_task_details, \"automl-tabular-stage-1-tuner\"\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"stage_1_tuning_result_artifact_uri = (\n",
|
||||
" stage_1_tuner_task.outputs[\"tuning_result_output\"].artifacts[0].uri\n",
|
||||
")"
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -63,7 +63,9 @@
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK to create image object detection models and do batch prediction using a Google Cloud [AutoML](https://cloud.google.com/vertex-ai/docs/start/automl-users) model."
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK to create image object detection models and do batch prediction using a Google Cloud [AutoML](https://cloud.google.com/vertex-ai/docs/start/automl-users) model.\n",
|
||||
"\n",
|
||||
"Learn more about [Object detection for image data](https://cloud.google.com/vertex-ai/docs/training-overview#object_detection_for_images)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -62,7 +62,9 @@
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK to create tabular forecasting models and do batch prediction using a Google Cloud [AutoML](https://cloud.google.com/vertex-ai/docs/start/automl-users) model."
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK to create tabular forecasting models and do batch prediction using a Google Cloud [AutoML](https://cloud.google.com/vertex-ai/docs/start/automl-users) model.\n",
|
||||
"\n",
|
||||
"Learn more about [Forecasting for tabular data](https://cloud.google.com/vertex-ai/docs/tabular-data/forecasting/overview)."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -831,6 +833,7 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "99b7a9287ba6"
|
||||
@@ -838,7 +841,7 @@
|
||||
"source": [
|
||||
"For AutoML models, manual scaling can be adjusted by setting both min and max nodes i.e., `starting_replica_count` and `max_replica_count` as the same value(in this example, set to 1). The node count can be increased or decreased as required by load.\n",
|
||||
" \n",
|
||||
"`batch_predict` can export predictions either to BigQuery or GCS. The BigQuery options are commented out below and the predictions will be exported to the BUCKET_URI."
|
||||
"`batch_predict` can export predictions either to BigQuery or GCS. This example exports to BigQuery."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -61,7 +61,9 @@
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK for Python to create tabular regression models and do batch prediction using a Google Cloud [AutoML](https://cloud.google.com/vertex-ai/docs/start/automl-users) model."
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK for Python to create tabular regression models and do batch prediction using a Google Cloud [AutoML](https://cloud.google.com/vertex-ai/docs/start/automl-users) model.\n",
|
||||
"\n",
|
||||
"Learn more about [Regression for tabular data](https://cloud.google.com/vertex-ai/docs/tabular-data/classification-regression/overview)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -62,7 +62,9 @@
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK for Python to create tabular regression models and do online prediction using a Google Cloud [AutoML](https://cloud.google.com/vertex-ai/docs/start/automl-users) model."
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK for Python to create tabular regression models and do online prediction using a Google Cloud [AutoML](https://cloud.google.com/vertex-ai/docs/start/automl-users) model.\n",
|
||||
"\n",
|
||||
"Learn more about [Regression for tabular data](https://cloud.google.com/vertex-ai/docs/tabular-data/classification-regression/overview)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -62,7 +62,9 @@
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK for Python to create text entity extraction models and do online prediction using a Google Cloud [AutoML](https://cloud.google.com/vertex-ai/docs/start/automl-users) model."
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK for Python to create text entity extraction models and do online prediction using a Google Cloud [AutoML](https://cloud.google.com/vertex-ai/docs/start/automl-users) model.\n",
|
||||
"\n",
|
||||
"Learn more about [Entity extraction for text data](https://cloud.google.com/vertex-ai/docs/training-overview#entity_extraction_for_text)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -61,7 +61,9 @@
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK to train and deploy an [AutoML](https://cloud.google.com/vertex-ai/docs/start/automl-users) text sentiment analysis model and get online predictions from it."
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK to train and deploy an [AutoML](https://cloud.google.com/vertex-ai/docs/start/automl-users) text sentiment analysis model and get online predictions from it.\n",
|
||||
"\n",
|
||||
"Learn more about [Sentiment analysis for text data](https://cloud.google.com/vertex-ai/docs/training-overview#sentiment_analysis_for_text)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -63,7 +63,9 @@
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK to create video action recognition models and do batch prediction using a Google Cloud [AutoML](https://cloud.google.com/vertex-ai/docs/start/automl-users) model."
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK to create video action recognition models and do batch prediction using a Google Cloud [AutoML](https://cloud.google.com/vertex-ai/docs/start/automl-users) model.\n",
|
||||
"\n",
|
||||
"Learn more about [Action recognition for video data](https://cloud.google.com/vertex-ai/docs/training-overview#action_recognition_for_videos)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -62,7 +62,9 @@
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK to create video classification models and do batch prediction using a Google Cloud [AutoML](https://cloud.google.com/vertex-ai/docs/start/automl-users) model."
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK to create video classification models and do batch prediction using a Google Cloud [AutoML](https://cloud.google.com/vertex-ai/docs/start/automl-users) model.\n",
|
||||
"\n",
|
||||
"Learn more about [Classification for video data](https://cloud.google.com/vertex-ai/docs/training-overview#classification_for_videos)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -62,7 +62,9 @@
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK for Python to create video object tracking models and do batch prediction using a Google Cloud [AutoML](https://cloud.google.com/vertex-ai/docs/start/automl-users) model."
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK for Python to create video object tracking models and do batch prediction using a Google Cloud [AutoML](https://cloud.google.com/vertex-ai/docs/start/automl-users) model.\n",
|
||||
"\n",
|
||||
"Learn more about [Object tracking for video data](https://cloud.google.com/vertex-ai/docs/training-overview#object_tracking_for_videos)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
[Online prediction with BigQuery ML](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/bigquery_ml/bqml-online-prediction.ipynb)
|
||||
|
||||
```
|
||||
@@ -14,3 +15,25 @@ The steps performed include:
|
||||
|
||||
```
|
||||
|
||||
Learn more about [BigQuery ML](https://cloud.google.com/vertex-ai/docs/beginner/bqml).
|
||||
|
||||
|
||||
[Get started with BigQuery ML Training](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/bigquery_ml/get_started_with_bqml_training.ipynb)
|
||||
|
||||
```
|
||||
Learn how to use `BigQueryML` for training with `Vertex AI`.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a local BigQuery table in your project
|
||||
- Train a BigQuery ML model
|
||||
- Evaluate the BigQuery ML model
|
||||
- Export the BigQuery ML model as a cloud model
|
||||
- Upload the exported model as a `Vertex AI Model` resource
|
||||
- Hyperparameter tune a BigQuery ML model with `Vertex AI Vizier`
|
||||
- Automatically register a BigQuery ML model to `Vertex AI Model Registry`
|
||||
|
||||
```
|
||||
|
||||
Learn more about [BigQuery ML](https://cloud.google.com/vertex-ai/docs/beginner/bqml).
|
||||
|
||||
|
||||
@@ -61,7 +61,9 @@
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This notebook is aimed at data analysts and data scientists who have data in BigQuery, want to train a model using BigQuery ML, register the model to Vertex AI Model Registry, and deploy it to an endpoint for real-time prediction. "
|
||||
"This notebook is aimed at data analysts and data scientists who have data in BigQuery, want to train a model using BigQuery ML, register the model to Vertex AI Model Registry, and deploy it to an endpoint for real-time prediction. \n",
|
||||
"\n",
|
||||
"Learn more about [BigQuery ML](https://cloud.google.com/vertex-ai/docs/beginner/bqml)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,24 @@
|
||||
|
||||
[Deploying Iris-detection model using FastAPI and Vertex AI custom container serving](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/custom/SDK_Custom_Container_Prediction.ipynb)
|
||||
|
||||
```
|
||||
Learn how to create, deploy and serve a custom classification model on Vertex AI.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Train a model that uses flower's measurements as input to predict the class of iris.
|
||||
- Save the model and its serialized pre-processor.
|
||||
- Build a FastAPI server to handle predictions and health checks.
|
||||
- Build a custom container with model artifacts.
|
||||
- Upload and deploy custom container to Vertex AI Endpoints.
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Custom training](https://cloud.google.com/vertex-ai/docs/training/custom-training).
|
||||
|
||||
Learn more about [Vertex AI Prediction](https://cloud.google.com/vertex-ai/docs/predictions/get-predictions).
|
||||
|
||||
|
||||
[Training and deploying a sales forecasting model using FBProphet and Vertex AI](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/custom/SDK_FBProphet_Forecasting_Online.ipynb)
|
||||
|
||||
```
|
||||
@@ -16,34 +37,9 @@ The steps performed include:
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Custom training](https://cloud.google.com/vertex-ai/docs/training/custom-training).
|
||||
|
||||
[Custom training and batch prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/custom/sdk-custom-image-classification-batch.ipynb)
|
||||
|
||||
```
|
||||
Learn to use `Vertex AI Training` to create a custom trained model and use `Vertex AI Batch Prediction` to do a batch prediction on the trained model.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a `Vertex AI` custom job for training a TensorFlow model.
|
||||
- Upload the trained model artifacts as a `Model` resource.
|
||||
- Make a batch prediction.
|
||||
|
||||
```
|
||||
|
||||
|
||||
[Profile model training performance using Profiler](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/custom/custom_training_tensorboard_profiler.ipynb)
|
||||
|
||||
```
|
||||
Learn how to enable Vertex AI TensorBoard Profiler for custom training jobs.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Setup a service account and a Cloud Storage bucket
|
||||
- Create a TensorBoard instance
|
||||
- Create and run a custom training job
|
||||
- View the TensorBoard Profiler dashboard
|
||||
|
||||
```
|
||||
Learn more about [Vertex AI Prediction](https://cloud.google.com/vertex-ai/docs/predictions/get-predictions).
|
||||
|
||||
|
||||
[Training a TensorFlow model on BigQuery data](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/custom/custom-tabular-bq-managed-dataset.ipynb)
|
||||
@@ -61,6 +57,43 @@ The steps performed include:
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Vertex AI Training](https://cloud.google.com/vertex-ai/docs/training/custom-training).
|
||||
|
||||
|
||||
[Profile model training performance using Profiler](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/custom/custom_training_tensorboard_profiler.ipynb)
|
||||
|
||||
```
|
||||
Learn how to enable Vertex AI TensorBoard Profiler for custom training jobs.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Setup a service account and a Cloud Storage bucket
|
||||
- Create a TensorBoard instance
|
||||
- Create and run a custom training job
|
||||
- View the TensorBoard Profiler dashboard
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Vertex AI TensorBoard Profiler](https://cloud.google.com/vertex-ai/docs/experiments/tensorboard-profiler).
|
||||
|
||||
|
||||
[Custom training and batch prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/custom/sdk-custom-image-classification-batch.ipynb)
|
||||
|
||||
```
|
||||
Learn to use `Vertex AI Training` to create a custom trained model and use `Vertex AI Batch Prediction` to do a batch prediction on the trained model.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a `Vertex AI` custom job for training a TensorFlow model.
|
||||
- Upload the trained model artifacts as a `Model` resource.
|
||||
- Make a batch prediction.
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Custom training](https://cloud.google.com/vertex-ai/docs/training/custom-training).
|
||||
|
||||
Learn more about [Vertex AI Batch Prediction](https://cloud.google.com/vertex-ai/docs/tabular-data/classification-regression/get-batch-predictions).
|
||||
|
||||
|
||||
[Custom training and online prediction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/custom/sdk-custom-image-classification-online.ipynb)
|
||||
|
||||
@@ -78,19 +111,7 @@ The steps performed include:
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Custom training](https://cloud.google.com/vertex-ai/docs/training/custom-training).
|
||||
|
||||
[Deploying Iris-detection model using FastAPI and Vertex AI custom container serving](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/custom/SDK_Custom_Container_Prediction.ipynb)
|
||||
|
||||
```
|
||||
Learn how to create, deploy and serve a custom classification model on Vertex AI.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Train a model that uses flower's measurements as input to predict the class of iris.
|
||||
- Save the model and its serialized pre-processor.
|
||||
- Build a FastAPI server to handle predictions and health checks.
|
||||
- Build a custom container with model artifacts.
|
||||
- Upload and deploy custom container to Vertex AI Endpoints.
|
||||
|
||||
```
|
||||
Learn more about [Vertex AI Prediction](https://cloud.google.com/vertex-ai/docs/predictions/get-predictions).
|
||||
|
||||
|
||||
@@ -58,7 +58,9 @@
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This tutorial walks you through building a custom container to serve a scikit-learn model on Vertex AI. You use the FastAPI Python web server framework to create a prediction and health endpoint. You also incorporate a pre-processor from training pipeline into your online serving application."
|
||||
"This tutorial walks you through building a custom container to serve a scikit-learn model on Vertex AI. You use the FastAPI Python web server framework to create a prediction and health endpoint. You also incorporate a pre-processor from training pipeline into your online serving application.\n",
|
||||
"\n",
|
||||
"Learn more about [Custom training](https://cloud.google.com/vertex-ai/docs/training/custom-training) and [Vertex AI Prediction](https://cloud.google.com/vertex-ai/docs/predictions/get-predictions)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -62,7 +62,9 @@
|
||||
"\n",
|
||||
"This tutorial walks you through building a custom container to serve a facebook prophet model on Vertex AI. You use the FastAPI Python web server framework to create a prediction endpoint. This notebook is a modified version of an example on [serving a scikit-learn model on Vertex AI](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/sdk/SDK_Custom_Container_Prediction.ipynb).\n",
|
||||
"\n",
|
||||
"Learn more about serving an FBProphet model from this [article on testdriven.io: Deploying and Hosting a Machine Learning Model with FastAPI and Heroku](https://testdriven.io/blog/fastapi-machine-learning/).\n"
|
||||
"Learn more about serving an FBProphet model from this [article on testdriven.io: Deploying and Hosting a Machine Learning Model with FastAPI and Heroku](https://testdriven.io/blog/fastapi-machine-learning/).\n",
|
||||
"\n",
|
||||
"Learn more about [Custom training](https://cloud.google.com/vertex-ai/docs/training/custom-training) and [Vertex AI Prediction](https://cloud.google.com/vertex-ai/docs/predictions/get-predictions).\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -61,7 +61,9 @@
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK for Python to train and deploy a custom tabular classification model for online prediction."
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK for Python to train and deploy a custom tabular classification model for online prediction.\n",
|
||||
"\n",
|
||||
"Learn more about [Vertex AI Training](https://cloud.google.com/vertex-ai/docs/training/custom-training)."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -145,8 +147,7 @@
|
||||
"# Install the packages\n",
|
||||
"! pip3 install --upgrade google-cloud-aiplatform \\\n",
|
||||
" google-cloud-storage \\\n",
|
||||
" google-cloud-bigquery \\\n",
|
||||
" pyarrow"
|
||||
" 'google-cloud-bigquery[pandas]'"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -630,12 +631,12 @@
|
||||
" df_train_x, df_train_y = df_train, df_train.pop(LABEL_COLUMN)\n",
|
||||
" df_validation_x, df_validation_y = df_validation, df_validation.pop(LABEL_COLUMN)\n",
|
||||
"\n",
|
||||
" y_train = np.asarray(df_train_y).astype(\"float32\")\n",
|
||||
" y_validation = np.asarray(df_validation_y).astype(\"float32\")\n",
|
||||
" y_train = tf.convert_to_tensor(np.asarray(df_train_y).astype(\"float32\"))\n",
|
||||
" y_validation = tf.convert_to_tensor(np.asarray(df_validation_y).astype(\"float32\"))\n",
|
||||
"\n",
|
||||
" # Convert to numpy representation\n",
|
||||
" x_train = np.asarray(df_train_x) \n",
|
||||
" x_test = np.asarray(df_validation_x)\n",
|
||||
" x_train = tf.convert_to_tensor(np.asarray(df_train_x).astype(\"float32\"))\n",
|
||||
" x_test = tf.convert_to_tensor(np.asarray(df_validation_x).astype(\"float32\"))\n",
|
||||
"\n",
|
||||
" # Convert to one-hot representation\n",
|
||||
" num_species = len(df_train_y.unique())\n",
|
||||
@@ -733,7 +734,7 @@
|
||||
" display_name=JOB_NAME,\n",
|
||||
" script_path=\"task.py\",\n",
|
||||
" container_uri=\"us-docker.pkg.dev/vertex-ai/training/tf-cpu.2-8:latest\",\n",
|
||||
" requirements=[\"google-cloud-bigquery>=2.20.0\", \"db-dtypes\"],\n",
|
||||
" requirements=[\"google-cloud-bigquery[pandas]\", \"protobuf<3.20.0\"],\n",
|
||||
" model_serving_container_image_uri=\"us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-8:latest\",\n",
|
||||
")\n",
|
||||
"\n",
|
||||
|
||||
@@ -61,7 +61,9 @@
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"Vertex AI TensorBoard Profiler lets you monitor and optimize your model training performance by helping you understand the resource consumption of training operations. This tutorial demonstrates how to enable Vertex AI TensorBoard Profiler so you can debug model training performance for your custom training jobs.\n"
|
||||
"Vertex AI TensorBoard Profiler lets you monitor and optimize your model training performance by helping you understand the resource consumption of training operations. This tutorial demonstrates how to enable Vertex AI TensorBoard Profiler so you can debug model training performance for your custom training jobs.\n",
|
||||
"\n",
|
||||
"Learn more about [Vertex AI TensorBoard Profiler](https://cloud.google.com/vertex-ai/docs/experiments/tensorboard-profiler)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -62,7 +62,9 @@
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK for Python to train and deploy a custom image classification model for batch prediction."
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK for Python to train and deploy a custom image classification model for batch prediction.\n",
|
||||
"\n",
|
||||
"Learn more about [Custom training](https://cloud.google.com/vertex-ai/docs/training/custom-training) and [Vertex AI Batch Prediction](https://cloud.google.com/vertex-ai/docs/tabular-data/classification-regression/get-batch-predictions)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -62,7 +62,9 @@
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK for Python to train and deploy a custom image classification model for online prediction."
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK for Python to train and deploy a custom image classification model for online prediction.\n",
|
||||
"\n",
|
||||
"Learn more about [Custom training](https://cloud.google.com/vertex-ai/docs/training/custom-training) and [Vertex AI Prediction](https://cloud.google.com/vertex-ai/docs/predictions/get-predictions)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
|
||||
[Get started with BigQuery datasets](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/datasets/get_started_bq_datasets.ipynb)
|
||||
|
||||
```
|
||||
Learn how to use `BigQuery` as a dataset for training with `Vertex AI`.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a Vertex AI `Dataset` resource from `BigQuery` table -- compatible for `AutoML` training.
|
||||
- Extract a copy of the dataset from `BigQuery` to a CSV file in Cloud Storage -- compatible for `AutoML` or custom training.
|
||||
- Select rows from a `BigQuery` dataset into a `pandas` dataframe -- compatible for custom training.
|
||||
- Select rows from a `BigQuery` dataset into a `tf.data.Dataset` -- compatible for custom training `TensorFlow` models.
|
||||
- Select rows from extracted CSV files into a `tf.data.Dataset` -- compatible for custom training `TensorFlow` models.
|
||||
- Create a `BigQuery` dataset from CSV files.
|
||||
- Extract data from `BigQuery` table into a `DMatrix` -- compatible for custom training `XGBoost` models.
|
||||
|
||||
```
|
||||
|
||||
Learn more about [BigQuery Datasets](https://cloud.google.com/bigquery/docs/datasets-intro).
|
||||
|
||||
|
||||
[Get started with Vertex AI Data Labeling](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/datasets/get_started_with_data_labeling.ipynb)
|
||||
|
||||
```
|
||||
Learn how to use the `Vertex AI Data Labeling` service.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a Specialist Pool for data labelers.
|
||||
- Create a data labeling job.
|
||||
- Submit the data labeling job.
|
||||
- List data labeling jobs.
|
||||
- Cancel a data labeling job.
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Vertex AI Data Labeling](https://cloud.google.com/vertex-ai/docs/datasets/data-labeling-job).
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,17 +1,25 @@
|
||||
[Compare pipeline runs with Vertex AI Experiments](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/experiments/comparing_pipeline_runs.ipynb)
|
||||
|
||||
[Build Vertex AI Experiment lineage for custom training](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/experiments/build_model_experimentation_lineage_with_prebuild_code.ipynb)
|
||||
|
||||
```
|
||||
Learn how to use `Vertex AI Experiments` to log a pipeline job and compare different pipeline jobs.
|
||||
Learn how to integrate preprocessing code in a Vertex AI experiments.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
* Formalize a training component
|
||||
* Build a training pipeline
|
||||
* Run several Pipeline jobs and log their results
|
||||
* Compare different Pipeline jobs
|
||||
- Execute module for preprocessing data
|
||||
- Create a dataset artifact
|
||||
- Log parameters
|
||||
- Execute module for training the model
|
||||
- Log parameters
|
||||
- Create model artifact
|
||||
- Assign tracking lineage to dataset, model and parameters
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Vertex AI Experiments](https://cloud.google.com/vertex-ai/docs/experiments/intro-vertex-ai-experiments).
|
||||
|
||||
Learn more about [Vertex ML Metadata](https://cloud.google.com/vertex-ai/docs/ml-metadata).
|
||||
|
||||
|
||||
[Track parameters and metrics for locally trained models](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/experiments/comparing_local_trained_models.ipynb)
|
||||
|
||||
@@ -26,13 +34,57 @@ The steps performed include:
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Vertex AI Experiments](https://cloud.google.com/vertex-ai/docs/experiments/intro-vertex-ai-experiments).
|
||||
|
||||
[Build Vertex AI Experiment lineage for custom training](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/experiments/build_model_experimentation_lineage_with_prebuild_code.ipynb)
|
||||
|
||||
[Compare pipeline runs with Vertex AI Experiments](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/experiments/comparing_pipeline_runs.ipynb)
|
||||
|
||||
```
|
||||
Learn how to integrate preprocessing code in a Vertex AI experiments.
|
||||
Learn how to use `Vertex AI Experiments` to log a pipeline job and compare different pipeline jobs.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
* Formalize a training component
|
||||
* Build a training pipeline
|
||||
* Run several Pipeline jobs and log their results
|
||||
* Compare different Pipeline jobs
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Vertex AI Experiments](https://cloud.google.com/vertex-ai/docs/experiments/intro-vertex-ai-experiments).
|
||||
|
||||
Learn more about [Vertex AI Pipelines](https://cloud.google.com/vertex-ai/docs/pipelines/introduction).
|
||||
|
||||
|
||||
[Get started with Vertex AI Experiments](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/experiments/get_started_with_vertex_experiments.ipynb)
|
||||
|
||||
```
|
||||
Learn how to use `Vertex AI Experiments` when training with `Vertex AI`.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Local (notebook) Training
|
||||
- Create an experiment
|
||||
- Create a first run in the experiment
|
||||
- Log parameters and metrics
|
||||
- Create artifact lineage
|
||||
- Visualize the experiment results
|
||||
- Execute a second run
|
||||
- Compare the two runs in the experiment
|
||||
- Cloud (`Vertex AI`) Training
|
||||
- Within the training script:
|
||||
- Create an experiment
|
||||
- Log parameters and metrics
|
||||
- Create artifact lineage
|
||||
- Create a `Vertex AI Training` custom job
|
||||
- Execute the custom job
|
||||
- Visualize the experiment results
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Vertex AI Experiments](https://cloud.google.com/vertex-ai/docs/experiments/intro-vertex-ai-experiments).
|
||||
|
||||
Learn more about [Vertex ML Metadata](https://cloud.google.com/vertex-ai/docs/ml-metadata).
|
||||
|
||||
Learn more about [Custom training](https://cloud.google.com/vertex-ai/docs/training/custom-training).
|
||||
|
||||
|
||||
+3
-1
@@ -61,7 +61,9 @@
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"As a Data Scientist, you want to be able to reuse code path (data preprocessing, feature engineering etc...) that others within your team have written to simplify and standardize all the complex data wrangling. "
|
||||
"As a Data Scientist, you want to be able to reuse code path (data preprocessing, feature engineering etc...) that others within your team have written to simplify and standardize all the complex data wrangling. \n",
|
||||
"\n",
|
||||
"Learn more about [Vertex AI Experiments](https://cloud.google.com/vertex-ai/docs/experiments/intro-vertex-ai-experiments) and [Vertex ML Metadata](https://cloud.google.com/vertex-ai/docs/ml-metadata)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -61,7 +61,9 @@
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"As a Data Scientist, you probably start running model experiments locally on your notebook. Depending on the framework you use, you would need to track parameters, training time series and evaluation metrics. In this way, you would be able to explain the modelling approach you would choose. \n"
|
||||
"As a Data Scientist, you probably start running model experiments locally on your notebook. Depending on the framework you use, you would need to track parameters, training time series and evaluation metrics. In this way, you would be able to explain the modelling approach you would choose. \n",
|
||||
"\n",
|
||||
"Learn more about [Vertex AI Experiments](https://cloud.google.com/vertex-ai/docs/experiments/intro-vertex-ai-experiments)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -61,7 +61,9 @@
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"Depending on the model life cycle of your data science team, you would like to experiment and track training pipeline runs and its associated parameters. Then, you would to compare runs of these Pipelines to each others in order to figure out which is the best configuration generates the model you will register in the Vertex AI Model Registry."
|
||||
"Depending on the model life cycle of your data science team, you would like to experiment and track training pipeline runs and its associated parameters. Then, you would to compare runs of these Pipelines to each others in order to figure out which is the best configuration generates the model you will register in the Vertex AI Model Registry.\n",
|
||||
"\n",
|
||||
"Learn more about [Vertex AI Experiments](https://cloud.google.com/vertex-ai/docs/experiments/intro-vertex-ai-experiments) and [Vertex AI Pipelines](https://cloud.google.com/vertex-ai/docs/pipelines/introduction)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+1224
File diff suppressed because it is too large
Load Diff
@@ -1,18 +1,3 @@
|
||||
[Custom training tabular regression model for batch prediction with explainabilty](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_custom_tabular_regression_batch_explain.ipynb)
|
||||
|
||||
```
|
||||
Learn how to use `Vertex AI Training and Explainable AI` to create a custom image classification model with explanations, and then you learn to use `Vertex AI Batch Prediction` to make a batch prediction request with explanations.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a `Vertex AI` custom job for training a TensorFlow model.
|
||||
- View the model evaluation for the trained model.
|
||||
- Set explanation parameters for when the model is deployed.
|
||||
- Upload the trained model artifacts and explanations as a `Model` resource.
|
||||
- Make a batch prediction with explanations.
|
||||
|
||||
```
|
||||
|
||||
|
||||
[AutoML training tabular binary classification model for batch explanation](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_automl_tabular_binary_classification_batch_explain.ipynb)
|
||||
|
||||
@@ -28,6 +13,10 @@ The steps performed include:
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Classification for tabular data](https://cloud.google.com/vertex-ai/docs/tabular-data/classification-regression/overview).
|
||||
|
||||
Learn more about [Vertex Explainable AI](https://cloud.google.com/vertex-ai/docs/explainable-ai/overview).
|
||||
|
||||
|
||||
[AutoML training tabular classification model for online explanation](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_automl_tabular_classification_online_explain.ipynb)
|
||||
|
||||
@@ -46,6 +35,30 @@ The steps performed include:
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Classification for tabular data](https://cloud.google.com/vertex-ai/docs/tabular-data/classification-regression/overview).
|
||||
|
||||
Learn more about [Vertex Explainable AI](https://cloud.google.com/vertex-ai/docs/explainable-ai/overview).
|
||||
|
||||
|
||||
[Custom training image classification model for batch prediction with explainabilty](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_custom_image_classification_batch_explain.ipynb)
|
||||
|
||||
```
|
||||
Learn to use `Vertex AI Training and Explainable AI` to create a custom image classification model with explanations, and then you learn to use `Vertex AI Batch Prediction` to make a batch prediction request with explanations.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a `Vertex AI` custom job for training a TensorFlow model.
|
||||
- View the model evaluation for the trained model.
|
||||
- Set explanation parameters for when the model is deployed.
|
||||
- Upload the trained model artifacts and explanation parameters as a `Model` resource.
|
||||
- Make a batch prediction with explanations.
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Vertex Explainable AI](https://cloud.google.com/vertex-ai/docs/explainable-ai/overview).
|
||||
|
||||
Learn more about [Vertex AI Batch Prediction](https://cloud.google.com/vertex-ai/docs/tabular-data/classification-regression/get-batch-predictions).
|
||||
|
||||
|
||||
[Custom training image classification model for online prediction with explainabilty](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_custom_image_classification_online_explain.ipynb)
|
||||
|
||||
@@ -65,6 +78,30 @@ The steps performed include:
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Vertex Explainable AI](https://cloud.google.com/vertex-ai/docs/explainable-ai/overview).
|
||||
|
||||
Learn more about [Vertex AI Prediction](https://cloud.google.com/vertex-ai/docs/predictions/get-predictions).
|
||||
|
||||
|
||||
[Custom training tabular regression model for batch prediction with explainabilty](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_custom_tabular_regression_batch_explain.ipynb)
|
||||
|
||||
```
|
||||
Learn how to use `Vertex AI Training and Explainable AI` to create a custom image classification model with explanations, and then you learn to use `Vertex AI Batch Prediction` to make a batch prediction request with explanations.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a `Vertex AI` custom job for training a TensorFlow model.
|
||||
- View the model evaluation for the trained model.
|
||||
- Set explanation parameters for when the model is deployed.
|
||||
- Upload the trained model artifacts and explanations as a `Model` resource.
|
||||
- Make a batch prediction with explanations.
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Vertex Explainable AI](https://cloud.google.com/vertex-ai/docs/explainable-ai/overview).
|
||||
|
||||
Learn more about [Vertex AI Batch Prediction](https://cloud.google.com/vertex-ai/docs/tabular-data/classification-regression/get-batch-predictions).
|
||||
|
||||
|
||||
[Custom training tabular regression model for online prediction with explainabilty](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_custom_tabular_regression_online_explain.ipynb)
|
||||
|
||||
@@ -84,11 +121,15 @@ The steps performed include:
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Vertex Explainable AI](https://cloud.google.com/vertex-ai/docs/explainable-ai/overview).
|
||||
|
||||
Learn more about [Vertex AI Prediction](https://cloud.google.com/vertex-ai/docs/predictions/get-predictions).
|
||||
|
||||
|
||||
[Custom training tabular regression model for online prediction with explainabilty using get_metadata](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_custom_tabular_regression_online_explain_get_metadata.ipynb)
|
||||
|
||||
```
|
||||
Learn how to create a custom model from a Python script in a Google prebuilt Docker container using the Vertex SDK, and then do a prediction with explanations on the deployed model by sending data.
|
||||
Learn how to create a custom model from a Python script in a Google prebuilt Docker container using the Vertex AI SDK, and then do a prediction with explanations on the deployed model by sending data.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
@@ -104,19 +145,27 @@ The steps performed include:
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Vertex Explainable AI](https://cloud.google.com/vertex-ai/docs/explainable-ai/overview).
|
||||
|
||||
[Custom training image classification model for batch prediction with explainabilty](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/sdk_custom_image_classification_batch_explain.ipynb)
|
||||
Learn more about [Vertex AI Prediction](https://cloud.google.com/vertex-ai/docs/predictions/get-predictions).
|
||||
|
||||
|
||||
[Explaining image classification with Vertex Explainable AI](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/explainable_ai/xai_image_classification_feature_attributions.ipynb)
|
||||
|
||||
```
|
||||
Learn to use `Vertex AI Training and Explainable AI` to create a custom image classification model with explanations, and then you learn to use `Vertex AI Batch Prediction` to make a batch prediction request with explanations.
|
||||
Learn how to configure feature-based explanations on a pre-trained image classification model and make online and batch predictions with explanations.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a `Vertex AI` custom job for training a TensorFlow model.
|
||||
- View the model evaluation for the trained model.
|
||||
- Set explanation parameters for when the model is deployed.
|
||||
- Upload the trained model artifacts and explanation parameters as a `Model` resource.
|
||||
- Make a batch prediction with explanations.
|
||||
- Download pretrained model from TensorFlow Hub
|
||||
- Upload model for deployment
|
||||
- Deploy model for online prediction
|
||||
- Make online prediction with explanations
|
||||
- Make batch predictions with explanations
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Vertex Explainable AI](https://cloud.google.com/vertex-ai/docs/explainable-ai/overview).
|
||||
|
||||
Learn more about [Vertex AI Prediction](https://cloud.google.com/vertex-ai/docs/predictions/get-predictions).
|
||||
|
||||
|
||||
+3
-1
@@ -62,7 +62,9 @@
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK to create tabular binary classification models and do batch prediction with explanation using a Google Cloud [AutoML](https://cloud.google.com/vertex-ai/docs/start/automl-users) model."
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK to create tabular binary classification models and do batch prediction with explanation using a Google Cloud [AutoML](https://cloud.google.com/vertex-ai/docs/start/automl-users) model.\n",
|
||||
"\n",
|
||||
"Learn more about [Classification for tabular data](https://cloud.google.com/vertex-ai/docs/tabular-data/classification-regression/overview). Learn more about [Vertex Explainable AI](https://cloud.google.com/vertex-ai/docs/explainable-ai/overview)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
+3
-1
@@ -62,7 +62,9 @@
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK to create tabular classification models and do online prediction with explanation using a Google Cloud [AutoML](https://cloud.google.com/vertex-ai/docs/start/automl-users) model."
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK to create tabular classification models and do online prediction with explanation using a Google Cloud [AutoML](https://cloud.google.com/vertex-ai/docs/start/automl-users) model.\n",
|
||||
"\n",
|
||||
"Learn more about [Classification for tabular data](https://cloud.google.com/vertex-ai/docs/tabular-data/classification-regression/overview) and [Vertex Explainable AI](https://cloud.google.com/vertex-ai/docs/explainable-ai/overview)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
+3
-1
@@ -62,7 +62,9 @@
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK to train and deploy a custom image classification model for batch prediction with explanation."
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK to train and deploy a custom image classification model for batch prediction with explanation.\n",
|
||||
"\n",
|
||||
"Learn more about [Vertex Explainable AI](https://cloud.google.com/vertex-ai/docs/explainable-ai/overview) and [Vertex AI Batch Prediction](https://cloud.google.com/vertex-ai/docs/tabular-data/classification-regression/get-batch-predictions)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
+4
-2
@@ -29,7 +29,7 @@
|
||||
"id": "title"
|
||||
},
|
||||
"source": [
|
||||
"# Vertex SDK: Custom training image classification model for online prediction with explainabilty\n",
|
||||
"# Vertex SDK: Custom training image classification model for online prediction with explainability\n",
|
||||
"\n",
|
||||
"<table align=\"left\">\n",
|
||||
" <td>\n",
|
||||
@@ -62,7 +62,9 @@
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK to train and deploy a custom image classification model for online prediction with explanation."
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK to train and deploy a custom image classification model for online prediction with explanation.\n",
|
||||
"\n",
|
||||
"Learn more about [Vertex Explainable AI](https://cloud.google.com/vertex-ai/docs/explainable-ai/overview) and [Vertex AI Prediction](https://cloud.google.com/vertex-ai/docs/predictions/get-predictions)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -62,7 +62,9 @@
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK to train and deploy a custom tabular regression model for batch prediction with explanation."
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK to train and deploy a custom tabular regression model for batch prediction with explanation.\n",
|
||||
"\n",
|
||||
"Learn more about [Vertex Explainable AI](https://cloud.google.com/vertex-ai/docs/explainable-ai/overview) and [Vertex AI Batch Prediction](https://cloud.google.com/vertex-ai/docs/tabular-data/classification-regression/get-batch-predictions)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
+5
-3
@@ -62,7 +62,9 @@
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK to train and deploy a custom tabular regression model for online prediction with explanation."
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK to train and deploy a custom tabular regression model for online prediction with explanation.\n",
|
||||
"\n",
|
||||
"Learn more about [Vertex Explainable AI](https://cloud.google.com/vertex-ai/docs/explainable-ai/overview) and [Vertex AI Prediction](https://cloud.google.com/vertex-ai/docs/predictions/get-predictions)."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -861,8 +863,8 @@
|
||||
" )\n",
|
||||
" params = []\n",
|
||||
" for _ in range(13):\n",
|
||||
" x_train[_], max = scale(x_train[_])\n",
|
||||
" x_test[_], _ = scale(x_test[_])\n",
|
||||
" x_train[_], max = scale(x_train[_:_+1:])\n",
|
||||
" x_test[_], _ = scale(x_test[_:_+1:])\n",
|
||||
" params.append(max)\n",
|
||||
"\n",
|
||||
" # store the normalization (max) value for each feature\n",
|
||||
|
||||
+3
-1
@@ -62,7 +62,9 @@
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK to train and deploy a custom tabular regression model for online prediction with explanation."
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK to train and deploy a custom tabular regression model for online prediction with explanation.\n",
|
||||
"\n",
|
||||
"Learn more about [Vertex Explainable AI](https://cloud.google.com/vertex-ai/docs/explainable-ai/overview) and [Vertex AI Prediction](https://cloud.google.com/vertex-ai/docs/predictions/get-predictions)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
+1045
File diff suppressed because one or more lines are too long
@@ -1,3 +1,20 @@
|
||||
|
||||
[Streaming ingestion SDK](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/feature_store/feature_store_streaming_ingestion_sdk.ipynb)
|
||||
|
||||
```
|
||||
Learn how to ingest features from a `Pandas DataFrame` into your Vertex AI Feature Store using `write_feature_values` method from the Vertex AI SDK.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create `Feature Store`
|
||||
- Create new `Entity Type` for your `Feature Store`
|
||||
- Ingest feature values from `Pandas DataFrame` into `Feature Store`'s `Entity Types`.
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Vertex AI Feature Store](https://cloud.google.com/vertex-ai/docs/featurestore).
|
||||
|
||||
|
||||
[Using Vertex AI Feature Store with Pandas Dataframe](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/feature_store/sdk-feature-store-pandas.ipynb)
|
||||
|
||||
```
|
||||
@@ -15,6 +32,8 @@ The steps performed include:
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Vertex AI Feature Store](https://cloud.google.com/vertex-ai/docs/featurestore).
|
||||
|
||||
|
||||
[Online and Batch predictions using Vertex AI Feature Store](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/feature_store/sdk-feature-store.ipynb)
|
||||
|
||||
@@ -27,6 +46,9 @@ The steps performed include:
|
||||
- Import feature data into `Vertex AI Feature Store` resource.
|
||||
- Serve online prediction requests using the imported features.
|
||||
- Access imported features in offline jobs, such as training jobs.
|
||||
- Use streaming ingestion to ingest small amount of data.
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Vertex AI Feature Store](https://cloud.google.com/vertex-ai/docs/featurestore).
|
||||
|
||||
|
||||
@@ -72,7 +72,9 @@
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This notebook demonstrates how to use Vertex AI Feature Store's streaming ingestion at the SDK layer."
|
||||
"This notebook demonstrates how to use Vertex AI Feature Store's streaming ingestion at the SDK layer.\n",
|
||||
"\n",
|
||||
"Learn more about [Vertex AI Feature Store](https://cloud.google.com/vertex-ai/docs/featurestore)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -62,7 +62,9 @@
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This notebook introduces Pandas support for Feature Store using Vertex AI SDK. For pre-requisites and introduction on Vertex AI SDK and Feature Store native support, please go through this [Colab notebook](https://colab.sandbox.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/feature_store/sdk-feature-store.ipynb). "
|
||||
"This notebook introduces Pandas support for Feature Store using Vertex AI SDK. For pre-requisites and introduction on Vertex AI SDK and Feature Store native support, please go through this [Colab notebook](https://colab.sandbox.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/feature_store/sdk-feature-store.ipynb). \n",
|
||||
"\n",
|
||||
"Learn more about [Vertex AI Feature Store](https://cloud.google.com/vertex-ai/docs/featurestore)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -62,7 +62,9 @@
|
||||
"\n",
|
||||
"This notebook introduces Vertex AI Feature Store, a managed cloud service for machine learning engineers and data scientists to store, serve, manage and share machine learning features at a large scale.\n",
|
||||
"\n",
|
||||
"This notebook assumes that you understand basic Google Cloud concepts such as [Project](https://cloud.google.com/storage/docs/projects), [Storage](https://cloud.google.com/storage) and [Vertex AI](https://cloud.google.com/vertex-ai/docs). Some machine learning knowledge is also helpful but not required.\n"
|
||||
"This notebook assumes that you understand basic Google Cloud concepts such as [Project](https://cloud.google.com/storage/docs/projects), [Storage](https://cloud.google.com/storage) and [Vertex AI](https://cloud.google.com/vertex-ai/docs). Some machine learning knowledge is also helpful but not required.\n",
|
||||
"\n",
|
||||
"Learn more about [Vertex AI Feature Store](https://cloud.google.com/vertex-ai/docs/featurestore)."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -84,7 +86,8 @@
|
||||
"- Create featurestore, entity type, and feature resources.\n",
|
||||
"- Import feature data into `Vertex AI Feature Store` resource.\n",
|
||||
"- Serve online prediction requests using the imported features.\n",
|
||||
"- Access imported features in offline jobs, such as training jobs."
|
||||
"- Access imported features in offline jobs, such as training jobs.\n",
|
||||
"- Use streaming ingestion to ingest small amount of data."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -185,7 +188,7 @@
|
||||
"source": [
|
||||
"## Installation\n",
|
||||
"\n",
|
||||
"Install the packages required for executing this notebook."
|
||||
"Install the packages required to execute this notebook."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -220,7 +223,7 @@
|
||||
"source": [
|
||||
"### Restart the kernel\n",
|
||||
"\n",
|
||||
"After you install the SDK, you need to restart the notebook kernel so it can find the packages. You can restart kernel from *Kernel -> Restart Kernel*, or running the following:"
|
||||
"After you install the SDK, you need to restart the notebook kernel so it can find the packages. You can restart kernel from *Kernel -> Restart Kernel*, or by running the following:"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -256,14 +259,14 @@
|
||||
"\n",
|
||||
"1. [Make sure that billing is enabled for your project](https://cloud.google.com/billing/docs/how-to/modify-project).\n",
|
||||
"\n",
|
||||
"1. [Enable the Vertex AI API and Compute Engine API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com,compute_component).\n",
|
||||
"1. [Enable the Vertex AI API and the Compute Engine API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com,compute_component).\n",
|
||||
"\n",
|
||||
"1. If you are running this notebook locally, you will need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
|
||||
"1. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk).\n",
|
||||
"\n",
|
||||
"1. Enter your project ID in the cell below. Then run the cell to make sure the\n",
|
||||
"1. Enter your project ID in the cell below, and then run the cell to make sure the\n",
|
||||
"Cloud SDK uses the right project for all the commands in this notebook.\n",
|
||||
"\n",
|
||||
"**Note**: Jupyter runs lines prefixed with `!` as shell commands, and it interpolates Python variables prefixed with `$` into these commands."
|
||||
"**Note**: Jupyter runs lines prefixed with `!` as shell commands, and interpolates Python variables prefixed with `$` into these commands."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -274,7 +277,7 @@
|
||||
"source": [
|
||||
"#### Set your project ID\n",
|
||||
"\n",
|
||||
"**If you don't know your project ID**, you may be able to get your project ID using `gcloud`."
|
||||
"**If you don't know your project ID**, you can get your project ID using `gcloud`."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -329,7 +332,7 @@
|
||||
"#### Region\n",
|
||||
"\n",
|
||||
"You can also change the `REGION` variable, which is used for operations\n",
|
||||
"throughout the rest of this notebook. Below are regions supported for Vertex AI. We recommend that you choose the region closest to you.\n",
|
||||
"throughout the rest of this notebook. The following regions are supported for Vertex AI. We recommend that you choose the region closest to you.\n",
|
||||
"\n",
|
||||
"- Americas: `us-central1`\n",
|
||||
"- Europe: `europe-west4`\n",
|
||||
@@ -361,7 +364,7 @@
|
||||
"source": [
|
||||
"#### UUID\n",
|
||||
"\n",
|
||||
"If you are in a live tutorial session, you might be using a shared test account or project. To avoid name collisions between users on resources created, you create a uuid for each instance session, and append it onto the name of resources you create in this tutorial."
|
||||
"If you are in a live tutorial session, you might be using a shared test account or project. To avoid name conflicts between users on resources created, you create a UUID for each instance session, and append it onto the name of resources you create in this tutorial."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -376,7 +379,7 @@
|
||||
"import string\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Generate a uuid of a specifed length(default=8)\n",
|
||||
"# Generate a UUID of a specifed length(default=8)\n",
|
||||
"def generate_uuid(length: int = 8) -> str:\n",
|
||||
" return \"\".join(random.choices(string.ascii_lowercase + string.digits, k=length))\n",
|
||||
"\n",
|
||||
@@ -452,7 +455,7 @@
|
||||
"\n",
|
||||
" google_auth.authenticate_user()\n",
|
||||
"\n",
|
||||
" # If you are running this notebook locally, replace the string below with the\n",
|
||||
" # If you are running this notebook locally, replace the following string with the\n",
|
||||
" # path to your service account key and run this cell to authenticate your GCP\n",
|
||||
" # account.\n",
|
||||
" elif not os.getenv(\"IS_TESTING\"):\n",
|
||||
@@ -489,19 +492,19 @@
|
||||
"id": "h_HmF24mBHv9"
|
||||
},
|
||||
"source": [
|
||||
"## Terminology and Concept\n",
|
||||
"## Terminology and concept\n",
|
||||
"\n",
|
||||
"### Featurestore Data model\n",
|
||||
"### Featurestore data model\n",
|
||||
"\n",
|
||||
"Vertex AI Feature Store organizes data with the following 3 important hierarchical concepts:\n",
|
||||
"```\n",
|
||||
"Featurestore -> Entity type -> Feature\n",
|
||||
"```\n",
|
||||
"* **Featurestore**: the place to store your features\n",
|
||||
"* **Entity type**: under a Featurestore, an Entity type describes an object to be modeled, real one or virtual one.\n",
|
||||
"* **Feature**: under an Entity type, a Feature describes an attribute of the Entity type\n",
|
||||
"* **Featurestore**: The place to store your features\n",
|
||||
"* **Entity type**: Under a featurestore, an entity type describes an object to be modeled, real one or virtual one.\n",
|
||||
"* **Feature**: Under an entity type, a feature describes an attribute of the entity type\n",
|
||||
"\n",
|
||||
"In the movie prediction example, you will create a featurestore called `movie_prediction`. This store has 2 entity types: `users` and `movies`. The `users` entity type has the `age`, `gender`, and `liked_genres` features. The `movies` entity type has the `titles`, `genres`, and `average rating` features.\n"
|
||||
"The movie prediction example lets you create a featurestore called `movie_prediction`. This store has 2 entity types. `users` and `movies`. The `users` entity type has the `age`, `gender`, and `liked_genres` features. The `movies` entity type has the `titles`, `genres`, and `average rating` features.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -510,7 +513,7 @@
|
||||
"id": "9UvxYyGUimKw"
|
||||
},
|
||||
"source": [
|
||||
"## Create Featurestore and Define Schemas"
|
||||
"## Create featurestore and define schemas"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -519,11 +522,11 @@
|
||||
"id": "buQBIv3ZL3A0"
|
||||
},
|
||||
"source": [
|
||||
"### Create Featurestore\n",
|
||||
"### Create featurestore\n",
|
||||
"\n",
|
||||
"The method to create a Featurestore returns a\n",
|
||||
"The method to create a featurestore returns a\n",
|
||||
"[long-running operation](https://google.aip.dev/151) (LRO). An LRO starts an asynchronous job. LROs are returned for other API\n",
|
||||
"methods too, such as updating or deleting a featurestore. Running the code cell will create a featurestore and print the process log."
|
||||
"methods too, such as updating or deleting a featurestore. Running the code cell creates a featurestore and print the process log."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -549,7 +552,7 @@
|
||||
"id": "ag8pCQ7rNjVf"
|
||||
},
|
||||
"source": [
|
||||
"Use the function call below to retrieve a Featurestore and check that it has been created.\n"
|
||||
"Use the following function call to retrieve a featurestore and check that it has been created.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -574,9 +577,9 @@
|
||||
"id": "EpmJq75zXjmT"
|
||||
},
|
||||
"source": [
|
||||
"### Create Entity Type\n",
|
||||
"### Create entity Type\n",
|
||||
"\n",
|
||||
"Entity types can be created within the Featurestore class. Below, create the Users entity type and Movies entity type. A process log will be printed out."
|
||||
"Entity types can be created within the `Featurestore` class. Below, create the `users` and `movies` entity types. A process log is printed out."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -587,7 +590,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Create users entity type\n",
|
||||
"# Create the `users` entity type\n",
|
||||
"users_entity_type = fs.create_entity_type(\n",
|
||||
" entity_type_id=\"users\",\n",
|
||||
" description=\"Users entity\",\n",
|
||||
@@ -602,7 +605,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Create movies entity type\n",
|
||||
"# Create the `movies` entity type\n",
|
||||
"movies_entity_type = fs.create_entity_type(\n",
|
||||
" entity_type_id=\"movies\",\n",
|
||||
" description=\"Movies entity\",\n",
|
||||
@@ -649,8 +652,8 @@
|
||||
"id": "FJW4q-0jO2Xf"
|
||||
},
|
||||
"source": [
|
||||
"### Create Feature\n",
|
||||
"Features can be created within each entity type. Add defining features to the Users entity type and Movies entity type by using the `create_feature` method."
|
||||
"### Create feature\n",
|
||||
"You can create features within each entity type. Use the `create_feature` method to add features to the `users` and `movies` entity types."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -661,7 +664,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# to create features one at a time use\n",
|
||||
"# To create one feature at a time, use:\n",
|
||||
"users_feature_age = users_entity_type.create_feature(\n",
|
||||
" feature_id=\"age\",\n",
|
||||
" value_type=\"INT64\",\n",
|
||||
@@ -687,7 +690,7 @@
|
||||
"id": "RQ9-AyFYBvcX"
|
||||
},
|
||||
"source": [
|
||||
"Use the [list_features](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/featurestore/entity_type.py#L349) method to list all the features of a given entity type."
|
||||
"Use the [`list_features`](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/featurestore/entity_type.py#L349) method to list all the features of a given entity type."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -746,12 +749,14 @@
|
||||
"source": [
|
||||
"## Search created features\n",
|
||||
"\n",
|
||||
"While the `list_features` method allows you to easily view all features of a single\n",
|
||||
"entity type, the [search](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/featurestore/feature.py#L352) method in the Feature class searches across all featurestores and entity types in a given location (such as `us-central1`), and returns a list of features. This can help you discover features that were created by someone else.\n",
|
||||
"While the `list_features` method lets you view all features for the same entity type,\n",
|
||||
"the [`search`](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/featurestore/feature.py#L352) method in the `Feature` class searches across all featurestores and entity types in a given location (such as `us-central1`) and returns a list of features. This lets you discover features created by someone else.\n",
|
||||
"\n",
|
||||
"You can query based on feature properties including feature ID, entity type ID, and feature description. You can also limit results by filtering on a specific featurestore, feature value type, and/or labels. Some search examples are shown below. \n",
|
||||
"You can query based on feature properties including feature ID, entity type ID, and feature description. You can also limit results by filtering based on a specific featurestore, feature value type, and/or label. Some search examples are shown below. \n",
|
||||
"\n",
|
||||
"Search for all features within a featurestore with the code snippet below."
|
||||
"**Example of using the `search` method**\n",
|
||||
"\n",
|
||||
"Use the following code snippet to search for all features within a feature store:\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -820,9 +825,9 @@
|
||||
"id": "K3n5XdK8Xjmw"
|
||||
},
|
||||
"source": [
|
||||
"## Import Feature Values\n",
|
||||
"## Import feature values\n",
|
||||
"\n",
|
||||
"You need to import feature values before you can use them for online/offline serving. In this step, you learn how to import feature values by ingesting the values from Cloud Storage. You can also import feature values from BigQuery or a Pandas dataframe.\n"
|
||||
"You need to import feature values before you can use them for online or offline serving. In this step, you learn how to import feature values by ingesting the values from GCS (Google Cloud Storage). You can also import feature values from BigQuery or a pandas dataFrame.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -831,11 +836,11 @@
|
||||
"id": "BlqJ-QdTcs6W"
|
||||
},
|
||||
"source": [
|
||||
"### Source Data Format and Layout\n",
|
||||
"### Source data format and layout\n",
|
||||
"\n",
|
||||
"BigQuery table/Avro/CSV are supported as input data types. No matter what format you are using, each imported entity *must* have an ID; also, each entity can *optionally* have a timestamp, specifying when the feature values are generated. This notebook uses Avro as an input, located at this public [bucket](https://console.cloud.google.com/storage/browser/cloud-samples-data-us-central1/vertex-ai/feature-store/datasets). The Avro schemas are as follows:\n",
|
||||
"BigQuery table/Avro/CSV are supported as input data types. No matter what format you are using, each imported entity *must* have an ID. Each entity can *optionally* have a timestamp, specifying when the feature values are generated. This notebook uses Avro as an input, located at this public [bucket](https://console.cloud.google.com/storage/browser/cloud-samples-data-us-central1/vertex-ai/feature-store/datasets). The Avro schemas are as follows:\n",
|
||||
"\n",
|
||||
"**For the Users entity**:\n",
|
||||
"**For the `users` entity**:\n",
|
||||
"```\n",
|
||||
"schema = {\n",
|
||||
" \"type\": \"record\",\n",
|
||||
@@ -865,7 +870,7 @@
|
||||
" }\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"**For the Movies entity**:\n",
|
||||
"**For the `movies` entity**:\n",
|
||||
"```\n",
|
||||
"schema = {\n",
|
||||
" \"type\": \"record\",\n",
|
||||
@@ -902,7 +907,7 @@
|
||||
"id": "m7DyDa6chbJx"
|
||||
},
|
||||
"source": [
|
||||
"### Import feature values for Users entity type\n",
|
||||
"### Import feature values for `users` entity type\n",
|
||||
"\n",
|
||||
"When importing, specify the following in your request:\n",
|
||||
"\n",
|
||||
@@ -955,9 +960,9 @@
|
||||
"id": "laXdJPIqkLJO"
|
||||
},
|
||||
"source": [
|
||||
"### Import feature values for Movies entity type\n",
|
||||
"### Import feature values for `movies` entity type\n",
|
||||
"\n",
|
||||
"Similarly, import feature values for the Movies entity type into the featurestore.\n"
|
||||
"Similarly, import feature values for the `movies` entity type into the featurestore.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1014,7 +1019,7 @@
|
||||
},
|
||||
"source": [
|
||||
"[Online serving](https://cloud.google.com/vertex-ai/docs/featurestore/serving-online)\n",
|
||||
"lets you serve feature values for small batches of entities. It's designed for latency-sensitive service, such as online model prediction. For example, for a movie service, you might want to quickly show movies that the current user would most likely watch."
|
||||
"lets you serve feature values for small batches of entities. It's designed for latency-sensitive services, such as online model prediction. For example, for a movie service, you might want to quickly show movies that the current user would most likely watch."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1025,9 +1030,9 @@
|
||||
"source": [
|
||||
"### Read one entity per request\n",
|
||||
"\n",
|
||||
"With the Vertex AI SDK, it is easy to read feature values of one entity. By default, the SDK will return the latest value of each feature, meaning the feature values with the most recent timestamp.\n",
|
||||
"With the Python SDK, it's easy to read feature values of one entity. By default, the SDK returns the latest value of each feature, that is, the feature values with the most recent timestamps.\n",
|
||||
"\n",
|
||||
"To read feature values, specify the entity type ID and features to read. By default all the features of an entity type will be selected. The response will output and display the selected entity type ID and the selected feature values as a Pandas dataframe."
|
||||
"To read feature values, specify the entity type ID and features to read. By default all the features of an entity type are selected. The output response displays the selected entity type ID and the selected feature values as a Pandas dataframe."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1060,7 +1065,7 @@
|
||||
"source": [
|
||||
"### Read multiple entities per request\n",
|
||||
"\n",
|
||||
"To read feature values from multiple entities, specify the different entity type IDs. By default all the features of an entity type will be selected. Note that fetching only a small number of entities is recommended when using this SDK due to its latency-sensitive nature."
|
||||
"To read feature values from multiple entities, specify the different entity type IDs. By default, all the features of an entity type are selected. Note that fetching only a small number of entities is recommended when using this SDK due to its latency-sensitive nature."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1115,16 +1120,16 @@
|
||||
"source": [
|
||||
"### Use case\n",
|
||||
"\n",
|
||||
"**The task** is to prepare a training dataset to train a model, which predicts if a given user will watch a given movie. To achieve this, you need 2 sets of input:\n",
|
||||
"**The task** is to prepare a training dataset to train a model, which predicts if a given user is going to watch a movie. To achieve this, you need 2 sets of input:\n",
|
||||
"\n",
|
||||
"* Features: you already imported into the featurestore.\n",
|
||||
"* Labels: the ground-truth data recorded that user X has watched movie Y.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"To be more specific, the ground-truth observation is described in Table 1 and the desired training dataset is described in Table 2. Each row in Table 2 is a result of joining the imported feature values from Vertex AI Feature Store according to the entity IDs and timestamps in Table 1. In this example, the `age`, `gender` and `liked_genres` features from `users` and\n",
|
||||
"the `titles`, `genres` and `average_rating` features from `movies` are chosen to train the model. Note that only positive examples are shown in these 2 tables, i.e., you can imagine there is a label column whose values are all `True`.\n",
|
||||
"the `titles`, `genres` and `average_rating` features from `movies` are chosen to train the model. Note that only positive examples are shown in these 2 tables, that is, you can imagine there is a label column whose values are all `True`.\n",
|
||||
"\n",
|
||||
"[batch_serve_to_bq](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/featurestore/featurestore.py#L770) takes Table 1 as\n",
|
||||
"[`batch_serve_to_bq`](https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/featurestore/featurestore.py#L770) takes Table 1 as\n",
|
||||
"input, joins all required feature values from the featurestore, and returns Table 2 for training.\n",
|
||||
"\n",
|
||||
"<h4 align=\"center\">Table 1. Ground-truth data</h4>\n",
|
||||
@@ -1154,7 +1159,7 @@
|
||||
"source": [
|
||||
"#### Why timestamp?\n",
|
||||
"\n",
|
||||
"Note that there is a `timestamp` column in Table 2. This indicates the time when the ground-truth was observed. This is to avoid data inconsistency.\n",
|
||||
"Note that there is a `timestamp` column in Table 2 to indicate the time when the ground-truth was observed. This is to avoid data inconsistency.\n",
|
||||
"\n",
|
||||
"For example, the 2nd row of Table 2 indicates that user `alice` watched movie `Cinema Paradiso` on `2019-11-01T00:00:00Z`. The featurestore keeps feature values for all timestamps but fetches feature values *only* at the given timestamp during batch serving. On that day, Alice might have been 54 years old, but now Alice might be 56; featurestore returns `age=54` as Alice's age, instead of `age=56`, because that is the value of the feature at the observation time. Similarly, other features might be time-variant as well, such as `liked_genres`."
|
||||
]
|
||||
@@ -1167,7 +1172,7 @@
|
||||
"source": [
|
||||
"### Create BigQuery dataset for output\n",
|
||||
"\n",
|
||||
"You need a BigQuery dataset to host the output data in `us-central1`. Input the name of the dataset you want to create and specify the name of the table you want to store the output created later. These will be used in the next section.\n",
|
||||
"You need a BigQuery dataset to host the output data in `us-central1`. Input the name of the dataset you want to create and specify the name of the table you want to store the output created later. These are used in the next section.\n",
|
||||
"\n",
|
||||
"**Make sure that the table name does NOT already exist**.\n"
|
||||
]
|
||||
@@ -1232,9 +1237,9 @@
|
||||
"id": "W8dLJ9nuDFgI"
|
||||
},
|
||||
"source": [
|
||||
"### Batch Read Feature Values\n",
|
||||
"### Batch read feature values\n",
|
||||
"\n",
|
||||
"Assemble the request which specify the following info:\n",
|
||||
"Assemble the request which specifies the following info:\n",
|
||||
"\n",
|
||||
"* Where is the label data, i.e., Table 1.\n",
|
||||
"* Which features are read, i.e., the column names in Table 2.\n",
|
||||
@@ -1281,6 +1286,96 @@
|
||||
"After the LRO finishes, you should be able to see the result in the [BigQuery console](https://console.cloud.google.com/bigquery), as a new table under the BigQuery dataset created earlier."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "7190f3c8b625"
|
||||
},
|
||||
"source": [
|
||||
"## Streaming ingestion\n",
|
||||
"\n",
|
||||
"Streaming ingestion is currently public preview. \n",
|
||||
"\n",
|
||||
"Streaming ingestion lets you make real-time updates to feature values. While batch import is suitable for importing a large volume of data with high latency, streaming ingestion is suitable for ingesting small amount of data with low latency. The written data becomes available to read using batch export and online serving."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "560e835c93db"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Since streaming ingestion is public preview, the feature is available in aiplatform_v1beta1.\n",
|
||||
"from google.cloud.aiplatform_v1beta1 import (\n",
|
||||
" FeaturestoreOnlineServingServiceClient, FeaturestoreServiceClient)\n",
|
||||
"from google.cloud.aiplatform_v1beta1.types import \\\n",
|
||||
" featurestore_online_service as featurestore_online_service_pb2\n",
|
||||
"from google.cloud.aiplatform_v1beta1.types import types as types_pb2\n",
|
||||
"\n",
|
||||
"API_ENDPOINT = \"{}-aiplatform.googleapis.com\".format(REGION)\n",
|
||||
"# Create client connection\n",
|
||||
"admin_client = FeaturestoreServiceClient(client_options={\"api_endpoint\": API_ENDPOINT})\n",
|
||||
"data_client = FeaturestoreOnlineServingServiceClient(\n",
|
||||
" client_options={\"api_endpoint\": API_ENDPOINT}\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "f53a06c9ab5c"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Call `write_feature_values` to ingest data to `users` entity type.\n",
|
||||
"data_client.write_feature_values(\n",
|
||||
" entity_type=admin_client.entity_type_path(\n",
|
||||
" PROJECT_ID, REGION, FEATURESTORE_ID, \"users\"\n",
|
||||
" ),\n",
|
||||
" payloads=[\n",
|
||||
" featurestore_online_service_pb2.WriteFeatureValuesPayload(\n",
|
||||
" entity_id=\"1305\",\n",
|
||||
" feature_values={\n",
|
||||
" \"age\": featurestore_online_service_pb2.FeatureValue(int64_value=34),\n",
|
||||
" \"gender\": featurestore_online_service_pb2.FeatureValue(\n",
|
||||
" string_value=\"female\"\n",
|
||||
" ),\n",
|
||||
" \"liked_genres\": featurestore_online_service_pb2.FeatureValue(\n",
|
||||
" string_array_value=types_pb2.StringArray(values=[\"drama\", \"action\"])\n",
|
||||
" ),\n",
|
||||
" },\n",
|
||||
" ),\n",
|
||||
" featurestore_online_service_pb2.WriteFeatureValuesPayload(\n",
|
||||
" entity_id=\"1306\",\n",
|
||||
" feature_values={\n",
|
||||
" \"age\": featurestore_online_service_pb2.FeatureValue(int64_value=50),\n",
|
||||
" \"gender\": featurestore_online_service_pb2.FeatureValue(\n",
|
||||
" string_value=\"male\"\n",
|
||||
" ),\n",
|
||||
" \"liked_genres\": featurestore_online_service_pb2.FeatureValue(\n",
|
||||
" string_array_value=types_pb2.StringArray(\n",
|
||||
" values=[\"suspense\", \"comedy\"]\n",
|
||||
" )\n",
|
||||
" ),\n",
|
||||
" },\n",
|
||||
" ),\n",
|
||||
" ],\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "700a9f1ebd19"
|
||||
},
|
||||
"source": [
|
||||
"Upon successful completion, the `write_feature_values` API returns an empty response.\n",
|
||||
"Similarly, ingest data to the `movies` entity type"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
@@ -1292,7 +1387,7 @@
|
||||
"To clean up all Google Cloud resources used in this project, you can [delete the Google Cloud\n",
|
||||
"project](https://cloud.google.com/resource-manager/docs/creating-managing-projects#shutting_down_projects) you used for the tutorial.\n",
|
||||
"\n",
|
||||
"You can also keep the project but delete the featurestore and the BigQuery dataset by running the code below:"
|
||||
"You can also keep the project, but delete the featurestore and the BigQuery dataset by running the following code:"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,7 +1,42 @@
|
||||
|
||||
[Using Vertex AI Matching Engine for StackOverflow Questions](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/matching_engine/sdk_matching_engine_create_stack_overflow_embeddings.ipynb)
|
||||
|
||||
```
|
||||
Learn how to encode custom text embeddings, create an Approximate Nearest Neighbor index, and query against indexes.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
* Create ANN index
|
||||
* Create an index endpoint with VPC Network
|
||||
* Deploy ANN index
|
||||
* Perform online query
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Vertex AI Matching Engine](https://cloud.google.com/vertex-ai/docs/matching-engine/overview).
|
||||
|
||||
|
||||
[Using Vertex AI Matching Engine for Text-to-Image Embeddings](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/matching_engine/sdk_matching_engine_create_text_to_image_embeddings.ipynb)
|
||||
|
||||
```
|
||||
Learn how to encode custom text embeddings, create an Approximate Nearest Neighbor index, and query against indexes.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
* Create ANN index
|
||||
* Create an index endpoint with VPC Network
|
||||
* Deploy ANN index
|
||||
* Perform online query
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Vertex AI Matching Engine](https://cloud.google.com/vertex-ai/docs/matching-engine/overview).
|
||||
|
||||
|
||||
[Create Vertex AI Matching Engine index](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/matching_engine/sdk_matching_engine_for_indexing.ipynb)
|
||||
|
||||
```
|
||||
Learn how to create Approximate Nearest Neighbor (ANN) Index, query against indexes, and validate the performance of the index.
|
||||
Learn how to create Approximate Nearest Neighbor Index, query against indexes, and validate the performance of the index.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
@@ -13,37 +48,5 @@ The steps performed include:
|
||||
|
||||
```
|
||||
|
||||
|
||||
[Introduction to builtin Swivel embedding algorithm](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/matching_engine/intro-swivel.ipynb)
|
||||
|
||||
```
|
||||
Learn how to train custom embeddings using Vertex AI Pipelines and deploy the model for serving.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
1. **Setup**: Importing the required libraries and setting your global variables.
|
||||
2. **Configure parameters**: Setting the appropriate parameter values for the pipeline job.
|
||||
3. **Train on Vertex AI Pipelines**: Create a Swivel job to Vertex Pipelines using pipeline template.
|
||||
4. **Deploy on Vertex AI Prediction**: Importing and deploying the trained model to a callable endpoint.
|
||||
5. **Predict**: Calling the deployed endpoint using online prediction.
|
||||
6. **Cleaning up**: Deleting resources created by this tutorial.
|
||||
|
||||
```
|
||||
|
||||
|
||||
[Introduction to builtin Two-towers embedding algorithm](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/matching_engine/two-tower-model-introduction.ipynb)
|
||||
|
||||
```
|
||||
Learn how to run the two-tower model.
|
||||
|
||||
The steps performed include:
|
||||
1. **Setup**: Importing the required libraries and setting your global variables.
|
||||
2. **Configure parameters**: Setting the appropriate parameter values for the training job.
|
||||
3. **Train on Vertex AI Training**: Submitting a training job.
|
||||
4. **Deploy on Vertex AI Prediction**: Importing and deploying the trained model to a callable endpoint.
|
||||
5. **Predict**: Calling the deployed endpoint using online or batch prediction.
|
||||
6. **Hyperparameter tuning**: Running a hyperparameter tuning job.
|
||||
7. **Cleaning up**: Deleting resources created by this tutorial.
|
||||
|
||||
```
|
||||
Learn more about [Vertex AI Matching Engine](https://cloud.google.com/vertex-ai/docs/matching-engine/overview).
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+1272
File diff suppressed because it is too large
Load Diff
+1238
File diff suppressed because one or more lines are too long
@@ -60,7 +60,9 @@
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This example demonstrates how to use the Vertex AI ANN Service. It is a high scale, low latency solution, to find similar vectors (or more specifically \"embeddings\") for a large corpus. Moreover, it is a fully managed offering, further reducing operational overhead. It is built upon [Approximate Nearest Neighbor (ANN) technology](https://ai.googleblog.com/2020/07/announcing-scann-efficient-vector.html) developed by Google Research."
|
||||
"This example demonstrates how to use the Vertex AI ANN Service. It is a high scale, low latency solution, to find similar vectors (or more specifically \"embeddings\") for a large corpus. Moreover, it is a fully managed offering, further reducing operational overhead. It is built upon [Approximate Nearest Neighbor (ANN) technology](https://ai.googleblog.com/2020/07/announcing-scann-efficient-vector.html) developed by Google Research.\n",
|
||||
"\n",
|
||||
"Learn more about [Vertex AI Matching Engine](https://cloud.google.com/vertex-ai/docs/matching-engine/overview)."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -290,8 +292,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# VPC_NETWORK = \"[your-vpc-network-name]\" # @param {type:\"string\"}\n",
|
||||
"VPC_NETWORK = \"matching-engine-test\" # @param {type:\"string\"}\n",
|
||||
"VPC_NETWORK = \"[your-vpc-network-name]\" # @param {type:\"string\"}\n",
|
||||
"\n",
|
||||
"PEERING_RANGE_NAME = \"ann-haystack-range\""
|
||||
]
|
||||
@@ -542,7 +543,7 @@
|
||||
" json.dumps(\n",
|
||||
" {\n",
|
||||
" \"id\": str(index),\n",
|
||||
" \"embedding\": [str(value) for value in train[index]],\n",
|
||||
" \"embedding\": [str(value) for value in embedding],\n",
|
||||
" \"restricts\": [\n",
|
||||
" {\n",
|
||||
" \"namespace\": \"class\",\n",
|
||||
@@ -644,7 +645,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"tree_ah_index = aiplatform.MatchingEngineIndex.create_tree_ah_index(\n",
|
||||
" display_name=DISPLAY_NAME_BRUTE_FORCE,\n",
|
||||
" display_name=DISPLAY_NAME,\n",
|
||||
" contents_delta_uri=EMBEDDINGS_INITIAL_URI,\n",
|
||||
" dimensions=DIMENSIONS,\n",
|
||||
" approximate_neighbors_count=150,\n",
|
||||
@@ -710,7 +711,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"brute_force_index = aiplatform.MatchingEngineIndex.create_brute_force_index(\n",
|
||||
" display_name=DISPLAY_NAME,\n",
|
||||
" display_name=DISPLAY_NAME_BRUTE_FORCE,\n",
|
||||
" contents_delta_uri=EMBEDDINGS_INITIAL_URI,\n",
|
||||
" dimensions=DIMENSIONS,\n",
|
||||
" distance_measure_type=\"DOT_PRODUCT_DISTANCE\",\n",
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,117 @@
|
||||
|
||||
[AutoML Image Classification](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/migration/UJ1 Vertex SDK AutoML Image Classification.ipynb)
|
||||
|
||||
```
|
||||
Learn to use `AutoML` to train an image model and use `Vertex AI Prediction` and `Vertex AI Batch Prediction` to do online and batch predictions.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Train an AutoML image classification model.
|
||||
- Make a batch prediction.
|
||||
- Deploy model to a endpoint
|
||||
- Make a online prediction
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Migrate to Vertex AI](https://cloud.google.com/vertex-ai/docs/start/migrating-to-vertex-ai).
|
||||
|
||||
Learn more about [Classification for image data](https://cloud.google.com/vertex-ai/docs/training-overview#classification_for_images).
|
||||
|
||||
|
||||
[Custom Scikit-Learn model with pre-built training container](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/migration/UJ10 Vertex SDK Custom Scikit-Learn with pre-built training container.ipynb)
|
||||
|
||||
```
|
||||
Learn to use `Vertex AI Training` to create a custom trained model and use `Vertex AI Batch Prediction` to do a batch prediction on the trained model.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a `Vertex AI` custom job for training a scikit-learn model.
|
||||
- Upload the trained model artifacts as a `Model` resource.
|
||||
- Make a batch prediction.
|
||||
- Deploy model to a endpoint
|
||||
- Make a online prediction
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Migrate to Vertex AI](https://cloud.google.com/vertex-ai/docs/start/migrating-to-vertex-ai).
|
||||
|
||||
Learn more about [Custom training](https://cloud.google.com/vertex-ai/docs/training/custom-training).
|
||||
|
||||
|
||||
[Hyperparameter Tuning](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/migration/UJ11 Vertex SDK Hyperparameter Tuning.ipynb)
|
||||
|
||||
```
|
||||
Learn to use `Vertex AI Hyperparameter` to create and tune a custom trained model.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Create a `Vertex AI` hyperparameter tuning job for training a TensorFlow model.
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Migrate to Vertex AI](https://cloud.google.com/vertex-ai/docs/training/hyperparameter-tuning-overview).
|
||||
|
||||
Learn more about [Custom training](https://cloud.google.com/vertex-ai/docs/training/custom-training).
|
||||
|
||||
|
||||
[AutoML Video Classification](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/migration/UJ14 Vertex SDK AutoML Video Classification.ipynb)
|
||||
|
||||
```
|
||||
Learn to use `AutoML` to train a video model and use `Vertex AI Batch Prediction` to do batch predictions.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Train an AutoML video classification model.
|
||||
- Make a batch prediction.
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Migrate to Vertex AI](https://cloud.google.com/vertex-ai/docs/start/migrating-to-vertex-ai).
|
||||
|
||||
Learn more about [Classification for video data](https://cloud.google.com/vertex-ai/docs/training-overview#classification_for_videos).
|
||||
|
||||
|
||||
[AutoML Video Object Tracking](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/migration/UJ15 Vertex SDK AutoML Object Tracking.ipynb)
|
||||
|
||||
```
|
||||
Learn to use `AutoML` to train a video model and use `Vertex AI Batch Prediction` to do batch predictions.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Train an AutoML video object tracking model.
|
||||
- Make a batch prediction.
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Migrate to Vertex AI](https://cloud.google.com/vertex-ai/docs/start/migrating-to-vertex-ai).
|
||||
|
||||
Learn more about [Object tracking for video data](https://cloud.google.com/vertex-ai/docs/training-overview#object_tracking_for_videos).
|
||||
|
||||
|
||||
[Custom Image Classification w/pre-built training container](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/migration/UJ2,12 Vertex SDK Custom Image Classification with pre-built training container.ipynb)
|
||||
|
||||
```
|
||||
Learn how to train a tensorflow image classification model using a prebuilt container and Vertex AI training.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- *Package the training code into a python application.*
|
||||
- *Containerize the training application using Cloud Build and Artifact Registry.*
|
||||
- *Create a custom container training job in Vertex AI and run it.*
|
||||
- *Evaluate the model generated from the training job.*
|
||||
- *Create a model resource for the trained model in Vertex AI Model Registry.*
|
||||
- *Run a Vertex AI batch prediction job.*
|
||||
- *Deploy the model resource to a Vertex AI Endpoint.*
|
||||
- *Run a online prediction job on the model resource.*
|
||||
- *Clean up the resources created.*
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Migrate to Vertex AI](https://cloud.google.com/vertex-ai/docs/start/migrating-to-vertex-ai).
|
||||
|
||||
Learn more about [Custom training](https://cloud.google.com/vertex-ai/docs/training/custom-training).
|
||||
|
||||
|
||||
[Custom Image Classification w/custom training container](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/migration/UJ3 Vertex SDK Custom Image Classification with custom training container.ipynb)
|
||||
|
||||
```
|
||||
@@ -17,6 +131,10 @@ The steps performed include:
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Migrate to Vertex AI](https://cloud.google.com/vertex-ai/docs/start/migrating-to-vertex-ai).
|
||||
|
||||
Learn more about [Custom training](https://cloud.google.com/vertex-ai/docs/training/custom-training).
|
||||
|
||||
|
||||
[AutoML Tabular Binary Classification](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/migration/UJ4 Vertex SDK AutoML Tabular Binary Classification.ipynb)
|
||||
|
||||
@@ -34,8 +152,96 @@ The steps performed include:
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Migrate to Vertex AI](https://cloud.google.com/vertex-ai/docs/start/migrating-to-vertex-ai).
|
||||
|
||||
[Custom Scikit-Learn model with pre-built training container](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/migration/UJ10 Vertex SDK Custom Scikit-Learn with pre-built training container.ipynb)
|
||||
Learn more about [Classification for tabular data](https://cloud.google.com/vertex-ai/docs/tabular-data/classification-regression/overview).
|
||||
|
||||
|
||||
[AutoML Image Object Detection](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/migration/UJ5 Vertex SDK AutoML Image Object Detection.ipynb)
|
||||
|
||||
```
|
||||
Learn to use `AutoML` to train an image model and use `Vertex AI Prediction` and `Vertex AI Batch Prediction` to do online and batch predictions.
|
||||
|
||||
The steps performed include:
|
||||
|
||||
- Train an AutoML object detection model.
|
||||
- Make a batch prediction.
|
||||
- Deploy model to a endpoint
|
||||
- Make a online prediction
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Migrate to Vertex AI](https://cloud.google.com/vertex-ai/docs/start/migrating-to-vertex-ai).
|
||||
|
||||
Learn more about [Object detection for image data](https://cloud.google.com/vertex-ai/docs/training-overview#object_detection_for_images).
|
||||
|
||||
|
||||
[AutoML Text Classification](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/migration/UJ6 Vertex SDK AutoML Text Classification.ipynb)
|
||||
|
||||
```
|
||||
The objective of this notebook is to build a AutoML Text Classification Model.
|
||||
|
||||
The steps performed include the following:
|
||||
|
||||
* Set your task name, and GCS prefix
|
||||
* Copy AutoML text demo train data for creating managed dataset
|
||||
* Create a dataset on Vertex AI.
|
||||
* Configure a training job
|
||||
* Launch a training job and create a model on Vertex AI
|
||||
* Copy AutoML Text Demo Prediction Data for creating batch prediction job
|
||||
* Perform batch prediction job on the model
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Migrate to Vertex AI](https://cloud.google.com/vertex-ai/docs/start/migrating-to-vertex-ai).
|
||||
|
||||
Learn more about [Classification for text data](https://cloud.google.com/vertex-ai/docs/training-overview#classification_for_text).
|
||||
|
||||
|
||||
[AutoML Text Entity Extraction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/migration/UJ7 Vertex SDK AutoML Text Entity Extraction.ipynb)
|
||||
|
||||
```
|
||||
The objective of this notebook is to build a AutoML Text Entity Extraction model.
|
||||
|
||||
The steps performed include the following:
|
||||
|
||||
* Set your task name, and GCS prefix
|
||||
* Copy AutoML video demo train data for creating managed dataset
|
||||
* Create a dataset on Vertex AI.
|
||||
* Configure a training job
|
||||
* Launch a training job and create a model on Vertex AI
|
||||
* Copy AutoML Video Demo Prediction Data for creating batch prediction job
|
||||
* Perform batch prediction job on the model
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Migrate to Vertex AI](https://cloud.google.com/vertex-ai/docs/start/migrating-to-vertex-ai).
|
||||
|
||||
Learn more about [Entity extraction for text data](https://cloud.google.com/vertex-ai/docs/training-overview#entity_extraction_for_text).
|
||||
|
||||
|
||||
[AutoML Text Sentiment Analysis](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/migration/UJ8 Vertex SDK AutoML Text Sentiment Analysis.ipynb)
|
||||
|
||||
```
|
||||
The objective of this notebook is to build a AutoML Text Sentiment Analysis model.
|
||||
|
||||
The steps performed include the following:
|
||||
|
||||
* Copy AutoML video demo train data for creating managed dataset
|
||||
* Create a dataset on Vertex AI.
|
||||
* Configure a training job
|
||||
* Launch a training job and create a model on Vertex AI
|
||||
* Copy AutoML Video Demo Prediction Data for creating batch prediction job
|
||||
* Perform batch prediction job on the model
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Migrate to Vertex AI](https://cloud.google.com/vertex-ai/docs/start/migrating-to-vertex-ai).
|
||||
|
||||
Learn more about [Sentiment analysis for text data](https://cloud.google.com/vertex-ai/docs/training-overview#sentiment_analysis_for_text).
|
||||
|
||||
|
||||
[Custom XGBoost model with pre-built training container](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/migration/UJ9 Vertex SDK Custom XGBoost with pre-built training container.ipynb)
|
||||
|
||||
```
|
||||
Learn to use `Vertex AI Training` to create a custom trained model and use `Vertex AI Batch Prediction` to do a batch prediction on the trained model.
|
||||
@@ -50,39 +256,7 @@ The steps performed include:
|
||||
|
||||
```
|
||||
|
||||
Learn more about [Migrate to Vertex AI](https://cloud.google.com/vertex-ai/docs/start/migrating-to-vertex-ai).
|
||||
|
||||
[AutoML Text Entity Extraction](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/migration/UJ7 Vertex SDK AutoML Text Entity Extraction.ipynb)
|
||||
|
||||
```
|
||||
The objective of this notebook is to build a AutoML Text Entity Extrasction Model.
|
||||
|
||||
The steps performed include the following:
|
||||
|
||||
* Set your task name, and GCS prefix
|
||||
* Copy AutoML video demo train data for creating managed dataset
|
||||
* Create a dataset on Vertex AI.
|
||||
* Configure a training job
|
||||
* Launch a training job and create a model on Vertex AI
|
||||
* Copy AutoML Video Demo Prediction Data for creating batch prediction job
|
||||
* Perform batch prediction job on the model
|
||||
|
||||
```
|
||||
|
||||
|
||||
[AutoML Text Classification](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/migration/UJ6 Vertex SDK AutoML Text Classification.ipynb)
|
||||
|
||||
```
|
||||
The objective of this notebook is to build a AutoML Video Classification Model.
|
||||
|
||||
The steps performed include the following:
|
||||
|
||||
* Set your task name, and GCS prefix
|
||||
* Copy AutoML video demo train data for creating managed dataset
|
||||
* Create a dataset on Vertex AI.
|
||||
* Configure a training job
|
||||
* Launch a training job and create a model on Vertex AI
|
||||
* Copy AutoML Video Demo Prediction Data for creating batch prediction job
|
||||
* Perform batch prediction job on the model
|
||||
|
||||
```
|
||||
Learn more about [Custom training](https://cloud.google.com/vertex-ai/docs/training/custom-training).
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
"id": "title:migration,new"
|
||||
},
|
||||
"source": [
|
||||
"# Vertex AI: Vertex AI Migration: AutoML Image Classification\n",
|
||||
"# Vertex AI Migration: AutoML Image Classification\n",
|
||||
"\n",
|
||||
"<table align=\"left\">\n",
|
||||
"\n",
|
||||
@@ -54,6 +54,45 @@
|
||||
"<br/><br/><br/>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "7a8a13b86a8b"
|
||||
},
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK for Python to train and deploy an AutoML image classification model.\n",
|
||||
"\n",
|
||||
"Learn more about [Migrate to Vertex AI](https://cloud.google.com/vertex-ai/docs/start/migrating-to-vertex-ai) and [Classification for image data](https://cloud.google.com/vertex-ai/docs/training-overview#classification_for_images)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "618cfedf829a"
|
||||
},
|
||||
"source": [
|
||||
"### Objective\n",
|
||||
"\n",
|
||||
"In this tutorial, you learn to use `AutoML` to train an image model and use `Vertex AI Prediction` and `Vertex AI Batch Prediction` to do online and batch predictions.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"This tutorial uses the following Google Cloud ML services:\n",
|
||||
"\n",
|
||||
"- `AutoML`\n",
|
||||
"- `Vertex AI Batch Prediction`\n",
|
||||
"- `Vertex AI Model` resource\n",
|
||||
"- `Vertex AI Endpoint` resource\n",
|
||||
"\n",
|
||||
"The steps performed include:\n",
|
||||
"\n",
|
||||
"- Train an AutoML image classification model.\n",
|
||||
"- Make a batch prediction.\n",
|
||||
"- Deploy model to a endpoint\n",
|
||||
"- Make a online prediction"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
|
||||
+4
-2
@@ -29,7 +29,7 @@
|
||||
"id": "title:migration,new"
|
||||
},
|
||||
"source": [
|
||||
"# Vertex AI: Vertex AI Migration: Custom Scikit-Learn model with pre-built training container\n",
|
||||
"# Vertex AI Migration: Custom Scikit-Learn model with pre-built training container\n",
|
||||
"\n",
|
||||
"<table align=\"left\">\n",
|
||||
" <td>\n",
|
||||
@@ -62,7 +62,9 @@
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK for Python to train and deploy a custom tabular classification scikit-learn model for batch prediction."
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK for Python to train and deploy a custom tabular classification scikit-learn model for batch prediction.\n",
|
||||
"\n",
|
||||
"Learn more about [Migrate to Vertex AI](https://cloud.google.com/vertex-ai/docs/start/migrating-to-vertex-ai) and [Custom training](https://cloud.google.com/vertex-ai/docs/training/custom-training)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
"id": "title:migration,new"
|
||||
},
|
||||
"source": [
|
||||
"# Vertex AI: Vertex AI Migration: Hyperparameter Tuning\n",
|
||||
"# Vertex AI Migration: Hyperparameter Tuning\n",
|
||||
"\n",
|
||||
"<table align=\"left\">\n",
|
||||
"\n",
|
||||
@@ -54,6 +54,42 @@
|
||||
"<br/><br/><br/>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "7a8a13b86a8b"
|
||||
},
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK for Python to tune hyperparameters in a custom tabular classification TensorFlow model.\n",
|
||||
"\n",
|
||||
"Learn more about [Migrate to Vertex AI](https://cloud.google.com/vertex-ai/docs/training/hyperparameter-tuning-overview) and [Custom training](https://cloud.google.com/vertex-ai/docs/training/custom-training)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "618cfedf829a"
|
||||
},
|
||||
"source": [
|
||||
"### Objective\n",
|
||||
"\n",
|
||||
"In this tutorial, you learn to use `Vertex AI Hyperparameter` to create and tune a custom trained model.\n",
|
||||
"\n",
|
||||
"You learn how to create and tune a custom-trained model from a Python script in a Docker container using the Vertex AI SDK for Python.\n",
|
||||
"\n",
|
||||
"This tutorial uses the following Google Cloud ML services:\n",
|
||||
"\n",
|
||||
"- `Vertex AI Training`\n",
|
||||
"- `Vertex AI Hyperparameter Tuning`\n",
|
||||
"\n",
|
||||
"The steps performed include:\n",
|
||||
"\n",
|
||||
"- Create a `Vertex AI` hyperparameter tuning job for training a TensorFlow model."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
"id": "title:migration,new"
|
||||
},
|
||||
"source": [
|
||||
"# Vertex AI: Vertex AI Migration: AutoML Video Classificaton\n",
|
||||
"# Vertex AI Migration: AutoML Video Classification\n",
|
||||
"\n",
|
||||
"<table align=\"left\">\n",
|
||||
"\n",
|
||||
@@ -54,6 +54,43 @@
|
||||
"<br/><br/><br/>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "7a8a13b86a8b"
|
||||
},
|
||||
"source": [
|
||||
"## Overview\n",
|
||||
"\n",
|
||||
"This tutorial demonstrates how to use the Vertex AI SDK for Python to train an AutoML video classification model and do batch prediction.\n",
|
||||
"\n",
|
||||
"Learn more about [Migrate to Vertex AI](https://cloud.google.com/vertex-ai/docs/start/migrating-to-vertex-ai) and [Classification for video data](https://cloud.google.com/vertex-ai/docs/training-overview#classification_for_videos)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "618cfedf829a"
|
||||
},
|
||||
"source": [
|
||||
"### Objective\n",
|
||||
"\n",
|
||||
"In this tutorial, you learn to use `AutoML` to train a video model and use `Vertex AI Batch Prediction` to do batch predictions.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"This tutorial uses the following Google Cloud ML services:\n",
|
||||
"\n",
|
||||
"- `AutoML`\n",
|
||||
"- `Vertex AI Batch Prediction`\n",
|
||||
"- `Vertex AI Model` resource\n",
|
||||
"- `Vertex AI Endpoint` resource\n",
|
||||
"\n",
|
||||
"The steps performed include:\n",
|
||||
"\n",
|
||||
"- Train an AutoML video classification model.\n",
|
||||
"- Make a batch prediction."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
@@ -531,7 +568,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"IMPORT_FILE = \"gs://automl-video-demo-data/hmdb_split1_5classes_train_inf.csv\""
|
||||
"IMPORT_FILE = \"gs://automl-video-demo-data/hmdb_split1_train_40_mp4_gs.csv\""
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -567,6 +604,19 @@
|
||||
"! gsutil cat $FILE | head"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "f483d8d80f64"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import datetime\n",
|
||||
"\n",
|
||||
"start = datetime.datetime.now()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
@@ -720,7 +770,19 @@
|
||||
"\n",
|
||||
"The `run` method when completed returns the `Model` resource.\n",
|
||||
"\n",
|
||||
"The execution of the training pipeline will take upto 20 minutes."
|
||||
"The execution of the training pipeline may take over 24 hrs."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "8f135100f5d9"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"if os.getenv(\"IS_TESTING\"):\n",
|
||||
" sys.exit(0)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -769,6 +831,18 @@
|
||||
" INFO:google.cloud.aiplatform.training_jobs:Model available at projects/759209241365/locations/us-central1/models/1899701006099283968"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "48ca7f0980e0"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"end = datetime.datetime.now()\n",
|
||||
"end - start"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user