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

[MacOS] Add MLProgram Gather op for CoreML EP #24387

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

carzh
Copy link
Contributor

@carzh carzh commented Apr 10, 2025

Description

Add MLProgram implementation for Gather

To support this change, I also added handling for converting int64 to int32 in model builder

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can commit the suggested changes from lintrunner.

@carzh carzh force-pushed the carzh/coreml-gather branch from 94a986d to 2591a76 Compare April 10, 2025 23:43
@carzh carzh requested a review from edgchen1 April 11, 2025 01:28
Comment on lines 184 to 185
// from: int64_data/raw, to: ints (use narrow to convert to int32)
// CoreML uses int32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this something we want to do for all int64 inputs?

Copy link
Contributor Author

@carzh carzh Apr 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, every CoreML op should have their int64 inputs converted to int32 and their int64 outputs converted to int32. CoreML doesn't support int64 for their ops (though I believe their spec includes a longints field). The path for adding constants already handles conversion from int64 to int32

Comment on lines +89 to +94
try {
return narrow<int32_t>(v);
} catch (const std::exception& e) {
ORT_THROW("Error converting int64 to int32 for tensor ", tensor_name, ": ", e.what(),
". Value (", v, ") exceeds int32 range.");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's nice that you're including more detail in the message.

however, generally, we try to avoid using try or catch directly in order to support builds with exceptions disabled. that's why those ORT_THROW and ORT_CATCH macros are there.

in this case, I think we can just call narrow and not bother with adding more info to the exception. if exceptions are enabled, it should be possible to follow a call stack back to this code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants