Issue: sagemaker.yml resources section tag-specific resource allocation not working as expected
In the resources section of sagemaker.yml, there is a technical possibility to allocate individual resources based on tags. However, this doesn't work correctly when using certain tag presets.
As an example:
resources:
__default__:
instance_count: 1
instance_type: ml.m5.large
timeout_seconds: 86400
security_group_ids: null
subnets: null
tag2:
instance_count: 1
instance_type: ml.m5.2xlarge # <- more resources
timeout_seconds: 86400
security_group_ids: null
subnets: null
When calling _get_resources_for_node() from generator.py, the function fails to match a tag properly. The returned object node_resources is None because next() returns only the first matching item, which in this case is the node name, even if the node has tags.
Here is the relevant snippet:
[n for n in chain([node.name], iter(node.tags))]
["name1", "tag1", "tag2"]
Suggested fix:
Update _get_resources_for_node to explicitly check for non-None values before returning:
def _get_resources_for_node(self, node: Union[KedroNode, SimpleNamespace]):
node_resources = next(
(
self.config.aws.resources.get(n)
for n in chain([node.name], iter(node.tags))
if self.config.aws.resources.get(n) is not None # <-- suggested update
),
None,
)
This change ensures the function returns the first valid resource matching either the node name or any of its tags.
Issue:
sagemaker.ymlresources section tag-specific resource allocation not working as expectedIn the resources section of
sagemaker.yml, there is a technical possibility to allocate individual resources based on tags. However, this doesn't work correctly when using certain tag presets.As an example:
When calling
_get_resources_for_node()fromgenerator.py, the function fails to match a tag properly. The returned objectnode_resourcesis None becausenext()returns only the first matching item, which in this case is the node name, even if the node has tags.Here is the relevant snippet:
Suggested fix:
Update
_get_resources_for_nodeto explicitly check for non-None values before returning:This change ensures the function returns the first valid resource matching either the node name or any of its tags.