Lee-W opened a new pull request, #36685:
URL: https://github.com/apache/airflow/pull/36685
While running a sagemaker training job in deferrable mode, the condition might already be met before we defer the task into the trigger. This PR intends to check the job status before deferring the task to trigger.
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
<!-- Please keep an empty line above the dashes. -->
---
**^ Add meaningful description above**
Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Lee-W commented on code in PR #36685:
URL: https://github.com/apache/airflow/pull/36685#discussion_r1471055969
##########
airflow/providers/amazon/aws/operators/sagemaker.py:
##########
@@ -1085,8 +1089,50 @@ def execute(self, context: Context) -> dict:
raise AirflowException(f"Sagemaker Training Job creation failed: {response}")
if self.deferrable and self.wait_for_completion:
+ description = self.hook.describe_training_job(self.config["TrainingJobName"])
+ status = description["TrainingJobStatus"]
+
+ if self.print_log:
+ instance_count = description["ResourceConfig"]["InstanceCount"]
+ last_describe_job_call = time.monotonic()
+ job_already_completed = status not in self.hook.non_terminal_states
+ _, last_description, last_describe_job_call = self.hook.describe_training_job_with_log(
+ self.config["TrainingJobName"],
+ {},
+ [],
+ instance_count,
+ LogState.TAILING if job_already_completed else LogState.COMPLETE,
Review Comment:
Yes, i think the condition is correct. Is there any concern here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Lee-W commented on code in PR #36685:
URL: https://github.com/apache/airflow/pull/36685#discussion_r1471055450
##########
airflow/providers/amazon/aws/hooks/sagemaker.py:
##########
@@ -1300,3 +1300,13 @@ def create_auto_ml_job(
if "BestCandidate" in res:
return res["BestCandidate"]
return None
+
+ async def describe_training_job_async(self, job_name: str) -> dict[str, Any]:
Review Comment:
I refined the code a bit and used it in the trigger. Could you please take a look? Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
pankajkoti commented on code in PR #36685:
URL: https://github.com/apache/airflow/pull/36685#discussion_r1458515289
##########
airflow/providers/amazon/aws/hooks/sagemaker.py:
##########
@@ -1300,3 +1300,13 @@ def create_auto_ml_job(
if "BestCandidate" in res:
return res["BestCandidate"]
return None
+
+ async def describe_training_job_async(self, job_name: str) -> dict[str, Any]:
Review Comment:
Where does this get used?
##########
airflow/providers/amazon/aws/operators/sagemaker.py:
##########
@@ -1085,8 +1089,50 @@ def execute(self, context: Context) -> dict:
raise AirflowException(f"Sagemaker Training Job creation failed: {response}")
if self.deferrable and self.wait_for_completion:
+ description = self.hook.describe_training_job(self.config["TrainingJobName"])
+ status = description["TrainingJobStatus"]
+
+ if self.print_log:
+ instance_count = description["ResourceConfig"]["InstanceCount"]
+ last_describe_job_call = time.monotonic()
+ job_already_completed = status not in self.hook.non_terminal_states
+ _, last_description, last_describe_job_call = self.hook.describe_training_job_with_log(
+ self.config["TrainingJobName"],
+ {},
+ [],
+ instance_count,
+ LogState.TAILING if job_already_completed else LogState.COMPLETE,
Review Comment:
Can we recheck if the conditional is correct here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Lee-W commented on code in PR #36685:
URL: https://github.com/apache/airflow/pull/36685#discussion_r1473735134
##########
airflow/providers/amazon/aws/operators/sagemaker.py:
##########
@@ -1085,8 +1089,50 @@ def execute(self, context: Context) -> dict:
raise AirflowException(f"Sagemaker Training Job creation failed: {response}")
if self.deferrable and self.wait_for_completion:
+ description = self.hook.describe_training_job(self.config["TrainingJobName"])
+ status = description["TrainingJobStatus"]
+
+ if self.print_log:
+ instance_count = description["ResourceConfig"]["InstanceCount"]
+ last_describe_job_call = time.monotonic()
+ job_already_completed = status not in self.hook.non_terminal_states
+ _, last_description, last_describe_job_call = self.hook.describe_training_job_with_log(
+ self.config["TrainingJobName"],
+ {},
+ [],
+ instance_count,
+ LogState.TAILING if job_already_completed else LogState.COMPLETE,
Review Comment:
yep, thanks for the reminder. fixed it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
pankajkoti commented on code in PR #36685:
URL: https://github.com/apache/airflow/pull/36685#discussion_r1471079764
##########
airflow/providers/amazon/aws/operators/sagemaker.py:
##########
@@ -1085,8 +1089,50 @@ def execute(self, context: Context) -> dict:
raise AirflowException(f"Sagemaker Training Job creation failed: {response}")
if self.deferrable and self.wait_for_completion:
+ description = self.hook.describe_training_job(self.config["TrainingJobName"])
+ status = description["TrainingJobStatus"]
+
+ if self.print_log:
+ instance_count = description["ResourceConfig"]["InstanceCount"]
+ last_describe_job_call = time.monotonic()
+ job_already_completed = status not in self.hook.non_terminal_states
+ _, last_description, last_describe_job_call = self.hook.describe_training_job_with_log(
+ self.config["TrainingJobName"],
+ {},
+ [],
+ instance_count,
+ LogState.TAILING if job_already_completed else LogState.COMPLETE,
Review Comment:
I was thinking if the condition should be other way round. Tail the logs while the job is not complete and if complete then set LogState.Complete.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
phanikumv merged PR #36685: URL: https://github.com/apache/airflow/pull/36685 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org For queries about this service, please contact Infrastructure at: users@infra.apache.org