feat: add Einsum op, WithConstantVariables, and bug fixes#64
Open
ajroetker wants to merge 6 commits intogomlx:mainfrom
Open
feat: add Einsum op, WithConstantVariables, and bug fixes#64ajroetker wants to merge 6 commits intogomlx:mainfrom
ajroetker wants to merge 6 commits intogomlx:mainfrom
Conversation
Add Einsum op support (2-operand), WithConstantVariables option for inference-only workloads where variables must be compile-time constants, and fix several bugs found during code review: - Fix nil pointer dereference in onnxQLinearMatMul when yZeroPoint is nil - Collapse redundant if/else-if branches for zero-point subtraction - Fix convertIf returning nil instead of panicking on zero outputs - Fix convertSubGraph overwriting shared model maps without restoring originals - Fix prettyprint format verb for shapes.Shape (%d -> %v)
…ertSubGraph - Fix opsDesc assignment bug in materialize.go: `varDesc = append(opsDesc, ...)` was assigning to the wrong variable, leaving opsDesc always empty and overwriting varDesc in error messages. - Thread *context.Context through convertIf -> convertSubGraph -> convertNode so sub-graph nodes that depend on model variables can resolve them correctly instead of panicking on nil context.
Use Go's comma-ok idiom on the saved maps directly instead of maintaining separate boolean maps to track key existence. Nil is never a valid value in variableNameToValue or nodeOutputToNode, so checking the saved map entry suffices. Also adds a concurrency-safety note.
- ScatterND: fix error message printing data rank (r) instead of indices rank (q) - ConstantOfShape: make 'value' attribute optional per ONNX spec, defaulting to scalar float32 zero when absent - LSTM: fix copy-paste bug reading "activation_alpha" for activationBeta instead of "activation_beta", and fix "activaitons" typo - MultiHeadAttention: fix 2D mask reshape producing (1,batch,kv_seq,1) instead of (batch,1,1,kv_seq) by using Reshape directly - LayerNormalization: use bias tensor's own dimensions for biasShape instead of reusing scale dimensions - convertIf: use m.onnxWhere for dtype promotion between then/else branches instead of raw Where which panics on mismatched dtypes
… LayerNorm bias - CumSum: use adjustedAxis consistently (CumSum supports negative axes but other calls in the same function use adjustedAxis) - RotaryEmbedding: add bounds check requiring at least 4 inputs before accessing inputs[2] and inputs[3] - GroupQueryAttention: add rank check before accessing Dimensions[2] on past KV inputs to prevent index-out-of-range on malformed tensors - LayerNormalization: only allocate biasShape when bias is non-nil, and use bias's own dimensions instead of scale dimensions
Prepare onnxBroadcastToCommonShape and convertSlice for future dynamic dimension support in gomlx. Both functions now detect DynamicDim axes, preserve axis names for the specialization system, and fall through to existing concrete-dimension logic when all dims are static.
5 tasks
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.
Summary
New Features
Bug Fixes
adjustedAxisconsistently (CumSum supports negative axes but other calls in the same function were using the raw axis)inputs[2]andinputs[3]Dimensions[2]on past KV inputs to prevent index-out-of-range on malformed tensorsbiasShapewhen bias is non-nil, and use bias's own dimensions instead of scale dimensionsvalueattribute optional per ONNX spec, defaulting to scalar float32 zero when absentactivation_alphaforactivationBetainstead ofactivation_beta; fixactivaitonstypo(1,batch,kv_seq,1)instead of(batch,1,1,kv_seq)by using Reshape directlym.onnxWherefor dtype promotion between then/else branches instead of rawWherewhich panics on mismatched dtypes; panic with descriptive message when If node produces no outputs instead of returning nilyZeroPointis nil (.DType()was called before the nil check); collapse redundant if/else-if branches for zero-point subtractionnodeOutputToNode,variableNameToValue) without saving/restoring originals — sub-graph names colliding with main graph names could corrupt state; thread*context.Contextthrough so sub-graph nodes can resolve model variables correctlyvarDesc = append(opsDesc, ...)copy-paste bug that leftopsDescalways empty and overwrotevarDescin error messagesshapes.Shape(%d→%v)Simplifications
savedVariableExists/savedNodeExistsmaps — use Go's comma-ok idiom on the saved maps directly since nil is never a valid valueTest plan