diff options
| author | Onur Gündüz <ogunduz@gmail.com> | 2026-06-16 16:27:47 +0200 |
|---|---|---|
| committer | Onur Gündüz <ogunduz@gmail.com> | 2026-06-16 16:27:47 +0200 |
| commit | d1ba1ebc06ef0d62ca932388fae83e6992594719 (patch) | |
| tree | f962207b779016593258f990348216999a58766a /src/tokenizer_bpe.h | |
| parent | be20dfda0f836808dccfc14db244592e41ba28bc (diff) | |
| download | ffwd-d1ba1ebc06ef0d62ca932388fae83e6992594719.tar.gz ffwd-d1ba1ebc06ef0d62ca932388fae83e6992594719.zip | |
chore: move sources to src/ with proper names, drop qwen_ prefix
Diffstat (limited to '')
| -rw-r--r-- | src/tokenizer_bpe.h (renamed from qwen_tokenizer.h) | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/qwen_tokenizer.h b/src/tokenizer_bpe.h index f7a3941..8d13d47 100644 --- a/qwen_tokenizer.h +++ b/src/tokenizer_bpe.h @@ -1,13 +1,13 @@ /* - * qwen_tokenizer.h - Qwen2/Qwen3 BPE tokenizer (GPT-2 byte-level) + * embed_tokenizer.h - Qwen2/Qwen3 BPE tokenizer (GPT-2 byte-level) * * Supports: * - decode token ID -> UTF-8 text * - encode UTF-8 text -> token IDs (vocab.json + merges.txt) */ -#ifndef QWEN_TOKENIZER_H -#define QWEN_TOKENIZER_H +#ifndef EMBED_TOKENIZER_H +#define EMBED_TOKENIZER_H /* Public-API export annotation. The libraries are built with * -fvisibility=hidden, so only declarations carrying EMBED_API are exported @@ -38,49 +38,49 @@ typedef struct { /* Byte-level unicode codepoint -> single-character token id (512 slots), * or NULL when any byte token is missing from the vocab. */ int *cp_to_id; -} qwen_tokenizer_t; +} embed_tokenizer_t; -typedef struct qwen_tokenizer_workspace qwen_tokenizer_workspace_t; +typedef struct embed_tokenizer_workspace embed_tokenizer_workspace_t; /* Load tokenizer from vocab.json in model directory */ -EMBED_API qwen_tokenizer_t *qwen_tokenizer_load(const char *vocab_json_path); +EMBED_API embed_tokenizer_t *embed_tokenizer_load(const char *vocab_json_path); /* Decode a single token ID to text. Returns pointer to internal string. */ -EMBED_API const char *qwen_tokenizer_decode(const qwen_tokenizer_t *tok, int token_id); +EMBED_API const char *embed_tokenizer_decode(const embed_tokenizer_t *tok, int token_id); /* Look up the id of a raw vocab.json token string (e.g. "<|endoftext|>"). * Returns -1 when the token is not in the vocab. */ -EMBED_API int qwen_tokenizer_token_id(const qwen_tokenizer_t *tok, const char *token); +EMBED_API int embed_tokenizer_token_id(const embed_tokenizer_t *tok, const char *token); /* Encode UTF-8 text into token IDs using BPE. * Returns malloc'd array of token IDs and sets *out_n_tokens. * Returns NULL on error (and sets *out_n_tokens to 0). */ EMBED_API int * -qwen_tokenizer_encode(const qwen_tokenizer_t *tok, const char *text, int *out_n_tokens); +embed_tokenizer_encode(const embed_tokenizer_t *tok, const char *text, int *out_n_tokens); /* Reusable scratch for allocation-light repeated encoding. */ -EMBED_API qwen_tokenizer_workspace_t *qwen_tokenizer_workspace_new(void); -EMBED_API void qwen_tokenizer_workspace_free(qwen_tokenizer_workspace_t *ws); +EMBED_API embed_tokenizer_workspace_t *embed_tokenizer_workspace_new(void); +EMBED_API void embed_tokenizer_workspace_free(embed_tokenizer_workspace_t *ws); /* Encode into caller-provided out_ids[0..out_cap-1]. * Returns 0 on success, -1 on error, -2 if out_cap is too small. * In all cases *out_n_tokens is set to the number of tokens needed/emitted * when out_n_tokens is non-NULL. */ -EMBED_API int qwen_tokenizer_encode_into(const qwen_tokenizer_t *tok, - qwen_tokenizer_workspace_t *ws, +EMBED_API int embed_tokenizer_encode_into(const embed_tokenizer_t *tok, + embed_tokenizer_workspace_t *ws, const char *text, int *out_ids, int out_cap, int *out_n_tokens); -/* Same tokenization as qwen_tokenizer_encode(), but reuses ws internally and +/* Same tokenization as embed_tokenizer_encode(), but reuses ws internally and * performs only the final returned int[] allocation. */ -EMBED_API int *qwen_tokenizer_encode_with_workspace(const qwen_tokenizer_t *tok, - qwen_tokenizer_workspace_t *ws, +EMBED_API int *embed_tokenizer_encode_with_workspace(const embed_tokenizer_t *tok, + embed_tokenizer_workspace_t *ws, const char *text, int *out_n_tokens); /* Free tokenizer */ -EMBED_API void qwen_tokenizer_free(qwen_tokenizer_t *tok); +EMBED_API void embed_tokenizer_free(embed_tokenizer_t *tok); -#endif /* QWEN_TOKENIZER_H */ +#endif /* EMBED_TOKENIZER_H */ |
