fix(tokenizer): build a tokenizer from GPT-2 slow files (vocab.json + merges.txt)

オープン
#3,569 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
57/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
rust
領域
backend

調査の方向性

Start in src/tokenizer/mod.rs: read the Qwen2 slow-tokenizer detection and builder, the shared vocab validation, and the load_tokenizer fallback order. Add GPT-2 fixture coverage for successful loading and conflicting added-token IDs, then compare encoding against the listed Transformers outputs. Remove the workaround sentence from docs/supported-models.md; it is done when the tokenizer tests pass and all acceptance examples match.

索引モデルが issue の本文から書いたものです。

説明

area:models modeltype:text priority:medium status:in-progress type:bug

Problem

Nikity/lille-130m-instruct ships vocab.json, merges.txt and a tokenizer_config.json with "tokenizer_class": "GPT2Tokenizer", but no tokenizer.json. Loading it fails. Reproduced on main with a view of models/lille-130m-instruct that leaves out tokenizer.json: MLXCEL_DEVICE=cpu mlxcel generate -m <view> -p Hello prints No tokenizer found in ... (tried tokenizer.json, tokenizer.model, *.tiktoken, tokenizer.jsonl, and vocab.json + merges.txt). docs/supported-models.md:90 tells users to copy a tokenizer.json in by hand.

Cause

The vocab.json + merges.txt fallback (src/tokenizer/mod.rs:2112-2119) is Qwen2-only. is_qwen2_slow_tokenizer_dir (:1516-1530) accepts only Qwen2Tokenizer/Qwen2TokenizerFast, and the existing test detects_a_qwen2_slow_tokenizer_directory asserts that a GPT2Tokenizer directory is refused. That refusal is correct. build_qwen2_bpe_tokenizer (:1572) applies NFC and the Qwen2 split regex, so GPT-2 text would tokenize differently. It also refuses any added token whose id is inside the base vocab, and Lille's five specials (32763-32767) are already in vocab.json with those same ids.

Proposed Solution

Add is_gpt2_slow_tokenizer_dir (GPT2Tokenizer or GPT2TokenizerFast) and build_gpt2_bpe_tokenizer, and try them right after the Qwen2 fallback. The builder follows transformers' GPT2Converter:

  • byte-level BPE, no normalizer
  • ByteLevel(add_prefix_space, trim_offsets=true, use_regex=true) pre-tokenizer and decoder
  • ByteLevel(trim_offsets=false) post-processor, or a BOS template when add_bos_token is true

add_prefix_space comes from tokenizer_config.json and defaults to false. Move the vocab/merges parsing and validate_dense_vocab_ids into a shared helper rather than copying them. Accept an added token inside the base vocab only when vocab.json maps that content to the same id. Refuse it otherwise.

Acceptance Criteria

  • New failing unit test: load_tokenizer on a write_qwen2_slow_tokenizer_dir(&dir, "GPT2Tokenizer") fixture succeeds (fails today with No tokenizer found), and a conflicting added-token id is refused
  • On the Lille view without tokenizer.json, encoding matches transformers 5.24.1: Hello -> [18435], Hello, world! -> [18435, 11, 995, 0], <|user|>Hi there<|assistant|> -> [32766, 15902, 612, 32765], naïve café 123 -> [12385, 26884, 303, 19945, 2634, 17031]
  • The workaround sentence is removed from docs/supported-models.md:90

Verification

cargo test --lib tokenizer::tests
MLXCEL_DEVICE=cpu cargo run --release -- generate -m <view-without-tokenizer.json> -p Hello -n 8
主要言語
Rust
スター
505
フォーク
81
平均マージ
14時間 2分
マージ済み PR(30日)
448

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

lablup/mlxcel のほかの issue

lablup/mlxcel の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。