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

Issue 2153/ Refactor PyTorch 64-Bit Data Type Conversion #2153 #2171

Merged

Conversation

teelrabbit
Copy link
Contributor

Made changes so it uses a function dtype_to_32bit that converts 64-bit data types to 32-bit data types.

@YifanShenSZ
Copy link
Collaborator

Thanks @teelrabbit for the proposed fix. We will need to also fix where all those "number to dtype" mapping are used, e.g. ops.py

@teelrabbit
Copy link
Contributor Author

Thanks @teelrabbit for the proposed fix. We will need to also fix where all those "number to dtype" mapping are used, e.g. ops.py

Makes sense. I'll do some testing and see I can use the current solution across all instances of where the mapping is used 🤙🏻

@teelrabbit
Copy link
Contributor Author

teelrabbit commented Mar 26, 2024

"number to dtype" mapping are used

Made some changes to the occurrences of NUM_TO_TORCH_DTYPE to use "dtype_to_32bit". Can you comfirm if this is what you intended by "number to dtype". https://pastes.dev/2oAOqJeDM1 @YifanShenSZ

db22515

'        np_type = nptype_from_builtin(target_dtype.dtype)
        dtype = NUMPY_DTYPE_TO_TORCH_NUM[np_type]	        dtype = NUMPY_DTYPE_TO_TORCH_NUM[np_type]


    torch_dtype = NUM_TO_TORCH_DTYPE[dtype]	    torch_dtype = dtype_to_32bit(dtype)
    if isinstance(_input, Var) and _input.can_be_folded_to_const():	    if isinstance(_input, Var) and _input.can_be_folded_to_const():
        # numpy -> torch -> torch cast -> numpy	        # numpy -> torch -> torch cast -> numpy
        # This path is needed to use the mapping of passed in dtypes to torch dtypes.	        # This path is needed to use the mapping of passed in dtypes to torch dtypes.

coremltools/converters/mil/frontend/torch/ops.py Outdated Show resolved Hide resolved
setup.py Outdated Show resolved Hide resolved
YifanShenSZ
YifanShenSZ previously approved these changes Apr 29, 2024
Copy link
Collaborator

@YifanShenSZ YifanShenSZ left a comment

Choose a reason for hiding this comment

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

One last minor revision needed, overall LGTM: As CI suggests, we should still keep the number keys 4 and 7, and update the corresponding values to 64-bit dtypes

Sorry about the review delay, we were on a change freeze due to 7.2 release 🙏 Many thanks for polishing coremltools!

@YifanShenSZ YifanShenSZ dismissed their stale review April 29, 2024 18:00

Waiting for last minor revision

Copy link
Collaborator

@YifanShenSZ YifanShenSZ left a comment

Choose a reason for hiding this comment

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

LGTM! CI ✅ Many thanks for contributing to coremltools!

@YifanShenSZ YifanShenSZ merged commit 0bef2d6 into apple:main Apr 30, 2024
@teelrabbit
Copy link
Contributor Author

LGTM! CI ✅ Many thanks for contributing to coremltools!
futurama-philip-fry

@teelrabbit
Copy link
Contributor Author

Also this issue should be closed out #2153 (comment)

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