gigatoken 0.2.2-aarch64-linux → 0.3.0-aarch64-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +13 -2
- data/lib/gigatoken/3.3/gigatoken_rb.so +0 -0
- data/lib/gigatoken/3.4/gigatoken_rb.so +0 -0
- data/lib/gigatoken/4.0/gigatoken_rb.so +0 -0
- data/lib/gigatoken/hub.rb +9 -2
- data/lib/gigatoken/packed_result.rb +7 -3
- data/lib/gigatoken/tokenizer.rb +8 -4
- data/lib/gigatoken/version.rb +1 -1
- data/rust-toolchain.toml +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 281a4ef78df3d94470e35cb463085c9da8e9bb3549c552bf6ab66f3bb4df47b1
|
|
4
|
+
data.tar.gz: f3d1531a68d00ab75abf45121b6a2df3ea113a7da39946b4e480ad7e4adea338
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fb9419f43f11adb7f0e181e5606b008f911439f486b332acc2ddbfd06e5e798721184ec6b37122e6dadc732b3543dc5666e3c53d38ad62a234948ba0c9abdc8e
|
|
7
|
+
data.tar.gz: f867d2440b5fda9a43fb67f9bd7b8159b933ee073eac1042e8176ccbbeef1ff69eefde75b6215dd8db1c909ece1dd7b6893a0d68b9c1217f2de459325024e180
|
data/README.md
CHANGED
|
@@ -15,7 +15,7 @@ Zero-copy Ruby bindings for [marcelroed/gigatoken](https://github.com/marcelroed
|
|
|
15
15
|
|
|
16
16
|
Mac Studio M4 Max, OpenWebText, GPT-2 tokenizer; every library produces the same tokenization, gigatoken just does it faster. The Python row includes a fix for [marcelroed/gigatoken#38](https://github.com/marcelroed/gigatoken/issues/38) — a hidden memcpy in `shrink_to_fit()` we found while chasing the last of the Ruby–Python gap and sent upstream (one-line fix; without it the wheel lands around 7.4 GB/s).
|
|
17
17
|
|
|
18
|
-
**340x faster** than the fastest existing Ruby gem (tiktoken_ruby) and **1,050x faster** than the tokenizers gem. Full methodology & exact counts: [docs/
|
|
18
|
+
**340x faster** than the fastest existing Ruby gem (tiktoken_ruby) and **1,050x faster** than the tokenizers gem. Full methodology & exact counts: [docs/explanation/benchmarks.md](docs/explanation/benchmarks.md).
|
|
19
19
|
|
|
20
20
|
## Install
|
|
21
21
|
|
|
@@ -119,7 +119,7 @@ packed[3] # => document 3's ids as an Array, on demand
|
|
|
119
119
|
|
|
120
120
|
### Async
|
|
121
121
|
|
|
122
|
-
`encode_batch` and `encode_files` release the GVL for the whole encode; the parallelism runs on the engine's rayon pool, not Ruby threads. Under `Async`, give the fiber scheduler a worker pool (`ASYNC_SCHEDULER_WORKER_POOL=true`) and the calling fiber yields to the reactor too. Design notes: [docs/
|
|
122
|
+
`encode_batch` and `encode_files` release the GVL for the whole encode; the parallelism runs on the engine's rayon pool, not Ruby threads. Under `Async`, give the fiber scheduler a worker pool (`ASYNC_SCHEDULER_WORKER_POOL=true`) and the calling fiber yields to the reactor too. Design notes: [docs/how-to/run-under-async.md](docs/how-to/run-under-async.md).
|
|
123
123
|
|
|
124
124
|
## CLI
|
|
125
125
|
|
|
@@ -138,6 +138,16 @@ gigatoken bench lib/gigatoken/encodings/cl100k_base.tiktoken README.md --pretoke
|
|
|
138
138
|
|
|
139
139
|
Leave it off against a `.tiktoken` TOKENIZER and both commands raise `Gigatoken::Error` naming the valid schemes instead of crashing; for every other TOKENIZER shape (`tokenizer.json`, a packaged name, a Hub repo id) `--pretokenizer` is accepted but ignored.
|
|
140
140
|
|
|
141
|
+
## Documentation
|
|
142
|
+
|
|
143
|
+
In-depth docs live under [`docs/`](docs/README.md), organized by
|
|
144
|
+
[Diátaxis](https://diataxis.fr/):
|
|
145
|
+
|
|
146
|
+
- **Tutorial:** [Getting started](docs/tutorials/getting-started.md)
|
|
147
|
+
- **How-to:** [Load a tokenizer](docs/how-to/load-a-tokenizer.md), [Tokenize files](docs/how-to/tokenize-files.md), [Packed results](docs/how-to/use-packed-results.md), [Cache budget](docs/how-to/tune-the-cache-budget.md), [Async](docs/how-to/run-under-async.md), [Measure](docs/how-to/measure-time-and-allocations.md)
|
|
148
|
+
- **Reference:** [`Tokenizer`](docs/reference/tokenizer.md), [`PackedResult`](docs/reference/packed-result.md), [File sources](docs/reference/file-sources.md), [Encodings and settings](docs/reference/encodings-and-settings.md), [CLI](docs/reference/cli.md)
|
|
149
|
+
- **Explanation:** [Benchmarks](docs/explanation/benchmarks.md), [Allocations](docs/explanation/allocations.md), [Async design](docs/explanation/async-design.md)
|
|
150
|
+
|
|
141
151
|
## Development
|
|
142
152
|
|
|
143
153
|
```bash
|
|
@@ -145,6 +155,7 @@ bundle install
|
|
|
145
155
|
bundle exec rake compile # native extension (Rust nightly, via rust-toolchain.toml)
|
|
146
156
|
bundle exec rspec
|
|
147
157
|
bundle exec standardrb
|
|
158
|
+
ruby -Ilib bench/operations.rb # every operation: i/s, objects and malloc per call
|
|
148
159
|
```
|
|
149
160
|
|
|
150
161
|
The Ruby layer is fiber-first throughout — no `Thread`, no `Mutex`; all parallelism lives in the core's rayon pool. CI runs ubuntu + macos × Ruby 3.3/3.4/4.0, and `release.yml` cross-builds the precompiled native gems (arm64-darwin, x86_64-linux, aarch64-linux).
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/lib/gigatoken/hub.rb
CHANGED
|
@@ -99,6 +99,12 @@ module Gigatoken
|
|
|
99
99
|
revision.match?(/\A[0-9a-f]{40}\z/)
|
|
100
100
|
end
|
|
101
101
|
|
|
102
|
+
# The Hub endpoint, resolved like huggingface_hub does it: HF_ENDPOINT,
|
|
103
|
+
# then https://huggingface.co.
|
|
104
|
+
def default_endpoint
|
|
105
|
+
env("HF_ENDPOINT") || DEFAULT_ENDPOINT
|
|
106
|
+
end
|
|
107
|
+
|
|
102
108
|
private
|
|
103
109
|
|
|
104
110
|
def env(key)
|
|
@@ -125,8 +131,9 @@ module Gigatoken
|
|
|
125
131
|
|
|
126
132
|
# @parameter endpoint [String] the Hub endpoint to fetch from — override
|
|
127
133
|
# for pointing at a local server in tests (dependency injection, not a
|
|
128
|
-
# mock).
|
|
129
|
-
|
|
134
|
+
# mock); defaults to Hub.default_endpoint (HF_ENDPOINT, then
|
|
135
|
+
# huggingface.co).
|
|
136
|
+
def initialize(endpoint: self.class.default_endpoint)
|
|
130
137
|
@endpoint = endpoint.chomp("/")
|
|
131
138
|
@internet = Async::HTTP::Internet.new
|
|
132
139
|
end
|
|
@@ -28,9 +28,13 @@ module Gigatoken
|
|
|
28
28
|
lens.sum
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
# Array of token ids for document `i`, materialized on demand
|
|
31
|
+
# Array of token ids for document `i`, materialized on demand; negative
|
|
32
|
+
# indices count from the end and out-of-range ones give nil, like Array.
|
|
32
33
|
def [](i)
|
|
33
|
-
|
|
34
|
+
i += size if i.negative?
|
|
35
|
+
return unless i >= 0 && i < size
|
|
36
|
+
|
|
37
|
+
buffer.values(:u32, @offsets[i] * 4, lens[i])
|
|
34
38
|
end
|
|
35
39
|
|
|
36
40
|
def each
|
|
@@ -42,7 +46,7 @@ module Gigatoken
|
|
|
42
46
|
# A ragged Array of Arrays, one per document — the same shape
|
|
43
47
|
# `encode_batch`/`encode_files` return with `packed: false`.
|
|
44
48
|
def to_a
|
|
45
|
-
|
|
49
|
+
Array.new(size) { |i| self[i] }
|
|
46
50
|
end
|
|
47
51
|
end
|
|
48
52
|
end
|
data/lib/gigatoken/tokenizer.rb
CHANGED
|
@@ -49,8 +49,8 @@ module Gigatoken
|
|
|
49
49
|
|
|
50
50
|
# Load tokenizer.json from HuggingFace Hub repo `repo_id` at `revision`
|
|
51
51
|
# (downloaded directly; huggingface_hub is not required).
|
|
52
|
-
def self.from_hub(repo_id, revision: "main", hub:
|
|
53
|
-
from_file(hub.hub_file(repo_id, "tokenizer.json", revision: revision))
|
|
52
|
+
def self.from_hub(repo_id, revision: "main", hub: nil)
|
|
53
|
+
from_file((hub || Hub.new).hub_file(repo_id, "tokenizer.json", revision: revision))
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
# Load from any of the supported source shapes: an existing file or
|
|
@@ -67,7 +67,7 @@ module Gigatoken
|
|
|
67
67
|
# here too, raising the same explanation from_encoding gives rather than
|
|
68
68
|
# reaching the Hub — but only those; an unrecognized bare name like
|
|
69
69
|
# "gpt2" still dispatches to the Hub.
|
|
70
|
-
def self.load(source, pretokenizer: nil, special_tokens: {}, revision: "main", hub:
|
|
70
|
+
def self.load(source, pretokenizer: nil, special_tokens: {}, revision: "main", hub: nil)
|
|
71
71
|
source = source.to_s
|
|
72
72
|
if source.end_with?(".tiktoken")
|
|
73
73
|
unless pretokenizer
|
|
@@ -83,8 +83,12 @@ module Gigatoken
|
|
|
83
83
|
raise Error, "#{source.inspect}: no such file or directory, not a .tiktoken path, and doesn't look like a HuggingFace Hub repo id"
|
|
84
84
|
end
|
|
85
85
|
|
|
86
|
+
# `data` is UTF-8 JSON whatever its encoding tag says (File.binread tags
|
|
87
|
+
# binary; a US-ASCII default_external tags that), so retag rather than let
|
|
88
|
+
# JSON.parse transcode from the tag; a UTF-8-tagged String needs no copy.
|
|
86
89
|
def self.special_tokens_from_json(data)
|
|
87
|
-
|
|
90
|
+
data = data.dup.force_encoding(Encoding::UTF_8) unless data.encoding == Encoding::UTF_8
|
|
91
|
+
added = JSON.parse(data)["added_tokens"] || []
|
|
88
92
|
added.each_with_object({}) { |t, h| h[t["content"]] = t["id"] if t["special"] }
|
|
89
93
|
end
|
|
90
94
|
private_class_method :special_tokens_from_json
|
data/lib/gigatoken/version.rb
CHANGED
data/rust-toolchain.toml
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
[toolchain]
|
|
2
|
-
channel = "nightly"
|
|
2
|
+
channel = "nightly-2026-09-18"
|
|
3
3
|
# Cross triples for the precompiled-gem builds (ruby-gem.yml). rustup's
|
|
4
4
|
# toolchain-file auto-install is the only thing that provisions nightly
|
|
5
5
|
# inside the rb-sys-dock containers, so the targets must be declared here —
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: gigatoken
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: aarch64-linux
|
|
6
6
|
authors:
|
|
7
7
|
- Eric Jacobs
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-09-
|
|
11
|
+
date: 2026-09-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: async
|