Skip to content

Conversation

@youzow3
Copy link

@youzow3 youzow3 commented Sep 27, 2025

Description

Add CastLike grad implementation.

Motivation and Context

Some models use CastLike instead of Cast, which prevents on-device training artifacts from being generated.

@youzow3
Copy link
Author

youzow3 commented Sep 27, 2025

@microsoft-github-policy-service agree

Copy link
Member

@snnn snnn left a comment

Choose a reason for hiding this comment

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

Thanks for adding the gradient for CastLike! The implementation looks correct.

I have one suggestion regarding the test:

The new test CastLikeGrad is a good starting point. As the TODO comment mentions, it would be great to add more test cases to cover various type combinations, similar to the existing CastGrad test. This would ensure that the gradient calculation is correct when casting between different data types (e.g., float to double, float to int32, etc.).

Other than that, the changes look good to me.

@youzow3
Copy link
Author

youzow3 commented Sep 28, 2025

Updated the test code but I'm not sure this is correct code to test cast between float-double.
Also, I think integer types cannot have gradient and gradient for "target_type" is always 0, so I don't think we need tests for cast between integer to float or float to integer.

@youzow3 youzow3 requested a review from snnn October 2, 2025 12:25
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