Skip to content

Fix module-config tensor init: shape-bounded randint high, int-dtype randint, float-dtype xavier, bfloat16 default, int64 for index tensors - #228

Merged
moriohara merged 6 commits into
mainfrom
fix/module-config-tensor-init-defaults
Aug 10, 2026
Merged

Fix module-config tensor init: shape-bounded randint high, int-dtype randint, float-dtype xavier, bfloat16 default, int64 for index tensors#228
moriohara merged 6 commits into
mainfrom
fix/module-config-tensor-init-defaults

Conversation

@kiszk

@kiszk kiszk commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes four defects in the auto-generated module test configs and the generator/API that produces them (utils/module_discovery/auto_generate_module_config.py). The source fixes make future regenerations correct; the four existing YAMLs under tests/configs/module_tests/ are updated to match.
Fixes #225

Problems & fixes

1. randint upper bound was a fixed 10000

_tensor_info_to_spec set the exclusive upper bound of integer tensors to a fixed 10000, unrelated to the tensor's own shape. For index/position/cache tensors this produces out-of-range values and unexpected element accesses.

Fix (source): high = max(min(shape), 1) — the tensor's smallest dimension, guarded to be ≥ 1.

2. Integer tensors initialized with randn

Some torch.int32/torch.int64 tensors used init: xavier. torch.randn (normal_kernel_cpu) or xavier is float-only and raises NotImplementedError for integer dtypes.

Fix (source): any integer dtype (int/uint/long/short/bool) now always uses randint.

3. Floating-point tensors defaulted to float32 instead of bfloat16

from_pretrained defaults to float32, so models loaded without an explicit dtype recorded float tensors as float32. Spyre runs in bfloat16, so bfloat16 should be the default in both the generator and the API.

Fix (source):

  • New DEFAULT_FLOAT_DTYPE = torch.bfloat16 constant.
  • APIload_model_only now setdefaults torch_dtype to bfloat16 (explicit caller values still honored).
  • YAML generator_tensor_info_to_spec normalizes any captured float dtype (float16/32/64/half/double) to bfloat16 on emit.

4. Special (index) tensors kept a floating-point dtype

Tensors matched by _is_special_tensor() (name contains position/mask/ids) carry indices, not activations, and are always initialized with randint. Some - notably position_embeddings were captured under a floating-point dtype, leaving the inconsistent combination of a float dtype with randint init.

Fix (source): _is_special_tensor() for position_embeddings returns False.

YAML changes

Applied to all four configs (granite_3_3_8b_instruct, granite_4_1_8b, Ministral-3-14B-Instruct-2512, Mistral-Small-3.2-24B-Instruct-2506):

  • Every high: 10000 → the tensor's smallest dimension (cache_position [128]128, all others → 1).
  • Integer tensors with init: randninit: randint (+ init_args.high) — hit the RotaryEmbedding inputs in granite_4_1_8b and Mistral-Small.
  • Float tensors with init: randninit: xavier for numerical stability
  • Tensor dtype: torch.float32torch.bfloat16 — in granite_4_1_8b and Mistral-Small.
  • position_embeddings tensor-list entries (float dtype + randint) → init: xavier — 8 per file across all four configs.

Comments, YAML anchors (&id001/*id001), and the supported_dtypes global block are preserved.

kiszk added 4 commits July 22, 2026 02:28
Signed-off-by: Kazuaki Ishizaki <ishizaki@jp.ibm.com>
Signed-off-by: Kazuaki Ishizaki <ishizaki@jp.ibm.com>
Signed-off-by: Kazuaki Ishizaki <ishizaki@jp.ibm.com>
Signed-off-by: Kazuaki Ishizaki <ishizaki@jp.ibm.com>
@kiszk
kiszk marked this pull request as ready for review July 22, 2026 03:33
@kiszk
kiszk requested a review from anubhavjana as a code owner July 22, 2026 03:33
@kiszk

kiszk commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator Author

@moriohara @anubhavjana Could you please review this PR?

@kiszk
kiszk requested a review from moriohara July 22, 2026 03:34
moriohara
moriohara previously approved these changes Jul 23, 2026

@moriohara moriohara left a comment

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.

lgtm

@moriohara
moriohara added this pull request to the merge queue Aug 10, 2026
@spyre-ci

spyre-ci Bot commented Aug 10, 2026

Copy link
Copy Markdown

🔄 merge-queue-integration: running

:hammer_and_wrench: orch *trigger-pr-validation* · arches amd64 · fp amd64=d5ec218f
L0 torch-spyre/torch-spyre-dev amd64 🔨
L1 hf-adapters/hf-adapters-dev amd64 ⏳
L2 spyre-inference/spyre-inference-dev amd64 ⏳

Merged via the queue into main with commit 762a907 Aug 10, 2026
79 of 80 checks passed
assaftibm pushed a commit that referenced this pull request Aug 10, 2026
…randint, float-dtype xavier, bfloat16 default, int64 for index tensors (#228)

* use xavier for initialization

Signed-off-by: Kazuaki Ishizaki <ishizaki@jp.ibm.com>

* update YAML files

Signed-off-by: Kazuaki Ishizaki <ishizaki@jp.ibm.com>

* Fix handling of position_embeddings

Signed-off-by: Kazuaki Ishizaki <ishizaki@jp.ibm.com>

* Fix comments

Signed-off-by: Kazuaki Ishizaki <ishizaki@jp.ibm.com>

---------

Signed-off-by: Kazuaki Ishizaki <ishizaki@jp.ibm.com>
Co-authored-by: Moriyoshi Ohara <ohara@jp.ibm.com>
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.

Unexpected entries in YAML files for module tests

3 participants