Skip to content

model: NPU-aware prefill_chunk_size default (512 on RBLN-CR) - #634

Merged
rebel-thkim merged 10 commits into
devfrom
pcc_by_npu
Jul 24, 2026
Merged

model: NPU-aware prefill_chunk_size default (512 on RBLN-CR)#634
rebel-thkim merged 10 commits into
devfrom
pcc_by_npu

Conversation

@rebel-thkim

@rebel-thkim rebel-thkim commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

What

Make the default prefill_chunk_size depend on the NPU type — 512 on RBLN-CR devices and 128 otherwise. CR NPUs use a larger prefill chunk for better prefill performance (PCC).

Changes

  • set_default_values: Resolve the NPU-based prefill_chunk_size default and its divisible-by-64 validation here, using rebel.get_npu_name(0) (guarded with or "" so compiling on a host without an attached NPU falls back to 128 instead of raising on "RBLN-CR" in None). This is the shared entry point that both decoderonly and gemma4 already route through via _update_attention_config, so the default is defined in one place.
  • decoderonly: Remove the prefill_chunk_size default/validation from the config constructor; _update_attention_config now captures the value returned by set_default_values.
  • gemma4: Drop the hardcoded 128 default from RBLNGemma4ForCausalLMConfig so it resolves at compile time through the shared path.

Notes

  • gemma3 (prefill_chunk_size or 256) is left as-is — existing behavior preserved.

Review feedback addressed

  • Dropped the _get_npu_name helper and its RBLN_FORCE_NPU_NAME / RBLN_TARGET_SOC env fallbacks; _resolve_npu / warn_deprecated_npu are back to using rebel.get_npu_name directly.
  • Moved the prefill_chunk_size default into set_default_values instead of duplicating it across each _update_rbln_config.

Test

  • py_compile + ruff check pass.
  • Added unit tests (tests/test_config.py::TestPrefillChunkSizeDefault) covering NPU-aware default resolution (512 on RBLN-CR, 128 otherwise), attached-NPU fallback, no-NPU fallback, explicit-value precedence, and divisible-by-64 validation — 8 passed.
  • Added an e2e wiring test (test_prefill_chunk_size_npu_wiring_e2e): pins npu=RBLN-CR03 in rbln_config, compiles tiny-llama without a CR device, asserts the resolved prefill_chunk_size is 512 and survives save/reload. Verified locally (9 passed, ~13s).

🤖 Generated with Claude Code

rebel-thkim and others added 2 commits July 16, 2026 12:26
- Guard `_get_npu_name()` returning None with `or ""` so compiling on a
  host without an attached NPU falls back to 128 instead of raising
  TypeError on `"RBLN-CR" in None`.
- Apply the same NPU-based default (512 on RBLN-CR, else 128) and the
  divisible-by-64 validation to gemma4, which reimplements
  `_update_rbln_config` without calling super(). The hardcoded 128
  default is dropped from RBLNGemma4ForCausalLMConfig so it resolves at
  compile time.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@rebel-thkim
rebel-thkim requested a review from rebel-jongho July 16, 2026 04:44
Comment thread src/optimum/rbln/utils/runtime_utils.py Outdated
Comment on lines +50 to +52
device_name = (
rebel.get_npu_name(0) or os.environ.get("RBLN_FORCE_NPU_NAME") or os.environ.get("RBLN_TARGET_SOC") or None
)

@rebel-jongho rebel-jongho Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is not needed. just use rebel.get_npu_name()

@rebel-jongho rebel-jongho left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

how about modifying set_default_values to set the default value of pcs?

Address review feedback:
- Drop the `_get_npu_name` helper and its env-var fallbacks; restore
  `_resolve_npu`/`warn_deprecated_npu` to use `rebel.get_npu_name`
  directly.
- Resolve the NPU-based `prefill_chunk_size` default (and the
  divisible-by-64 validation) inside `set_default_values`, the shared
  entry point both decoderonly and gemma4 already route through via
  `_update_attention_config`, instead of duplicating it in each
  `_update_rbln_config`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@rebel-thkim
rebel-thkim changed the base branch from main to dev July 16, 2026 07:15
rebel-thkim and others added 3 commits July 16, 2026 16:15
set_default_values took only the locally attached device
(rebel.get_npu_name(0)) into account, so compiling with an explicitly
pinned target NPU (rbln_config.npu) — e.g. targeting RBLN-CR from a host
without one — would pick the wrong default. Prefer the pinned npu and
fall back to the local device only when it is unset.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Resolve conflict in gemma4/configuration_gemma4.py: dev refactored
image-prefill handling to the single `image_prefill_chunk_size`
(#605) while this branch was based on the older `image_prefill_chunk_sizes`
form. Take dev's version wholesale and re-apply only the PCC change
(drop the hardcoded prefill_chunk_size=128 default so it resolves via
set_default_values, plus the docstring).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Moving the prefill_chunk_size default into set_default_values (called
from _update_attention_config) left it unresolved (None) when
validate_sliding_window ran first, crashing with
`TypeError: unsupported operand type(s) for -: 'int' and 'NoneType'`
for sliding-window models (e.g. Mistral). Run _update_attention_config
before the sliding-window block so prefill_chunk_size is set in time.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@rebel-jongho rebel-jongho left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

do we need any tests? or it's just a simple functionality?

rebel-thkim and others added 2 commits July 24, 2026 16:13
# Conflicts:
#	src/optimum/rbln/transformers/modeling_attention_utils.py
#	src/optimum/rbln/transformers/models/gemma4/configuration_gemma4.py
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@rebel-thkim

Copy link
Copy Markdown
Contributor Author

Resolved the merge conflict with dev (the repo-wide Optional[X]X | None typing migration touched the same lines) and added unit tests in tests/test_config.py covering the NPU-aware prefill_chunk_size resolution: 512 on RBLN-CR, 128 otherwise, fallback to the attached NPU (and to 128 when no NPU is attached), explicit values taking precedence, and the divisible-by-64 validation. All 8 tests pass locally without device compilation.

rebel-thkim and others added 2 commits July 24, 2026 16:30
Pin npu=RBLN-CR03 in rbln_config, compile without a CR device, and assert
the resolved prefill_chunk_size (512) survives save/reload.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The CI runner's compiler (dev371) fails cross-compiling for RBLN-CR03 on a
CA25 machine. Keep the wiring test but skip it, matching the existing
TestLlamaForCausalLM_fp8 pattern; unit tests still cover the resolution logic.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@rebel-thkim
rebel-thkim merged commit 3b90449 into dev Jul 24, 2026
7 checks passed
@rebel-thkim
rebel-thkim deleted the pcc_by_npu branch July 24, 2026 08:28
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