Skip to content

Infer scalar type for attentionMask and causalMask from model IO#41

Open
Gunnarguy wants to merge 1 commit into
mainfrom
jules-infer-scalar-type-attention-mask-16516042149922076732
Open

Infer scalar type for attentionMask and causalMask from model IO#41
Gunnarguy wants to merge 1 commit into
mainfrom
jules-infer-scalar-type-attention-mask-16516042149922076732

Conversation

@Gunnarguy

Copy link
Copy Markdown
Owner

Replaced hardcoded Float16 with dynamically inferred scalar type (from modelDescription.inputDescriptionsByName) for attentionMask and causalMask in LanguageModelWithStatefulKVCache.predictNextTokenScores. Uses Float if .float32 is detected, and defaults back to Float16 otherwise.


PR created automatically by Jules for task 16516042149922076732 started by @Gunnarguy

Co-authored-by: Gunnarguy <110250624+Gunnarguy@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 24, 2026 23:19
@google-labs-jules

Copy link
Copy Markdown

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @Gunnarguy, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 attentionMask scalar type from modelDescription.inputDescriptionsByName and create the mask as Float when the model expects .float32, otherwise Float16.
  • Infer causalMask scalar type similarly, using Float for .float32 and Float16 otherwise.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +536 to 543
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
Comment on lines +550 to 557
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
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