Infer scalar type for attentionMask and causalMask from model IO#41
Infer scalar type for attentionMask and causalMask from model IO#41Gunnarguy wants to merge 1 commit into
Conversation
Co-authored-by: Gunnarguy <110250624+Gunnarguy@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Sorry @Gunnarguy, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
There was a problem hiding this comment.
Pull request overview
Updates the CoreML stateful KV-cache language model implementation to choose the scalar type for attentionMask and causalMask based on the model’s declared input data types, rather than always using Float16. This aligns mask tensor creation with the actual model I/O descriptors and helps support models exported with float32 mask inputs.
Changes:
- Infer
attentionMaskscalar type frommodelDescription.inputDescriptionsByNameand create the mask asFloatwhen the model expects.float32, otherwiseFloat16. - Infer
causalMaskscalar type similarly, usingFloatfor.float32andFloat16otherwise.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let isFloat32 = modelDescription.inputDescriptionsByName[Keys.attentionMask]?.multiArrayConstraint?.dataType == .float32 | ||
| let attentionMask: MLTensor | ||
| if isFloat32 { | ||
| attentionMask = MLTensor(zeros: [1, 1, 1, tokenCount + 1], scalarType: Float.self) | ||
| } else { | ||
| attentionMask = MLTensor(zeros: [1, 1, 1, tokenCount + 1], scalarType: Float16.self) | ||
| } | ||
| inputDictionary[Keys.attentionMask] = attentionMask |
| let isFloat32 = modelDescription.inputDescriptionsByName[Keys.causalMask]?.multiArrayConstraint?.dataType == .float32 | ||
| let causalMask: MLTensor | ||
| if isFloat32 { | ||
| causalMask = MLTensor(zeros: [1, 1, 1, tokenCount + 1], scalarType: Float.self) | ||
| } else { | ||
| causalMask = MLTensor(zeros: [1, 1, 1, tokenCount + 1], scalarType: Float16.self) | ||
| } | ||
| inputDictionary[Keys.causalMask] = causalMask |
Replaced hardcoded
Float16with dynamically inferred scalar type (frommodelDescription.inputDescriptionsByName) forattentionMaskandcausalMaskinLanguageModelWithStatefulKVCache.predictNextTokenScores. UsesFloatif.float32is detected, and defaults back toFloat16otherwise.PR created automatically by Jules for task 16516042149922076732 started by @Gunnarguy