Skip to content

BatchPredictionJob : sync=False and wait_for_resource_creation() #636

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

Closed
dparkar opened this issue Aug 18, 2021 · 1 comment · Fixed by #660
Closed

BatchPredictionJob : sync=False and wait_for_resource_creation() #636

dparkar opened this issue Aug 18, 2021 · 1 comment · Fixed by #660
Labels
api: aiplatform Issues related to the AI Platform API.

Comments

@dparkar
Copy link

dparkar commented Aug 18, 2021

I want to launch a bunch of AutoMLTabularTrainingJob(s) asynchronously and as each training job completes successfully, launch it's corresponding BatchPredictionJob asynchronously and then once the prediction job completes successfully, download those predictions and score locally.

I am able to launch AutoMLTabularTrainingJob asynchronously using sync=False, then starting the job using job.run and then job.wait_for_resource_creation(). After this I am able to access job.state to wait on the job to complete.

However, I am unable to do the same with the BatchPredictionJob. BatchPredictionJob doesn't seem to follow the "construct and run" pattern hence there is no job.wait_for_resource_creation(). Because of this, once a BatchPredictionJob is created, any attempt to access its properties results in "RuntimeError: BatchPredictionJob resource has not been created."

prediction_run = model.batch_predict(
        job_display_name="my_prediction_job",
        gcs_source="gs://test_dataset.csv",
        instances_format="csv",
        gcs_destination_prefix="gs://predictions.csv",
        predictions_format="csv",
        sync=False)

while prediction_run.state == job_state.JobState.JOB_STATE_RUNNING: # RuntimeError: BatchPredictionJob resource has not been created.
       time.sleep(60)

print("Prediction run is complete.")
@dparkar
Copy link
Author

dparkar commented Aug 30, 2021

Awesome. Thanks @sasha-gitg !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: aiplatform Issues related to the AI Platform API.
Projects
None yet
1 participant