Skip to content

Updates the kvcache func in TextDecoder to work with Swift6#289

Open
jdowd7 wants to merge 1 commit intoargmaxinc:mainfrom
jdowd7:fix-updateKVCacheFunc-Swift6
Open

Updates the kvcache func in TextDecoder to work with Swift6#289
jdowd7 wants to merge 1 commit intoargmaxinc:mainfrom
jdowd7:fix-updateKVCacheFunc-Swift6

Conversation

@jdowd7
Copy link

@jdowd7 jdowd7 commented Jan 2, 2025

Refactors this func to address the warning:

Capture of 'keyTensorPointer' with non-sendable type 'UnsafeMutableRawBufferPointer' in a @sendable closure; this is an error in the Swift 6 language mode

  • Simplified the index calculations by treating the 4D tensors as 2D (hidden_dim × seq_length)
  • Added bounds checking to prevent out-of-range access
  • Used direct array indexing with properly calculated linear indices
  • Simplified memory copying using direct pointer access for the slices

Tested in our application and its working as expected

@ZachNagengast
Copy link
Contributor

Thanks @jdowd7! Do you have any metrics on if there is a speed difference between the two implementations?

@jdowd7
Copy link
Author

jdowd7 commented Jan 2, 2025

Thanks @jdowd7! Do you have any metrics on if there is a speed difference between the two implementations?

Not yet, will benchmark and report back when I get a chance

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