Skip to content

fix: raise ValueError in get_subword_id when bucket == 0 - #15

Merged
munlicode merged 1 commit into
munlicode:mainfrom
bact:fix/subword-id-bucket-zero
Oct 4, 2026
Merged

munlicode merged 1 commit into
munlicode:mainfrom
bact:fix/subword-id-bucket-zero

Conversation

@bact

@bact bact commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Default supervised models have bucket=0, so getSubwordId and getSubwordVector did hash % 0: SIGFPE on x86_64, out-of-range id on arm64.

This fix will throw std::invalid_argument (ValueError in Python) instead.

Default supervised models have bucket=0, so getSubwordId and getSubwordVector did `hash % 0`: SIGFPE on x86_64, out-of-range id on arm64.

This fix will throw std::invalid_argument (ValueError in Python) instead.

Signed-off-by: Arthit Suriyawongkul <[email protected]>
@bact

bact commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Note that the test currently uses threads = 10 to avoid NaN bug.
Once #14 is merged, we can change the number of threads to anything, or drop the setting (will be default, 0).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The fix is covered for the reported case, and remaining feedback is limited to minor nits.

Review effort: Lite
Findings: None

What changed in this PR

Fixes subword handling for models with no buckets by raising ValueError instead of performing invalid modulo operations.

Changes:

  • Validates bucket counts in subword ID and vector methods.
  • Adds a Python regression test for zero-bucket models.
File Summary
src/​fasttext.cc Adds guards for non-positive buckets. Minor nits note untested getSubwordVector coverage and misleading negative-bucket diagnostics.
python/​fasttext_module/​fasttext/​tests/​test_script.py Verifies get_subword_id raises ValueError.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@munlicode munlicode left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Merging. Thanks for PR. ^_^

@munlicode
munlicode merged commit 7dddc91 into munlicode:main Oct 4, 2026
9 checks passed
@bact
bact deleted the fix/subword-id-bucket-zero branch October 4, 2026 09:42
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.

3 participants