Skip to content

Change how ModelModifier builds the result, i.e.#420

Merged
copybara-service[bot] merged 1 commit intomainfrom
test_877932514
Mar 12, 2026
Merged

Change how ModelModifier builds the result, i.e.#420
copybara-service[bot] merged 1 commit intomainfrom
test_877932514

Conversation

@copybara-service
Copy link
Contributor

@copybara-service copybara-service bot commented Mar 4, 2026

Change how ModelModifier builds the result, i.e.

  • Use ModelModifier._serialize_model, i.e. pack the model's Buffers separately, for models with more than 1 MiB of Buffers since we can do a much better job at this than flatbuffer's Python interface,
  • In ModelModifier._serialize_model, serialize the model (without Buffers) only once, and update the Buffers' offset and size values directly in the packed model,
  • Compute the exact buffer size and allocate it in one go (don't grow dynamically with .extend(...)), using bytearray and memoryview to avoid intermediate copies.

@copybara-service copybara-service bot force-pushed the test_877932514 branch 5 times, most recently from c053474 to 3f32bc9 Compare March 9, 2026 12:09
* Use `ModelModifier._serialize_model`, i.e. pack the model's `Buffer`s separately, for models with more than 1 MiB of `Buffer`s since we can do a much better job at this than `flatbuffer`'s Python interface,
* In `ModelModifier._serialize_model`, serialize the model (without `Buffer`s) only once, and update the `Buffer`s' `offset` and `size` values directly in the packed model,
* Compute the exact buffer size and allocate it in one go (don't grow dynamically with `.extend(...)`), using `bytearray` and `memoryview` to avoid intermediate copies.

PiperOrigin-RevId: 882765823
@copybara-service copybara-service bot merged commit ce26ec6 into main Mar 12, 2026
@copybara-service copybara-service bot deleted the test_877932514 branch March 12, 2026 21:00
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.

1 participant