bytepft 0.1.0__tar.gz
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.
- bytepft-0.1.0/.github/workflows/ci.yml +27 -0
- bytepft-0.1.0/.github/workflows/publish.yml +76 -0
- bytepft-0.1.0/.gitignore +10 -0
- bytepft-0.1.0/CHANGELOG.md +43 -0
- bytepft-0.1.0/CONTRIBUTING.md +84 -0
- bytepft-0.1.0/LICENSE +201 -0
- bytepft-0.1.0/NOTICE +8 -0
- bytepft-0.1.0/PKG-INFO +119 -0
- bytepft-0.1.0/README.md +92 -0
- bytepft-0.1.0/STATUS.md +109 -0
- bytepft-0.1.0/configs/qwen3_06b.yaml +40 -0
- bytepft-0.1.0/configs/tiny_smoke.yaml +33 -0
- bytepft-0.1.0/docs/architecture.md +120 -0
- bytepft-0.1.0/docs/mps.md +51 -0
- bytepft-0.1.0/docs/releases.md +62 -0
- bytepft-0.1.0/docs/research.md +138 -0
- bytepft-0.1.0/docs/results/ci_validation.json +23 -0
- bytepft-0.1.0/docs/results/local_validation.json +36 -0
- bytepft-0.1.0/docs/results/mps_validation.json +42 -0
- bytepft-0.1.0/docs/results/qwen_cpu_smoke.json +40 -0
- bytepft-0.1.0/docs/results/qwen_mps_smoke.json +42 -0
- bytepft-0.1.0/docs/results/tiny_cpu_example.json +133 -0
- bytepft-0.1.0/docs/training.md +205 -0
- bytepft-0.1.0/examples/byte_tokenizer.py +25 -0
- bytepft-0.1.0/examples/compare_models.py +71 -0
- bytepft-0.1.0/examples/qwen_cpu_smoke.py +173 -0
- bytepft-0.1.0/examples/retrofit_qwen.py +60 -0
- bytepft-0.1.0/examples/train_tiny_model.py +102 -0
- bytepft-0.1.0/pyproject.toml +55 -0
- bytepft-0.1.0/scripts/prepare_release.py +40 -0
- bytepft-0.1.0/src/bytepft/__init__.py +18 -0
- bytepft-0.1.0/src/bytepft/_version.py +8 -0
- bytepft-0.1.0/src/bytepft/adapters/__init__.py +12 -0
- bytepft-0.1.0/src/bytepft/adapters/base.py +40 -0
- bytepft-0.1.0/src/bytepft/adapters/qwen.py +291 -0
- bytepft-0.1.0/src/bytepft/api.py +164 -0
- bytepft-0.1.0/src/bytepft/cli.py +176 -0
- bytepft-0.1.0/src/bytepft/config.py +149 -0
- bytepft-0.1.0/src/bytepft/evaluation/__init__.py +6 -0
- bytepft-0.1.0/src/bytepft/evaluation/benchmarks.py +65 -0
- bytepft-0.1.0/src/bytepft/evaluation/metrics.py +70 -0
- bytepft-0.1.0/src/bytepft/exceptions.py +21 -0
- bytepft-0.1.0/src/bytepft/inference/__init__.py +6 -0
- bytepft-0.1.0/src/bytepft/inference/cache.py +24 -0
- bytepft-0.1.0/src/bytepft/inference/generation.py +259 -0
- bytepft-0.1.0/src/bytepft/models/__init__.py +1 -0
- bytepft-0.1.0/src/bytepft/models/boundaries.py +162 -0
- bytepft-0.1.0/src/bytepft/models/byte_model.py +164 -0
- bytepft-0.1.0/src/bytepft/models/decoder.py +35 -0
- bytepft-0.1.0/src/bytepft/models/depooling.py +37 -0
- bytepft-0.1.0/src/bytepft/models/embeddings.py +42 -0
- bytepft-0.1.0/src/bytepft/models/encoder.py +27 -0
- bytepft-0.1.0/src/bytepft/models/heads.py +15 -0
- bytepft-0.1.0/src/bytepft/models/pooling.py +108 -0
- bytepft-0.1.0/src/bytepft/py.typed +0 -0
- bytepft-0.1.0/src/bytepft/serialization.py +102 -0
- bytepft-0.1.0/src/bytepft/tokenization/__init__.py +5 -0
- bytepft-0.1.0/src/bytepft/tokenization/byte_tokenizer.py +206 -0
- bytepft-0.1.0/src/bytepft/training/__init__.py +1 -0
- bytepft-0.1.0/src/bytepft/training/datasets.py +196 -0
- bytepft-0.1.0/src/bytepft/training/distillation.py +135 -0
- bytepft-0.1.0/src/bytepft/training/losses.py +116 -0
- bytepft-0.1.0/src/bytepft/training/trainer.py +446 -0
- bytepft-0.1.0/tests/test_adapters.py +137 -0
- bytepft-0.1.0/tests/test_api_cli.py +162 -0
- bytepft-0.1.0/tests/test_boundaries.py +95 -0
- bytepft-0.1.0/tests/test_config.py +101 -0
- bytepft-0.1.0/tests/test_datasets.py +114 -0
- bytepft-0.1.0/tests/test_distillation.py +72 -0
- bytepft-0.1.0/tests/test_generation.py +188 -0
- bytepft-0.1.0/tests/test_gradients.py +80 -0
- bytepft-0.1.0/tests/test_losses.py +87 -0
- bytepft-0.1.0/tests/test_model.py +153 -0
- bytepft-0.1.0/tests/test_mps.py +171 -0
- bytepft-0.1.0/tests/test_pooling.py +91 -0
- bytepft-0.1.0/tests/test_precision.py +142 -0
- bytepft-0.1.0/tests/test_qwen_integration.py +28 -0
- bytepft-0.1.0/tests/test_release.py +75 -0
- bytepft-0.1.0/tests/test_review_regressions.py +88 -0
- bytepft-0.1.0/tests/test_serialization.py +118 -0
- bytepft-0.1.0/tests/test_tokenizer.py +95 -0
- bytepft-0.1.0/tests/test_training.py +218 -0
- bytepft-0.1.0/tests/test_training_controls.py +104 -0
- bytepft-0.1.0/uv.lock +2812 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
test:
|
|
13
|
+
# macOS wheels keep the CPU test install free of CUDA runtime dependencies.
|
|
14
|
+
runs-on: macos-15
|
|
15
|
+
timeout-minutes: 10
|
|
16
|
+
env:
|
|
17
|
+
UV_PYTHON: "3.13"
|
|
18
|
+
HF_HUB_OFFLINE: "1"
|
|
19
|
+
OMP_NUM_THREADS: "2"
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v7
|
|
22
|
+
- uses: astral-sh/setup-uv@v7
|
|
23
|
+
with:
|
|
24
|
+
python-version: "3.13"
|
|
25
|
+
- run: uv sync --frozen
|
|
26
|
+
- run: uv run --frozen pytest
|
|
27
|
+
- run: uv run --frozen ruff check .
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
inputs:
|
|
8
|
+
tag:
|
|
9
|
+
description: Version to build without publishing (for example, v0.1.0)
|
|
10
|
+
required: true
|
|
11
|
+
default: v0.1.0
|
|
12
|
+
type: string
|
|
13
|
+
|
|
14
|
+
permissions:
|
|
15
|
+
contents: read
|
|
16
|
+
|
|
17
|
+
concurrency:
|
|
18
|
+
group: pypi-${{ github.event.release.tag_name || inputs.tag }}
|
|
19
|
+
cancel-in-progress: false
|
|
20
|
+
|
|
21
|
+
jobs:
|
|
22
|
+
build:
|
|
23
|
+
runs-on: macos-15
|
|
24
|
+
timeout-minutes: 15
|
|
25
|
+
env:
|
|
26
|
+
RELEASE_TAG: ${{ github.event.release.tag_name || inputs.tag }}
|
|
27
|
+
UV_PYTHON: "3.13"
|
|
28
|
+
HF_HUB_OFFLINE: "1"
|
|
29
|
+
OMP_NUM_THREADS: "2"
|
|
30
|
+
steps:
|
|
31
|
+
- uses: actions/checkout@v7
|
|
32
|
+
with:
|
|
33
|
+
persist-credentials: false
|
|
34
|
+
- uses: astral-sh/setup-uv@v7
|
|
35
|
+
with:
|
|
36
|
+
python-version: "3.13"
|
|
37
|
+
- run: uv sync --frozen
|
|
38
|
+
- name: Set package version from release tag
|
|
39
|
+
id: prepare
|
|
40
|
+
run: uv run --frozen python scripts/prepare_release.py
|
|
41
|
+
- run: uv sync --frozen
|
|
42
|
+
- name: Verify installed version
|
|
43
|
+
env:
|
|
44
|
+
EXPECTED_VERSION: ${{ steps.prepare.outputs.version }}
|
|
45
|
+
run: |
|
|
46
|
+
uv run --frozen python - <<'PY'
|
|
47
|
+
import os
|
|
48
|
+
from importlib.metadata import version
|
|
49
|
+
from bytepft import __version__
|
|
50
|
+
assert version("bytepft") == __version__ == os.environ["EXPECTED_VERSION"]
|
|
51
|
+
PY
|
|
52
|
+
- run: uv run --frozen pytest
|
|
53
|
+
- run: uv build --no-sources
|
|
54
|
+
- run: uvx twine check dist/*
|
|
55
|
+
- uses: actions/upload-artifact@v4
|
|
56
|
+
with:
|
|
57
|
+
name: release-distributions
|
|
58
|
+
path: dist/*
|
|
59
|
+
if-no-files-found: error
|
|
60
|
+
|
|
61
|
+
publish:
|
|
62
|
+
if: github.event_name == 'release'
|
|
63
|
+
needs: build
|
|
64
|
+
runs-on: ubuntu-latest
|
|
65
|
+
environment:
|
|
66
|
+
name: pypi
|
|
67
|
+
url: https://pypi.org/project/bytepft/
|
|
68
|
+
permissions:
|
|
69
|
+
id-token: write
|
|
70
|
+
steps:
|
|
71
|
+
- uses: actions/download-artifact@v4
|
|
72
|
+
with:
|
|
73
|
+
name: release-distributions
|
|
74
|
+
path: dist/
|
|
75
|
+
- name: Publish with PyPI Trusted Publishing
|
|
76
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
bytepft-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 — 2026-11-06
|
|
4
|
+
|
|
5
|
+
Initial experimental release of the BytePFT Python library.
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Fixed UTF-8 byte vocabulary with separate controls, raw-byte support, batching,
|
|
10
|
+
tokenizer persistence and incremental text decoding.
|
|
11
|
+
- Causal GRU byte encoder/decoder, fixed/learned/oracle patching, last/mean
|
|
12
|
+
pooling, causal depooling and a trainable byte/control prediction head.
|
|
13
|
+
- Dense Qwen3 adapter using Hugging Face transformer layers, explicit
|
|
14
|
+
configuration checks, frozen/global training control and native KV caches.
|
|
15
|
+
- Offline tiny reference workflow and a real 0.6B base-checkpoint CPU smoke test.
|
|
16
|
+
- Diagnostic and source-aligned Stage 1 objectives; explicit optional Stage 2;
|
|
17
|
+
validation, gradient accumulation/clipping, learning-rate scheduling, early
|
|
18
|
+
stopping and resumable stage checkpoints.
|
|
19
|
+
- Greedy and sampled byte generation with cached and uncached reference paths.
|
|
20
|
+
- Safetensors model persistence, offline loading and training-state checkpoints.
|
|
21
|
+
- Byte-normalized evaluation, measured generation benchmarking, CLI commands,
|
|
22
|
+
examples, CPU tests and release tooling.
|
|
23
|
+
|
|
24
|
+
### Validation scope
|
|
25
|
+
|
|
26
|
+
CPU tests demonstrate tiny-corpus loss reduction, frozen/unfrozen parameter
|
|
27
|
+
behavior, aligned scalar event losses, deterministic resumption and persistence.
|
|
28
|
+
The real pretrained base checkpoint passes one local gradient update and an exact
|
|
29
|
+
save/load logit comparison. That smoke experiment is **not full adaptation** and
|
|
30
|
+
does not establish retained source-model quality.
|
|
31
|
+
|
|
32
|
+
### Known limitations
|
|
33
|
+
|
|
34
|
+
- The reference GRU, causal boundary and separate-head architecture differs from
|
|
35
|
+
the cited Nature method; exact mLSTM/fused-boundary support is not implemented.
|
|
36
|
+
- Full pretrained adaptation, downstream task quality and matched source-model
|
|
37
|
+
performance comparisons have not been executed.
|
|
38
|
+
- MPS fp32 passed bounded training/inference and real pretrained integration
|
|
39
|
+
checks on an M3 Pro. CUDA and MPS mixed precision remain unvalidated. CPU is the default.
|
|
40
|
+
- Inference supports a single generation stream; batched generation and
|
|
41
|
+
distributed training are not implemented.
|
|
42
|
+
- Source embedding/output matrices are retained in checkpoints for Stage 1;
|
|
43
|
+
inference does not use the source tokenizer.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Contributing to BytePFT
|
|
2
|
+
|
|
3
|
+
BytePFT prioritizes a small, understandable and verifiable byte-model workflow.
|
|
4
|
+
Contributions should preserve causal alignment, document boundaries and the
|
|
5
|
+
distinction between reference baselines and research reproductions.
|
|
6
|
+
|
|
7
|
+
## Development setup
|
|
8
|
+
|
|
9
|
+
Use Python 3.11+ and `uv`:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
uv sync
|
|
13
|
+
uv run pytest
|
|
14
|
+
uv run ruff check .
|
|
15
|
+
uv run mypy
|
|
16
|
+
uv build
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The ordinary suite is CPU compatible and must not download pretrained weights.
|
|
20
|
+
Use `uv sync --extra training` when working on the optional Hugging Face dataset
|
|
21
|
+
integration. Tests use tiny randomly initialized Qwen3 configurations to exercise
|
|
22
|
+
the real Hugging Face transformer implementation.
|
|
23
|
+
|
|
24
|
+
Defaults use CPU. Do not introduce automatic GPU execution into tests or
|
|
25
|
+
examples. CUDA/MPS tests and pretrained-weight downloads must be explicit opt-ins
|
|
26
|
+
and describe their hardware and download requirements. A contributor must choose
|
|
27
|
+
to run those experiments; CI should remain usable without them.
|
|
28
|
+
|
|
29
|
+
## Making a change
|
|
30
|
+
|
|
31
|
+
Keep changes focused, match the surrounding style and add tests for observable
|
|
32
|
+
behavior. Test the failure path when adding validation or serialization code.
|
|
33
|
+
For neural components, cover shapes, masks, finite gradients and relevant causal
|
|
34
|
+
invariants. Changing future bytes must not change predictions for earlier bytes.
|
|
35
|
+
Patch construction must account for every valid byte once, in order.
|
|
36
|
+
|
|
37
|
+
For training changes, check that Stage 1 leaves global parameters unchanged and
|
|
38
|
+
that optional Stage 2 unfreezing updates them. Resume tests should compare the
|
|
39
|
+
same training configuration and data against a continuous run, including optimizer,
|
|
40
|
+
scheduler, random sampling state and history. For inference changes, compare
|
|
41
|
+
cached logits or greedy bytes against the uncached reference implementation.
|
|
42
|
+
|
|
43
|
+
Run the tests appropriate to the change, then the ordinary suite and tooling
|
|
44
|
+
before proposing a release. Report the commands actually run and any unavailable
|
|
45
|
+
validation. Avoid claiming that a successful forward pass, random-weight test or
|
|
46
|
+
single gradient step proves model quality.
|
|
47
|
+
|
|
48
|
+
## Research and API changes
|
|
49
|
+
|
|
50
|
+
Read the relevant methods and upstream implementation before adding a derived
|
|
51
|
+
architecture or objective. Record the paper section, source revision, deviations
|
|
52
|
+
and validation in [docs/research.md](docs/research.md). Preserve applicable licenses
|
|
53
|
+
when incorporating third-party code. Original additions use Apache-2.0.
|
|
54
|
+
|
|
55
|
+
Compare teacher and student distributions only when their events and axes are
|
|
56
|
+
mathematically aligned. Source-token logits and byte logits cannot be directly
|
|
57
|
+
KL-diverged. Document byte offsets, BOS/EOS treatment and the prediction shift
|
|
58
|
+
when adding an alignment method.
|
|
59
|
+
|
|
60
|
+
Do not expose an unfinished adapter or command as supported. Add model-family
|
|
61
|
+
compatibility checks rather than relying on coincidentally similar module paths.
|
|
62
|
+
The current exact-paper mLSTM and fused-boundary architecture remain unsupported.
|
|
63
|
+
|
|
64
|
+
## Reporting an issue
|
|
65
|
+
|
|
66
|
+
Include a minimal example, Python/PyTorch/Transformers versions, device and dtype,
|
|
67
|
+
configuration, traceback and whether the model is random, source pretrained or a
|
|
68
|
+
trained BytePFT checkpoint. For resume issues, include the checkpoint stage/step
|
|
69
|
+
and whether the config or documents changed. Never include credentials or private
|
|
70
|
+
training data in a public report.
|
|
71
|
+
|
|
72
|
+
## Release checklist
|
|
73
|
+
|
|
74
|
+
1. Update [CHANGELOG.md](CHANGELOG.md) and choose a release tag such as `v0.1.0`.
|
|
75
|
+
2. Run the ordinary CPU suite, Ruff, mypy and `uv build`.
|
|
76
|
+
3. Inspect wheel/sdist contents and install the wheel into a clean environment.
|
|
77
|
+
4. Review [STATUS.md](STATUS.md), examples and measured results for accurate claims.
|
|
78
|
+
5. Complete the one-time [PyPI setup](docs/releases.md), then publish a GitHub
|
|
79
|
+
release from the tested commit. The release tag sets the package version and
|
|
80
|
+
triggers publication automatically. A manual workflow dispatch builds and
|
|
81
|
+
tests a candidate without publishing. Ordinary pushes and pull requests do
|
|
82
|
+
not publish packages.
|
|
83
|
+
|
|
84
|
+
Do not add fabricated authorship or automatic co-author trailers to commits.
|
bytepft-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
https://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright {yyyy} {name of copyright owner}
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
bytepft-0.1.0/NOTICE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
BytePFT
|
|
2
|
+
Copyright 2026 BytePFT contributors
|
|
3
|
+
|
|
4
|
+
Original BytePFT code is licensed under Apache-2.0.
|
|
5
|
+
Research attribution: Minixhofer et al., Retrofitting language models to operate over bytes,
|
|
6
|
+
Nature (2026), https://www.nature.com/articles/s41586-026-11111-4
|
|
7
|
+
BytePFT is an independent reference implementation of the cited research.
|
|
8
|
+
Qwen model weights and Hugging Face dependencies retain their respective licenses.
|
bytepft-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: bytepft
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Retrofitting language models, one byte at a time.
|
|
5
|
+
Project-URL: Repository, https://github.com/skundu42/bytepft
|
|
6
|
+
Project-URL: Issues, https://github.com/skundu42/bytepft/issues
|
|
7
|
+
Project-URL: Documentation, https://github.com/skundu42/bytepft/tree/main/docs
|
|
8
|
+
Author: BytePFT contributors
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
License-File: NOTICE
|
|
12
|
+
Keywords: distillation,language-model,pytorch,utf-8
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
16
|
+
Requires-Python: >=3.11
|
|
17
|
+
Requires-Dist: pyyaml>=6
|
|
18
|
+
Requires-Dist: safetensors>=0.5
|
|
19
|
+
Requires-Dist: torch<3,>=2.6
|
|
20
|
+
Requires-Dist: transformers<5,>=4.57.6
|
|
21
|
+
Provides-Extra: benchmark
|
|
22
|
+
Requires-Dist: psutil>=6; extra == 'benchmark'
|
|
23
|
+
Provides-Extra: training
|
|
24
|
+
Requires-Dist: accelerate>=1; extra == 'training'
|
|
25
|
+
Requires-Dist: datasets>=3; extra == 'training'
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# BytePFT
|
|
29
|
+
|
|
30
|
+
[](https://github.com/skundu42/bytepft/actions/workflows/ci.yml)
|
|
31
|
+
[](https://www.python.org/downloads/)
|
|
32
|
+
[](https://github.com/skundu42/bytepft/blob/main/LICENSE)
|
|
33
|
+
|
|
34
|
+
**Retrofitting language models, one byte at a time.**
|
|
35
|
+
|
|
36
|
+
BytePFT is a Python library for adapting pretrained Qwen3 language models to
|
|
37
|
+
UTF-8 bytes. It trains a byte-level encoder and decoder around the existing
|
|
38
|
+
transformer, with patch-based processing and cached byte generation.
|
|
39
|
+
|
|
40
|
+
BytePFT is experimental. The reference implementation is tested on CPU and Apple
|
|
41
|
+
MPS in fp32; full pretrained adaptation and retained language quality have not yet
|
|
42
|
+
been evaluated. See [project status](https://github.com/skundu42/bytepft/blob/main/STATUS.md) for results and limitations.
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
Requires Python 3.11+.
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
pip install bytepft
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Or install from source:
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
pip install git+https://github.com/skundu42/bytepft.git
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Quickstart
|
|
59
|
+
|
|
60
|
+
Train a tiny model locally, without downloading pretrained weights:
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from bytepft import BytePFT, BytePFTConfig
|
|
64
|
+
|
|
65
|
+
model = BytePFT.from_tiny(
|
|
66
|
+
config=BytePFTConfig(hidden_size=32, encoder_layers=1, decoder_layers=1),
|
|
67
|
+
device="cpu",
|
|
68
|
+
)
|
|
69
|
+
model.retrofit(
|
|
70
|
+
["hello byte world\n"] * 4,
|
|
71
|
+
stage1_steps=100,
|
|
72
|
+
learning_rate=0.01,
|
|
73
|
+
validation_fraction=0,
|
|
74
|
+
output_dir="outputs/tiny",
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
model = BytePFT.load("outputs/tiny")
|
|
78
|
+
print(model.generate("hello", max_new_bytes=32, temperature=0))
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
This example uses a randomly initialized tiny transformer. To adapt pretrained
|
|
82
|
+
weights, use `BytePFT.from_pretrained("Qwen/Qwen3-0.6B-Base")` and follow the
|
|
83
|
+
[training guide](https://github.com/skundu42/bytepft/blob/main/docs/training.md). Adaptation must complete before generation.
|
|
84
|
+
|
|
85
|
+
## Features
|
|
86
|
+
|
|
87
|
+
- UTF-8 byte encoding with separate padding, beginning and end symbols.
|
|
88
|
+
- Fixed, oracle and learned patch boundaries.
|
|
89
|
+
- Frozen-backbone Stage 1 and optional end-to-end Stage 2 training.
|
|
90
|
+
- Resumable checkpoints, validation and bits-per-byte evaluation.
|
|
91
|
+
- Greedy and sampled generation with local state and global KV caching.
|
|
92
|
+
|
|
93
|
+
Defaults use CPU. Select `device="mps"` explicitly for Apple GPU execution;
|
|
94
|
+
[MPS validation](https://github.com/skundu42/bytepft/blob/main/docs/mps.md) currently covers fp32. CUDA remains unvalidated.
|
|
95
|
+
|
|
96
|
+
## Command line
|
|
97
|
+
|
|
98
|
+
```sh
|
|
99
|
+
bytepft train-tiny --output outputs/tiny --device cpu
|
|
100
|
+
bytepft generate --model outputs/tiny --prompt "hello" --max-new-bytes 32
|
|
101
|
+
bytepft inspect Qwen/Qwen3-0.6B-Base
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Run `bytepft --help` for all commands.
|
|
105
|
+
|
|
106
|
+
## Documentation
|
|
107
|
+
|
|
108
|
+
- [Training and checkpoints](https://github.com/skundu42/bytepft/blob/main/docs/training.md)
|
|
109
|
+
- [Architecture](https://github.com/skundu42/bytepft/blob/main/docs/architecture.md)
|
|
110
|
+
- [Research notes](https://github.com/skundu42/bytepft/blob/main/docs/research.md)
|
|
111
|
+
- [Examples](https://github.com/skundu42/bytepft/tree/main/examples)
|
|
112
|
+
- [Contributing](https://github.com/skundu42/bytepft/blob/main/CONTRIBUTING.md) · [Releases](https://github.com/skundu42/bytepft/blob/main/docs/releases.md) · [Changelog](https://github.com/skundu42/bytepft/blob/main/CHANGELOG.md)
|
|
113
|
+
|
|
114
|
+
Inspired by [*Retrofitting language models to operate over bytes*, Nature (2026)](https://www.nature.com/articles/s41586-026-11111-4).
|
|
115
|
+
BytePFT uses a simplified reference architecture; the research notes document its deviations.
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
[Apache-2.0](https://github.com/skundu42/bytepft/blob/main/LICENSE). See [NOTICE](https://github.com/skundu42/bytepft/blob/main/NOTICE) for attribution.
|
bytepft-0.1.0/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# BytePFT
|
|
2
|
+
|
|
3
|
+
[](https://github.com/skundu42/bytepft/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.python.org/downloads/)
|
|
5
|
+
[](https://github.com/skundu42/bytepft/blob/main/LICENSE)
|
|
6
|
+
|
|
7
|
+
**Retrofitting language models, one byte at a time.**
|
|
8
|
+
|
|
9
|
+
BytePFT is a Python library for adapting pretrained Qwen3 language models to
|
|
10
|
+
UTF-8 bytes. It trains a byte-level encoder and decoder around the existing
|
|
11
|
+
transformer, with patch-based processing and cached byte generation.
|
|
12
|
+
|
|
13
|
+
BytePFT is experimental. The reference implementation is tested on CPU and Apple
|
|
14
|
+
MPS in fp32; full pretrained adaptation and retained language quality have not yet
|
|
15
|
+
been evaluated. See [project status](https://github.com/skundu42/bytepft/blob/main/STATUS.md) for results and limitations.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
Requires Python 3.11+.
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
pip install bytepft
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Or install from source:
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
pip install git+https://github.com/skundu42/bytepft.git
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Quickstart
|
|
32
|
+
|
|
33
|
+
Train a tiny model locally, without downloading pretrained weights:
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from bytepft import BytePFT, BytePFTConfig
|
|
37
|
+
|
|
38
|
+
model = BytePFT.from_tiny(
|
|
39
|
+
config=BytePFTConfig(hidden_size=32, encoder_layers=1, decoder_layers=1),
|
|
40
|
+
device="cpu",
|
|
41
|
+
)
|
|
42
|
+
model.retrofit(
|
|
43
|
+
["hello byte world\n"] * 4,
|
|
44
|
+
stage1_steps=100,
|
|
45
|
+
learning_rate=0.01,
|
|
46
|
+
validation_fraction=0,
|
|
47
|
+
output_dir="outputs/tiny",
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
model = BytePFT.load("outputs/tiny")
|
|
51
|
+
print(model.generate("hello", max_new_bytes=32, temperature=0))
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
This example uses a randomly initialized tiny transformer. To adapt pretrained
|
|
55
|
+
weights, use `BytePFT.from_pretrained("Qwen/Qwen3-0.6B-Base")` and follow the
|
|
56
|
+
[training guide](https://github.com/skundu42/bytepft/blob/main/docs/training.md). Adaptation must complete before generation.
|
|
57
|
+
|
|
58
|
+
## Features
|
|
59
|
+
|
|
60
|
+
- UTF-8 byte encoding with separate padding, beginning and end symbols.
|
|
61
|
+
- Fixed, oracle and learned patch boundaries.
|
|
62
|
+
- Frozen-backbone Stage 1 and optional end-to-end Stage 2 training.
|
|
63
|
+
- Resumable checkpoints, validation and bits-per-byte evaluation.
|
|
64
|
+
- Greedy and sampled generation with local state and global KV caching.
|
|
65
|
+
|
|
66
|
+
Defaults use CPU. Select `device="mps"` explicitly for Apple GPU execution;
|
|
67
|
+
[MPS validation](https://github.com/skundu42/bytepft/blob/main/docs/mps.md) currently covers fp32. CUDA remains unvalidated.
|
|
68
|
+
|
|
69
|
+
## Command line
|
|
70
|
+
|
|
71
|
+
```sh
|
|
72
|
+
bytepft train-tiny --output outputs/tiny --device cpu
|
|
73
|
+
bytepft generate --model outputs/tiny --prompt "hello" --max-new-bytes 32
|
|
74
|
+
bytepft inspect Qwen/Qwen3-0.6B-Base
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Run `bytepft --help` for all commands.
|
|
78
|
+
|
|
79
|
+
## Documentation
|
|
80
|
+
|
|
81
|
+
- [Training and checkpoints](https://github.com/skundu42/bytepft/blob/main/docs/training.md)
|
|
82
|
+
- [Architecture](https://github.com/skundu42/bytepft/blob/main/docs/architecture.md)
|
|
83
|
+
- [Research notes](https://github.com/skundu42/bytepft/blob/main/docs/research.md)
|
|
84
|
+
- [Examples](https://github.com/skundu42/bytepft/tree/main/examples)
|
|
85
|
+
- [Contributing](https://github.com/skundu42/bytepft/blob/main/CONTRIBUTING.md) · [Releases](https://github.com/skundu42/bytepft/blob/main/docs/releases.md) · [Changelog](https://github.com/skundu42/bytepft/blob/main/CHANGELOG.md)
|
|
86
|
+
|
|
87
|
+
Inspired by [*Retrofitting language models to operate over bytes*, Nature (2026)](https://www.nature.com/articles/s41586-026-11111-4).
|
|
88
|
+
BytePFT uses a simplified reference architecture; the research notes document its deviations.
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
[Apache-2.0](https://github.com/skundu42/bytepft/blob/main/LICENSE). See [NOTICE](https://github.com/skundu42/bytepft/blob/main/NOTICE) for attribution.
|