Upload asynchronous prediction sample. (#3122)

* Upload examples of kfp v2

* Upload run experiment example.

* Upload batch prediction job sample.

* Update recycling of computing resources

Recycling computing resources after predictions.

* Upload missing file

Add delete endpoint func to recycle resources.

* Upload asynchronous prediction sample.

Upload asynchronous prediction sample of kfp v2.
This commit is contained in:
Aiden010200
2024-06-24 13:12:54 +00:00
committed by GitHub
parent 41d482d65d
commit 9c2cc6d39f
@@ -0,0 +1,32 @@
import numpy as np
from kfp.v2 import dsl
@dsl.component(base_image='python:3.8',packages_to_install=['google-cloud-aiplatform==1.36.0'])
def async_predict(
endpoint_id: str,
instances: dict,
) -> np.ndarray:
import numpy as np
from google.cloud import aiplatform
endpoint = aiplatform.Endpoint(endpoint_id)
response = await endpoint.predict_async(instances)
predictions = np.asarray(response.predictions)
print(predictions.tolist())
return predictions
@dsl.pipeline(name='async-prediction')
def pipeline_prediction():
project = "projects/990000000009/locations/us-west1"
endpoint_id = project + "/endpoints/2200000000000000002"
instances = [{
"key1": "value1",
"key2": 2
}]
async_predict(endpoint_id, instances)
if __name__ == "__main__":
from kfp.v2 import compiler
compiler.Compiler().compile(
pipeline_func=pipeline_prediction,
package_path='async_prediction.json')