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

azure.ai.ml.entities._inputs_outputs._get_param_with_standard_annotation doesn't support stringizized annotations enabled by from __future__ import annotations. #35538

Open
mchikyt3 opened this issue May 8, 2024 · 8 comments
Assignees
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. Machine Learning needs-team-attention This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention This issue is responsible by Azure service team.

Comments

@mchikyt3
Copy link

mchikyt3 commented May 8, 2024

  • Package Name: azure-ai-ml
  • Package Version: 1.15.0
  • Operating System: Windows 10
  • Python Version: 3.12.2

Describe the bug
I'm using mldesigner.command_component to convert a function into a command component that is used later in a pipeline. The inputs and outputs of the command components are determined by the type annotations of the parameters of the function. However, stringized annotations, which is enabled by from __future__ import annotations, can't be parsed.

After debugging, the problem can be traced down to #L334, where getattr(cls_or_func, "__annotations__", {}) returns a dictionary of type annotation strings. It can be replaced by a helper function typing.get_type_hints(cls_or_func, include_extras=True) to correctly evaluate the type back from its string form. The flag include_extras is set to True to correctly deal with the Annotated type.

To Reproduce
Steps to reproduce the behavior:

  1. Run the following script:
from __future__ import annotations

from azure.ai.ml.entities._inputs_outputs import _get_param_with_standard_annotation


def test_annotation(param: int):
    return


_get_param_with_standard_annotation(test_annotation, is_func=True)
  1. The exception trace:
Exception has occurred: UserErrorException       (note: full exception trace is shown but execution is paused at: _run_module_as_main)
Unsupported annotation type 'int' for parameter 'param'.
  File "C:\Users\someone\Documents\VSCode\.venvazureml\Lib\site-packages\azure\ai\ml\entities\_inputs_outputs\utils.py", line 142, in _get_fields
    raise UserErrorException(msg)
  File "C:\Users\someone\Documents\VSCode\.venvazureml\Lib\site-packages\azure\ai\ml\entities\_inputs_outputs\utils.py", line 337, in _get_param_with_standard_annotation
    annotation_fields = _get_fields(annotations)
                        ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\someone\Documents\VSCode\test_annotation.py", line 10, in <module>
    _get_param_with_standard_annotation(test_annotation, is_func=True)
  File "C:\Program Files\Python312\Lib\runpy.py", line 88, in _run_code
    exec(code, run_globals)
  File "C:\Program Files\Python312\Lib\runpy.py", line 198, in _run_module_as_main (Current frame)
    return _run_code(code, main_globals, None,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
azure.ai.ml.exceptions.UserErrorException: Unsupported annotation type 'int' for parameter 'param'.

Expected behavior
The type should be correctly recognized.

@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels May 8, 2024
@mchikyt3
Copy link
Author

mchikyt3 commented May 8, 2024

This issue is related to stringizing annotations as per PEP 563 and PEP 649. The problem can be solved by test_annotation.__annotations__.update(typing.get_type_hints(test_annotation)) though, but it's not recommended in the Annotations Best Practices.

@mchikyt3 mchikyt3 closed this as completed May 8, 2024
@mchikyt3 mchikyt3 changed the title Annotations of primitive types don't work in mldesigner.command_component decorated functions. azure.ai.ml.entities._inputs_outputs._get_param_with_standard_annotation doesn't support stringizized annotations. May 13, 2024
@mchikyt3 mchikyt3 changed the title azure.ai.ml.entities._inputs_outputs._get_param_with_standard_annotation doesn't support stringizized annotations. azure.ai.ml.entities._inputs_outputs._get_param_with_standard_annotation doesn't support stringizized annotations enabled by from __future__ import annotations. May 13, 2024
@mchikyt3 mchikyt3 reopened this May 13, 2024
mchikyt3 pushed a commit to mchikyt3/azure-sdk-for-python that referenced this issue May 13, 2024
@xiangyan99 xiangyan99 added Machine Learning Service Attention This issue is responsible by Azure service team. and removed needs-triage This is a new issue that needs to be triaged to the appropriate team. labels May 13, 2024
@github-actions github-actions bot added the needs-team-attention This issue needs attention from Azure service team or SDK team label May 13, 2024
Copy link

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @Azure/azure-ml-sdk @azureml-github.

@diondrapeck
Copy link
Member

Hi @mchikyt3 - thank you for bringing this to our attention. I see your PR to address it. Please let me know if you need help getting the tests green. Once it is ready for review, I can review it and help you get it merged.

Thank you for contributing.

@mchikyt3
Copy link
Author

Hi, @diondrapeck. Thank you for your reply. Regarding the test for the PR, I've found that the original code doesn't pass (see commit 261e93e). Please let me know if this is a known issue, or I've missed something. Thanks.

@diondrapeck
Copy link
Member

Can you link to the specific test/error log where you're seeing that? I don't see it in the errors for your PR.

@mchikyt3
Copy link
Author

I have reverted my changes, only leaving an empty comment to trigger testing. You may check the errors now #35599. Thanks.

@diondrapeck
Copy link
Member

Yes, I've confirmed this is a failure going on in main, unrelated to your PR. Please add your changes back and I'll review them. Once the main issue is fixed, we can get your PR tested objectively and merged. Thank you!

@mchikyt3
Copy link
Author

Thanks @diondrapeck. My changes are back now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. Machine Learning needs-team-attention This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

3 participants