Handle UnionAll Broadcasted in broadcast override inference#3267
Draft
vchuravy wants to merge 1 commit into
Draft
Handle UnionAll Broadcasted in broadcast override inference#3267vchuravy wants to merge 1 commit into
vchuravy wants to merge 1 commit into
Conversation
`widenconst` can yield a `UnionAll` `Broadcasted` type (free Axes/F/Args parameters), which has no `.parameters` field, causing a `FieldError` during inference of the broadcast mapreduce/foldl override. Guard both helpers so they conservatively skip the override when the type is not a fully-specified `DataType`. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Inference crashes with a
FieldErrorwhen Enzyme's broadcast mapreduce/foldl override is consulted for aBroadcastedtype thatwidenconstleft only partially specified (aUnionAllwith freeAxes/F/Argsparameters):bc_or_array_or_number_tyandhas_arraymatchTy <: Broadcast.Broadcasted{...}and then directly readTy.parameters[4](the broadcast args tuple type). That access assumesTyis a concreteDataType, but aUnionAllhas noparametersfield. This was hit in the wild by the SVD reverse rule in TensorKit, which produces such a partially-specifiedBroadcastedtype.Fix
Guard both helpers so they bail out (return
false) whenTyis not a fully-specifiedDataType. Returningfalseis the conservative, correct choice: when the args tuple type is unknown, Enzyme simply skips the broadcast override and falls back to the normal AD path instead of crashing.Testing
🤖 Generated with Claude Code