“RuntimeError: CustomJob resource has not been created” 在创建 Vertex AI CustomJob 时发生

huangapple go评论89阅读模式
英文:

"RuntimeError: CustomJob resource has not been created" when creating Vertex AI CustomJob

问题

我尝试创建一个类似于 https://cloud.google.com/python/docs/reference/aiplatform/latest/google.cloud.aiplatform.CustomJob 示例的 Vertex AI CustomJob。

  1. import time
  2. from google.cloud import aiplatform
  3. worker_pool_specs = [
  4. {
  5. "machine_spec": {
  6. "machine_type": "n1-standard-4",
  7. },
  8. "replica_count": 1,
  9. "container_spec": {
  10. "image_uri": "eu.gcr.io/somexistingimage",
  11. "command": ["python", "myscript.py", "test", "--var"],
  12. "args": [],
  13. },
  14. }
  15. ]
  16. job = aiplatform.CustomJob(
  17. display_name="job_{}".format(round(time.time())),
  18. worker_pool_specs=worker_pool_specs,
  19. project="my-project",
  20. staging_bucket="gs://some-bucket",
  21. )

现在,当我检查作业时,几乎所有字段(create_time、display_name、end_time等)都包含以下文本:

  1. Traceback (most recent call last):
  2. File "<string>", line 1, in <module>
  3. File ".../lib/python3.9/site-packages/google/cloud/aiplatform/base.py", line 686, in display_name
  4. self._assert_gca_resource_is_available()
  5. File ".../lib/python3.9/site-packages/google/cloud/aiplatform/base.py", line 1332, in _assert_gca_resource_is_available
  6. raise RuntimeError(
  7. RuntimeError: CustomJob resource has not been created.

环境:
python 3.9.16
google-cloud-aiplatform 1.28.1

我已登录,并且默认的应用程序身份验证已设置正确,因为我可以提交 CustomContainerTrainingJob,但无法提交 CustomJob

我找不到关于这个错误的任何信息。我该如何修复这个问题?

英文:

I try to create a Vertex AI CustomJob similar to the example from https://cloud.google.com/python/docs/reference/aiplatform/latest/google.cloud.aiplatform.CustomJob

  1. import time
  2. from google.cloud import aiplatform
  3. worker_pool_specs = [
  4. {
  5. &quot;machine_spec&quot;: {
  6. &quot;machine_type&quot;: &quot;n1-standard-4&quot;,
  7. },
  8. &quot;replica_count&quot;: 1,
  9. &quot;container_spec&quot;: {
  10. &quot;image_uri&quot;: &quot;eu.gcr.io/somexistingimage&quot;,
  11. &quot;command&quot;: [&quot;python&quot;, &quot;myscript.py&quot;, &quot;test&quot;, &quot;--var&quot;],
  12. &quot;args&quot;: [],
  13. },
  14. }
  15. ]
  16. job = aiplatform.CustomJob(
  17. display_name=&quot;job_{}&quot;.format(round(time.time())),
  18. worker_pool_specs=worker_pool_specs,
  19. project=&quot;my-project&quot;,
  20. staging_bucket=&quot;gs://some-bucket&quot;,
  21. )

Now when I inspect the job, practically all fields (create_time, display_name, end_time, ...) contain the following text:

  1. Traceback (most recent call last):
  2. File &quot;&lt;string&gt;&quot;, line 1, in &lt;module&gt;
  3. File &quot;..../lib/python3.9/site-packages/google/cloud/aiplatform/base.py&quot;, line 686, in display_name
  4. self._assert_gca_resource_is_available()
  5. File &quot;..../lib/python3.9/site-packages/google/cloud/aiplatform/base.py&quot;, line 1332, in _assert_gca_resource_is_available
  6. raise RuntimeError(
  7. RuntimeError: CustomJob resource has not been created.

Environment:
python 3.9.16
google-cloud-aiplatform 1.28.1

I'm logged in and default application auth is set correctly, as I can submit CustomContainerTrainingJobs. Just not CustomJobs.

I cannot find anything on this error. How can I fix this?

答案1

得分: 0

好的,解决方案非常简单:

在作业对象(例如job.display_name)在作业已运行或提交之前,不应读取属性。

如果执行job.submit(),然后可以在之后检查作业,或者如果运行job.run(sync=True)
如果运行job.run(sync=False),你会得到相同的错误,因为你永远不知道作业是否已完全初始化。

英文:

Ok, the solution is quite simple:

You must not read out the attributes of the Job object (e.g. job.display_name) before the job has been run or submitted.

If you execute job.submit() you can inspect the job afterwards, or if you run job.run(sync=True).
If you run job.run(sync=False) you get the same error, because you never know if the Job has been fully initialized.

huangapple
  • 本文由 发表于 2023年7月31日 21:14:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76804004.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定