Skip to content

fix CI tests on main - #857

Closed
davidkoski wants to merge 1 commit into
mainfrom
fix-ci-2
Closed

davidkoski wants to merge 1 commit into
mainfrom
fix-ci-2

Conversation

@davidkoski

Copy link
Copy Markdown
Member

Proposed changes

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

AI usage

  • I have read this PR description in full and approve it as my own, and it
    accurately describes the code changes.
  • AI usage disclosure: claude used to track down root cause and prepare fixes

Comment on lines 336 to +338
try makeHybridAttentionKVCache(
parameters: parameters, slidingWindow: slidingWindow,
usesSlidingWindow: $0 == .slidingAttention)
usesSlidingWindow: $0 == .slidingAttention, headDim: headDim)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This was added in #676 but #704 adds a headHim to Qwen3Model. We need to be able to thread that through.

return try makeSlidingWindowKVCache(parameters: parameters, window: slidingWindow)
}
return try makeAttentionKVCache(parameters: parameters)
return try makeAttentionKVCache(parameters: parameters, headDim: headDim)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

#676 and #704 part 2


/// The layer compresses once it holds more than this many tokens. `nil`
/// when the layer does not compress.
/// when the layer does not compress or starts compressed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Side effect of this fix (qwen3 behavior from #704 now in the reranker)

Comment on lines +605 to +615
if let configuration {
probeParameters?.kvCache = KVCacheConfiguration(
capacity: configuration.capacity, compatibility: configuration.compatibility,
rewind: configuration.rewind)
probeParameters?.maxKVSize = nil
probeParameters?.kvBits = nil
probeParameters?.kvScheme = nil
probeParameters?.kvGroupSize = 64
probeParameters?.quantizedKVStart = 0
}
let cache = try newCache(parameters: probeParameters)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

#704 plus #852 -- now qwen3 produces a VarianceNormalizedKVCache

#expect(abs(chunked.query - reference.query).max().item(Float.self) < 1e-4)
// TF32 matmuls (neural accelerators) leave ~1.2e-3 at step size 1; see MatmulPrecision.
expectClose(chunked.documents, reference.documents, atol: 1e-4, reducedAtol: 5e-3)
expectClose(chunked.query, reference.query, atol: 1e-4, reducedAtol: 5e-3)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Two NAX fixes, just use MatmulPrecision

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Kept your commit int #858 also .

- cnflict between #676 and #704
- conflic between #852 and #704
- NAX tolerance issues (not seen in CI but seen locally when testing)
@aleroot

aleroot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Aarg, sorry about this one, I need to start avoiding optional params: #704's headDim: Int? = nil let #676's new call compile without it, and Qwen3 silently stayed on the old path 🙈. We can probably follow up with something like:

public enum KVCacheStart: Sendable {
    /// The model's attention reads compressed caches from the first prefill.
    case compressed(headDim: Int)
    /// Prefill fills a full-precision cache and converts it afterwards.
    case deferred
}

public func makeAttentionKVCache(
    parameters: GenerateParameters?, start: KVCacheStart
) throws -> KVCache

@available(*, deprecated, message: "Pass start: explicitly")
public func makeAttentionKVCache(
    parameters: GenerateParameters?, headDim: Int? = nil
) throws -> KVCache {
    try makeAttentionKVCache(
        parameters: parameters,
        start: headDim.map { .compressed(headDim: $0) } ?? .deferred)
}

@davidkoski what do you think?

The same goes for makeHybridAttentionKVCache. A new call site then can't compile without choosing, and existing callers keep building with a warning that points them to the new form. Maybe add something similar to this PR?

@davidkoski

Copy link
Copy Markdown
Member Author

No worries -- a lot of PRs in the same area, it is bound to happen. I suppose I should trigger a rebase before merging if I see some in the same area.

Anyway, that is why it is not wise to deploy off main :-)

Yes, I think non-optional might be the way to go here (with the deprecation) and the enum makes sense. Do you want to make the fix -- it is easier for me to review your change than get people on my side to review mine (people are out for conferences, vacation, etc). Feel free to lift any (or none) of this that you want.

@aleroot

aleroot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Thanks @davidkoski added in #858 , please note there are a lot of changes to conform to this new typed rule, this should help even when people just blindly use agents as this force the agent to think about a choice ...

@davidkoski

Copy link
Copy Markdown
Member Author

Replaced with #858

@davidkoski davidkoski closed this Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants