Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding batch gemini predict sample #12606

Open
wants to merge 50 commits into
base: main
Choose a base branch
from

Conversation

CadillacBurgess1
Copy link
Contributor

@CadillacBurgess1 CadillacBurgess1 commented Sep 18, 2024

Description

Fixes #

Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.

Checklist

Copy link

snippet-bot bot commented Sep 18, 2024

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Sep 18, 2024
generative_ai/batch_predict/batch_gemini_predict.py Outdated Show resolved Hide resolved


def batch_prediction_gemini_example(
input_uri: str = None, output_uri: str = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
input_uri: str = None, output_uri: str = None
input_uri: Optional[str] = None, output_uri: Optional[str] = None

Also add:

from typing import Optional

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the same as it was before. Also, should these parameters be optional/default None? Aren't those required parameters for the method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an old version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated params

generative_ai/batch_predict/batch_gemini_predict.py Outdated Show resolved Hide resolved
generative_ai/batch_predict/batch_gemini_predict.py Outdated Show resolved Hide resolved
Copy link
Contributor

@holtskinner holtskinner Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a duplicate file. Change the name to use all underscores and replace the previous file.

@CadillacBurgess1
Copy link
Contributor Author

The issue was importing the preview resource. When I first created this sample it was working using the preview namespace (which as fine when I first started working on this sample), but the samples and testing in the batch predict folder uses the aiplatform namespace. Both aiplatform and vertexai.preview have a BatchPredictionJob class and they work a little different. I updated my sample to use the BatchPredictionJob class in the aiplatform namespace.

@holtskinner
Copy link
Contributor

holtskinner commented Sep 19, 2024

The issue was importing the preview resource. When I first created this sample it was working using the preview namespace (which as fine when I first started working on this sample), but the samples and testing in the batch predict folder uses the aiplatform namespace. Both aiplatform and vertexai.preview have a BatchPredictionJob class and they work a little different. I updated my sample to use the BatchPredictionJob class in the aiplatform namespace.

I think this sample should be using the vertexai.preview BatchPredictionJob class as it is intended for use with Gemini. (Different than other batch prediction samples for non-Gemini models)

I'll defer to the Vertex AI SDK product team @Ark-kun (or other)


This notebook from @gericdong also uses the vertexai.preview space

https://github.com/GoogleCloudPlatform/generative-ai/pull/1138/files

Copy link
Contributor

@holtskinner holtskinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, something I missed in our sync. The older PaLM samples use aiplatform instead of vertexai because the Batch Prediction methods weren't implemented yet in vertexai when PaLM was released.

import os
from typing import Optional

from google.cloud.aiplatform import BatchPredictionJob
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from google.cloud.aiplatform import BatchPredictionJob
from vertexai.preview.batch_prediction import BatchPredictionJob

"""

# [START generativeaionvertexai_batch_predict_gemini_createjob]
from google.cloud import aiplatform
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from google.cloud import aiplatform
import vertexai
from vertexai.preview.batch_prediction import BatchPredictionJob

# output_uri = bq://example_project.example_dataset.example_table or gs://mybucket/sampledataset.json

# Initialize
aiplatform.init(project=PROJECT_ID, location=LOCATION)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
aiplatform.init(project=PROJECT_ID, location=LOCATION)
vertexai.init(project=PROJECT_ID, location=LOCATION)

aiplatform.init(project=PROJECT_ID, location=LOCATION)

# Create the batch prediction job using BatchPredictionJob
batch_prediction_job = aiplatform.BatchPredictionJob.create(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
batch_prediction_job = aiplatform.BatchPredictionJob.create(
batch_prediction_job = BatchPredictionJob.create(

@holtskinner
Copy link
Contributor

Looks like you're getting an error in the tests:

ValueError: Please either specify output_uri_prefix or set staging_bucket in vertexai.init().

print(f"Job output location: {batch_prediction_job.output_location}")

# Example response:
# Job output location: gs://yourbucket/gen-ai-batch-prediction/prediction-model-year-month-dayThour:minute:second.12345
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Job output location: gs://yourbucket/gen-ai-batch-prediction/prediction-model-year-month-dayThour:minute:second.12345
# Job output location: gs://yourbucket/gen-ai-batch-prediction/prediction-model-year-month-day-hour:minute:second.12345

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.



def batch_prediction_gemini_example(
input_uri: str = None, output_uri: str = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the same as it was before. Also, should these parameters be optional/default None? Aren't those required parameters for the method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants