Skip to content

Batch PICache Mamba-slot releases - #9

Open
morluto wants to merge 1 commit into
redai-studio:mainfrom
morluto:agent/pic-batched-frees
Open

morluto wants to merge 1 commit into
redai-studio:mainfrom
morluto:agent/pic-batched-frees

Conversation

@morluto

@morluto morluto commented Jul 28, 2026

Copy link
Copy Markdown

Motivation

PICache currently releases Mamba slots one at a time. Every released slot constructs a separate tensor and calls the allocator independently, producing repeated device work and repeated torch.cat operations.

Before

slot 1 --> tensor([1]) --> free() --> torch.cat
slot 2 --> tensor([2]) --> free() --> torch.cat
  ...                                  ...
slot N --> tensor([N]) --> free() --> torch.cat

After

[slot 1, slot 2, ..., slot N]
              |
              v
       one device tensor
              |
              v
       one free()/torch.cat

Modifications

  • Collect the Mamba slot IDs released by a cache operation.
  • Construct one tensor for the complete collection.
  • Return all collected slots through one allocator call.
  • Preserve the existing cache-removal and ownership semantics.

Accuracy Tests

Not applicable. The change preserves allocator state and cache contents while batching the release operation.

Speed Tests and Profiling

A focused CPU allocator benchmark was run seven times for each batch size:

Released slots Before After Improvement
128 3.223 ms 0.599 ms 5.4x
512 8.065 ms 1.186 ms 6.8x
1,024 17.973 ms 2.406 ms 7.5x

These measurements isolate state-allocator bookkeeping; they are not end-to-end inference timings.

Test Plan

4 passed

The focused tests passed locally and on a clean DigitalOcean Linux environment at commit 98b7618a06a0aa1089324d49a78d4bc4674d1642.

Coverage verifies:

  • Multiple slots are returned in one allocator call.
  • Released slot IDs remain correct.
  • Empty releases do not invoke the allocator.
  • Existing cache-removal behavior is preserved.

Closes #5.

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.

[Performance] Batch PICache Mamba-slot releases

1 participant