entail-ai 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.
Files changed (45) hide show
  1. entail_ai-0.1.0/LICENSE +202 -0
  2. entail_ai-0.1.0/PKG-INFO +161 -0
  3. entail_ai-0.1.0/README.md +139 -0
  4. entail_ai-0.1.0/entail/__init__.py +31 -0
  5. entail_ai-0.1.0/entail/__main__.py +5 -0
  6. entail_ai-0.1.0/entail/adapters/__init__.py +0 -0
  7. entail_ai-0.1.0/entail/adapters/_shared.py +88 -0
  8. entail_ai-0.1.0/entail/adapters/autoinstall/__init__.py +2 -0
  9. entail_ai-0.1.0/entail/adapters/autoinstall/sitecustomize.py +113 -0
  10. entail_ai-0.1.0/entail/adapters/cache_contract.py +211 -0
  11. entail_ai-0.1.0/entail/adapters/rope_alias.py +255 -0
  12. entail_ai-0.1.0/entail/adapters/sglang_adapter.py +106 -0
  13. entail_ai-0.1.0/entail/adapters/sglang_cache_contract.py +97 -0
  14. entail_ai-0.1.0/entail/adapters/sglang_cache_probe.py +66 -0
  15. entail_ai-0.1.0/entail/adapters/transformers_adapter.py +72 -0
  16. entail_ai-0.1.0/entail/adapters/vllm_cache_contract.py +109 -0
  17. entail_ai-0.1.0/entail/adapters/vllm_layout.py +169 -0
  18. entail_ai-0.1.0/entail/adapters/vllm_ledger.py +122 -0
  19. entail_ai-0.1.0/entail/adapters/vllm_seed.py +108 -0
  20. entail_ai-0.1.0/entail/adapters/vllm_source.py +169 -0
  21. entail_ai-0.1.0/entail/cli.py +110 -0
  22. entail_ai-0.1.0/entail/core.py +161 -0
  23. entail_ai-0.1.0/entail/facts.py +72 -0
  24. entail_ai-0.1.0/entail/hook.py +46 -0
  25. entail_ai-0.1.0/entail/kv_contract.py +73 -0
  26. entail_ai-0.1.0/entail/preflight.py +266 -0
  27. entail_ai-0.1.0/entail/propagate.py +139 -0
  28. entail_ai-0.1.0/entail_ai.egg-info/PKG-INFO +161 -0
  29. entail_ai-0.1.0/entail_ai.egg-info/SOURCES.txt +43 -0
  30. entail_ai-0.1.0/entail_ai.egg-info/dependency_links.txt +1 -0
  31. entail_ai-0.1.0/entail_ai.egg-info/entry_points.txt +3 -0
  32. entail_ai-0.1.0/entail_ai.egg-info/top_level.txt +1 -0
  33. entail_ai-0.1.0/pyproject.toml +42 -0
  34. entail_ai-0.1.0/setup.cfg +4 -0
  35. entail_ai-0.1.0/setup.py +25 -0
  36. entail_ai-0.1.0/tests/test_adapter.py +131 -0
  37. entail_ai-0.1.0/tests/test_autoinstall.py +53 -0
  38. entail_ai-0.1.0/tests/test_cache_contract.py +143 -0
  39. entail_ai-0.1.0/tests/test_core.py +82 -0
  40. entail_ai-0.1.0/tests/test_kv_contract.py +61 -0
  41. entail_ai-0.1.0/tests/test_preflight.py +76 -0
  42. entail_ai-0.1.0/tests/test_propagate.py +113 -0
  43. entail_ai-0.1.0/tests/test_rope_alias.py +170 -0
  44. entail_ai-0.1.0/tests/test_vllm_layout.py +81 -0
  45. entail_ai-0.1.0/tests/test_vllm_source.py +89 -0
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://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
+ http://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.
202
+
@@ -0,0 +1,161 @@
1
+ Metadata-Version: 2.4
2
+ Name: entail-ai
3
+ Version: 0.1.0
4
+ Summary: Keep what a value means intact across LLM inference-stack boundaries: declare it, check it against the data, and resolve a mismatch before it becomes a silent wrong answer
5
+ Author: wwoosshh
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/wwoosshh/entail
8
+ Project-URL: Issues, https://github.com/wwoosshh/entail/issues
9
+ Keywords: llm,inference,vllm,sglang,transformers,correctness,rope,silent-errors
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
+ Requires-Python: >=3.10
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Dynamic: license-file
22
+
23
+ # entail
24
+
25
+ **Keep what a value means intact across LLM inference-stack boundaries.**
26
+
27
+ An inference stack is a chain of parts — checkpoint and config, loader, engine, kernels, quantization, cache.
28
+ Each part can be correct on its own terms while the *meaning* of a value is lost between two of them: a declared
29
+ property the chosen kernel ignores, a setting that arrives under a name nobody reads any more, a cache that
30
+ silently loses a token. The output is then wrong, fluently and without a warning.
31
+
32
+ entail declares what a value means where it crosses a boundary, checks the declaration against the real thing,
33
+ and when they disagree **it resolves the mismatch first** — routes the value to a consumer that honours it, or
34
+ converts it to the form the consumer reads — and prints one line saying what it changed. It stops only when no
35
+ fix exists.
36
+
37
+ The name is the logical sense of *entail*: what a checkpoint declares must entail what the engine executes.
38
+ (ent·**AI**·**L** — an AI library.)
39
+
40
+ > Status: research prototype (alpha). Measured on one RTX 4070 Ti with the versions under "Tested with".
41
+
42
+ ## Why: a case measured end to end
43
+
44
+ Restating a model's **own** `rope_scaling` at launch — the route model cards give for enabling YaRN — drops
45
+ `rope_theta` under transformers 5, and the engine silently falls back to a RoPE base of 10,000.
46
+
47
+ Llama-3.2-3B-Instruct, greedy, GSM8K (first 500 on vLLM, first 200 on SGLang):
48
+
49
+ | | untouched | same `rope_scaling` passed again at launch | with entail |
50
+ |---|---|---|---|
51
+ | vLLM 0.30.0 `--hf-overrides` | 379 / 500 | **279 / 500**, no warning | 378 / 500 |
52
+ | SGLang 0.5.20 `--json-model-override-args` | 161 / 200 | **106 / 200** | 161 / 200 (outputs identical) |
53
+
54
+ The degraded runs are identical to an explicit `rope_theta = 10000`. Outputs stay fluent; the answers are wrong.
55
+ Qwen3 dense models happen to be safe because those model files fill in 1,000,000; Llama, Qwen3-MoE, Gemma and
56
+ others do not.
57
+
58
+ ## Install
59
+
60
+ ```bash
61
+ pip install "git+https://github.com/wwoosshh/entail"
62
+ ```
63
+
64
+ Install it into the same environment as your engine (vLLM, SGLang or transformers). entail has no dependencies
65
+ of its own. Once it is on PyPI: `pip install entail-ai` (the import name stays `entail`). `uv pip install` works
66
+ the same way.
67
+
68
+ Check what it sees:
69
+
70
+ ```bash
71
+ entail doctor
72
+ ```
73
+
74
+ ## Use
75
+
76
+ Turn it on with one environment variable; nothing else changes.
77
+
78
+ ```bash
79
+ ENTAIL=load vllm serve meta-llama/Llama-3.2-3B-Instruct --hf-overrides '{"rope_scaling": {...}}'
80
+ ENTAIL=load python -m sglang.launch_server --model-path ... --json-model-override-args '{...}'
81
+ ENTAIL=load python your_transformers_script.py
82
+ ```
83
+
84
+ When it changes something, it says so:
85
+
86
+ ```
87
+ [entail] resolved LlamaConfig.rope_scaling was given after the config was built; it replaces rope_parameters and
88
+ would have dropped rope_theta=500000.0, ...; kept it, as config.json would
89
+ ```
90
+
91
+ From inside a script:
92
+
93
+ ```python
94
+ import entail
95
+ entail.enable() # mode="load", policy="resolve"; child processes inherit it
96
+ ```
97
+
98
+ ### How it reaches engine worker processes
99
+
100
+ vLLM and SGLang run the model in processes they start themselves. `pip install` puts one file,
101
+ `entail-autoinstall.pth`, into site-packages; Python reads it at every start-up. Its single line checks the
102
+ environment and does nothing unless `ENTAIL` is set. `entail hook status|install|uninstall` shows or manages it
103
+ (an editable install does not place it — run `entail hook install`).
104
+
105
+ ## What it does
106
+
107
+ **Resolves**
108
+
109
+ | mismatch | resolution | measured |
110
+ |---|---|---|
111
+ | a RoPE value given under its transformers-4 name after the config is built (`rope_theta`, `rope_scaling` — keyword to `from_pretrained`, attribute, vLLM `--hf-overrides`, SGLang `--json-model-override-args`) | written where `config.json` would have put it, including per-layer-type RoPE (asks the config class) | equal to the `config.json` route on 4 model families × 2 routes × 3 values; GSM8K restored (table above) |
112
+ | an attention backend that drops a declared model property (e.g. Gemma 2 logit soft-capping on transformers `sdpa`, SGLang `flashinfer`) | switched to a backend measured to honour it (`eager`, `triton`) | tokens equal the reference run; cost 1.18× (transformers), 1.13× (SGLang, the backend's own price) |
113
+
114
+ **Checks** (and stops, when nothing can resolve it)
115
+
116
+ - attention properties against each engine's backends, before any weight is read
117
+ - config keys that would be swallowed, and tied-embedding declarations against the checkpoint
118
+ - vLLM weights after repacking: layout, stride and a value sample against the declared transform
119
+ - weights in memory against the checkpoint file (`ENTAIL_SOURCE=1`)
120
+ - the KV cache contract (a request holds what it needs, nothing shrank) on transformers, vLLM's paged cache
121
+ and SGLang
122
+
123
+ `entail preflight --model /path/to/model --engine sglang --list` runs the start-up checks without starting a server.
124
+
125
+ ## Configuration
126
+
127
+ | variable | values | meaning |
128
+ |---|---|---|
129
+ | `ENTAIL` | `off` (default), `load`, `debug` | `load`: start-up checks and resolvers; `debug`: also every declared boundary, and uncovered cases become errors |
130
+ | `ENTAIL_POLICY` | `resolve` (default), `refuse` | `refuse` stops at the first mismatch instead of resolving |
131
+ | `ENTAIL_ONLY` | e.g. `rope_alias,sglang_adapter` | install only these adapters |
132
+ | `ENTAIL_VERBOSE` | `1` | print each adapter as it is installed |
133
+ | `ENTAIL_SOURCE` | `1` | also compare loaded weights with the checkpoint file (vLLM, a little I/O at start-up) |
134
+ | `ENTAIL_SEED` | test names | fault injection used to test the checks themselves; never set it in production |
135
+
136
+ ## Tested with
137
+
138
+ transformers 5.12.1 and 5.17.0, vLLM 0.30.0, SGLang 0.5.20, torch 2.13–2.14, Python 3.12, one RTX 4070 Ti
139
+ (12 GB). Other versions may work; `entail doctor` prints what is installed. On transformers 4.x the RoPE resolver
140
+ has nothing to do and stays out of the way.
141
+
142
+ The capability table (which backend honours what) records its evidence per entry, and only entries marked
143
+ *measured* are used as resolution targets. The measurement scripts and raw results are kept in the author's
144
+ research workspace and are not in this repository yet.
145
+
146
+ ## Development
147
+
148
+ ```bash
149
+ git clone https://github.com/wwoosshh/entail && cd entail
150
+ pip install -e .
151
+ entail hook install # editable installs do not place the start-up hook
152
+ PYTHON=python bash tests/run_all.sh
153
+ ```
154
+
155
+ Tests that need a local model look in `ENTAIL_TEST_MODELS` (default `~/models`) and skip when it is absent.
156
+
157
+ 한국어 안내: [README.ko.md](README.ko.md)
158
+
159
+ ## License
160
+
161
+ See [LICENSE](LICENSE).
@@ -0,0 +1,139 @@
1
+ # entail
2
+
3
+ **Keep what a value means intact across LLM inference-stack boundaries.**
4
+
5
+ An inference stack is a chain of parts — checkpoint and config, loader, engine, kernels, quantization, cache.
6
+ Each part can be correct on its own terms while the *meaning* of a value is lost between two of them: a declared
7
+ property the chosen kernel ignores, a setting that arrives under a name nobody reads any more, a cache that
8
+ silently loses a token. The output is then wrong, fluently and without a warning.
9
+
10
+ entail declares what a value means where it crosses a boundary, checks the declaration against the real thing,
11
+ and when they disagree **it resolves the mismatch first** — routes the value to a consumer that honours it, or
12
+ converts it to the form the consumer reads — and prints one line saying what it changed. It stops only when no
13
+ fix exists.
14
+
15
+ The name is the logical sense of *entail*: what a checkpoint declares must entail what the engine executes.
16
+ (ent·**AI**·**L** — an AI library.)
17
+
18
+ > Status: research prototype (alpha). Measured on one RTX 4070 Ti with the versions under "Tested with".
19
+
20
+ ## Why: a case measured end to end
21
+
22
+ Restating a model's **own** `rope_scaling` at launch — the route model cards give for enabling YaRN — drops
23
+ `rope_theta` under transformers 5, and the engine silently falls back to a RoPE base of 10,000.
24
+
25
+ Llama-3.2-3B-Instruct, greedy, GSM8K (first 500 on vLLM, first 200 on SGLang):
26
+
27
+ | | untouched | same `rope_scaling` passed again at launch | with entail |
28
+ |---|---|---|---|
29
+ | vLLM 0.30.0 `--hf-overrides` | 379 / 500 | **279 / 500**, no warning | 378 / 500 |
30
+ | SGLang 0.5.20 `--json-model-override-args` | 161 / 200 | **106 / 200** | 161 / 200 (outputs identical) |
31
+
32
+ The degraded runs are identical to an explicit `rope_theta = 10000`. Outputs stay fluent; the answers are wrong.
33
+ Qwen3 dense models happen to be safe because those model files fill in 1,000,000; Llama, Qwen3-MoE, Gemma and
34
+ others do not.
35
+
36
+ ## Install
37
+
38
+ ```bash
39
+ pip install "git+https://github.com/wwoosshh/entail"
40
+ ```
41
+
42
+ Install it into the same environment as your engine (vLLM, SGLang or transformers). entail has no dependencies
43
+ of its own. Once it is on PyPI: `pip install entail-ai` (the import name stays `entail`). `uv pip install` works
44
+ the same way.
45
+
46
+ Check what it sees:
47
+
48
+ ```bash
49
+ entail doctor
50
+ ```
51
+
52
+ ## Use
53
+
54
+ Turn it on with one environment variable; nothing else changes.
55
+
56
+ ```bash
57
+ ENTAIL=load vllm serve meta-llama/Llama-3.2-3B-Instruct --hf-overrides '{"rope_scaling": {...}}'
58
+ ENTAIL=load python -m sglang.launch_server --model-path ... --json-model-override-args '{...}'
59
+ ENTAIL=load python your_transformers_script.py
60
+ ```
61
+
62
+ When it changes something, it says so:
63
+
64
+ ```
65
+ [entail] resolved LlamaConfig.rope_scaling was given after the config was built; it replaces rope_parameters and
66
+ would have dropped rope_theta=500000.0, ...; kept it, as config.json would
67
+ ```
68
+
69
+ From inside a script:
70
+
71
+ ```python
72
+ import entail
73
+ entail.enable() # mode="load", policy="resolve"; child processes inherit it
74
+ ```
75
+
76
+ ### How it reaches engine worker processes
77
+
78
+ vLLM and SGLang run the model in processes they start themselves. `pip install` puts one file,
79
+ `entail-autoinstall.pth`, into site-packages; Python reads it at every start-up. Its single line checks the
80
+ environment and does nothing unless `ENTAIL` is set. `entail hook status|install|uninstall` shows or manages it
81
+ (an editable install does not place it — run `entail hook install`).
82
+
83
+ ## What it does
84
+
85
+ **Resolves**
86
+
87
+ | mismatch | resolution | measured |
88
+ |---|---|---|
89
+ | a RoPE value given under its transformers-4 name after the config is built (`rope_theta`, `rope_scaling` — keyword to `from_pretrained`, attribute, vLLM `--hf-overrides`, SGLang `--json-model-override-args`) | written where `config.json` would have put it, including per-layer-type RoPE (asks the config class) | equal to the `config.json` route on 4 model families × 2 routes × 3 values; GSM8K restored (table above) |
90
+ | an attention backend that drops a declared model property (e.g. Gemma 2 logit soft-capping on transformers `sdpa`, SGLang `flashinfer`) | switched to a backend measured to honour it (`eager`, `triton`) | tokens equal the reference run; cost 1.18× (transformers), 1.13× (SGLang, the backend's own price) |
91
+
92
+ **Checks** (and stops, when nothing can resolve it)
93
+
94
+ - attention properties against each engine's backends, before any weight is read
95
+ - config keys that would be swallowed, and tied-embedding declarations against the checkpoint
96
+ - vLLM weights after repacking: layout, stride and a value sample against the declared transform
97
+ - weights in memory against the checkpoint file (`ENTAIL_SOURCE=1`)
98
+ - the KV cache contract (a request holds what it needs, nothing shrank) on transformers, vLLM's paged cache
99
+ and SGLang
100
+
101
+ `entail preflight --model /path/to/model --engine sglang --list` runs the start-up checks without starting a server.
102
+
103
+ ## Configuration
104
+
105
+ | variable | values | meaning |
106
+ |---|---|---|
107
+ | `ENTAIL` | `off` (default), `load`, `debug` | `load`: start-up checks and resolvers; `debug`: also every declared boundary, and uncovered cases become errors |
108
+ | `ENTAIL_POLICY` | `resolve` (default), `refuse` | `refuse` stops at the first mismatch instead of resolving |
109
+ | `ENTAIL_ONLY` | e.g. `rope_alias,sglang_adapter` | install only these adapters |
110
+ | `ENTAIL_VERBOSE` | `1` | print each adapter as it is installed |
111
+ | `ENTAIL_SOURCE` | `1` | also compare loaded weights with the checkpoint file (vLLM, a little I/O at start-up) |
112
+ | `ENTAIL_SEED` | test names | fault injection used to test the checks themselves; never set it in production |
113
+
114
+ ## Tested with
115
+
116
+ transformers 5.12.1 and 5.17.0, vLLM 0.30.0, SGLang 0.5.20, torch 2.13–2.14, Python 3.12, one RTX 4070 Ti
117
+ (12 GB). Other versions may work; `entail doctor` prints what is installed. On transformers 4.x the RoPE resolver
118
+ has nothing to do and stays out of the way.
119
+
120
+ The capability table (which backend honours what) records its evidence per entry, and only entries marked
121
+ *measured* are used as resolution targets. The measurement scripts and raw results are kept in the author's
122
+ research workspace and are not in this repository yet.
123
+
124
+ ## Development
125
+
126
+ ```bash
127
+ git clone https://github.com/wwoosshh/entail && cd entail
128
+ pip install -e .
129
+ entail hook install # editable installs do not place the start-up hook
130
+ PYTHON=python bash tests/run_all.sh
131
+ ```
132
+
133
+ Tests that need a local model look in `ENTAIL_TEST_MODELS` (default `~/models`) and skip when it is absent.
134
+
135
+ 한국어 안내: [README.ko.md](README.ko.md)
136
+
137
+ ## License
138
+
139
+ See [LICENSE](LICENSE).
@@ -0,0 +1,31 @@
1
+ """entail: keep what a value means intact across LLM inference-stack boundaries.
2
+
3
+ Most users never import this: `pip install` puts a start-up hook in the environment, and `ENTAIL=load` turns it
4
+ on for a process and every process it spawns (see README). `enable()` does the same from inside a script.
5
+ """
6
+ import os
7
+
8
+ from .core import (RoleError, boundary, check_config_keys, check_props, check_tied, facts_of, mode, policy, require,
9
+ set_mode, set_policy, tag)
10
+ from .facts import (LAYOUT_KINDS, KernelCaps, Layout, ModelProps, Positions, Quantized, Reduction, Valid)
11
+
12
+ __version__ = "0.1.0"
13
+
14
+
15
+ def enable(mode="load", policy="resolve"):
16
+ """Turn entail on in this process, and in any process it starts from now on.
17
+
18
+ Sets ENTAIL / ENTAIL_POLICY (children inherit the environment), sets the mode and policy here, and installs the
19
+ adapters: at once for engines already imported, and as each one finishes importing otherwise."""
20
+ os.environ["ENTAIL"] = mode
21
+ os.environ["ENTAIL_POLICY"] = policy
22
+ set_mode(mode)
23
+ set_policy(policy)
24
+ from .adapters.autoinstall import sitecustomize as _hook
25
+
26
+ _hook.activate()
27
+
28
+
29
+ __all__ = ["RoleError", "boundary", "check_config_keys", "check_props", "check_tied", "enable", "facts_of", "mode",
30
+ "policy", "require", "set_mode", "set_policy", "tag", "LAYOUT_KINDS", "KernelCaps", "Layout", "ModelProps",
31
+ "Positions", "Quantized", "Reduction", "Valid", "__version__"]
@@ -0,0 +1,5 @@
1
+ import sys
2
+
3
+ from .cli import main
4
+
5
+ sys.exit(main())
File without changes
@@ -0,0 +1,88 @@
1
+ """What every engine adapter needs: read the declared properties off a config, and judge one backend.
2
+
3
+ Two outcomes, and they are not the same thing:
4
+ violation - the table says this backend drops a property the model declares. Always an error.
5
+ uncovered - the table does not know this backend, so nothing was checked. An error in `debug` mode, a printed
6
+ warning in `load` mode, because a research table will always lag behind new backends.
7
+ """
8
+ from ..facts import ModelProps
9
+ from ..preflight import CAPS, check
10
+
11
+
12
+ def props_of(config):
13
+ """ModelProps from a HF config object (PretrainedConfig or anything with the same attributes)."""
14
+ text = getattr(config, "text_config", None) or config
15
+ return ModelProps(softcap=getattr(text, "attn_logit_softcapping", None),
16
+ sliding_window=getattr(text, "sliding_window", None))
17
+
18
+
19
+ def verdict(config, backend, engine):
20
+ """Return (kind, message) for this config and backend, or None when there is nothing to say."""
21
+ props = props_of(config)
22
+ declared = [f"{k}={v}" for k, v in vars(props).items() if v is not None]
23
+ if not declared:
24
+ return None
25
+ table = CAPS[engine]
26
+ entry = table.get(backend) if isinstance(backend, str) else None
27
+ if entry is None:
28
+ return ("uncovered",
29
+ f"{engine} attention backend '{backend}' is not in the capability table, so "
30
+ f"{', '.join(declared)} was not checked\n known: {', '.join(sorted(table))}")
31
+ missing = check(props, entry[0])
32
+ if not missing:
33
+ return None
34
+ return ("violation",
35
+ f"{engine} attention backend '{backend}' does not honour: {', '.join(missing)}"
36
+ f"\n evidence: {entry[1]}")
37
+
38
+
39
+ RESOLUTIONS = [] # every resolution made in this process, so a caller or a test can see what was changed
40
+
41
+
42
+ def choose(config, engine, preference):
43
+ """The first backend in `preference` that honours everything this model declares.
44
+
45
+ Only capabilities marked as measured count: a resolution routes the value to a consumer we have *seen*
46
+ honour the declaration, never to one we only believe does (the table has been wrong from code reading
47
+ before - vLLM FLEX_ATTENTION, sweep/RESULTS.md).
48
+ """
49
+ props = props_of(config)
50
+ table = CAPS[engine]
51
+ for name in preference:
52
+ entry = table.get(name)
53
+ if entry is None or check(props, entry[0]) or "measured:" not in entry[1]:
54
+ continue
55
+ return name
56
+ return None
57
+
58
+
59
+ def note_resolution(engine, where, frm, to, config):
60
+ """Say what was changed and why. A resolution that nobody hears about is the silent behaviour this
61
+ library exists to remove, so this always prints, whatever the verbosity."""
62
+ missing = check(props_of(config), CAPS[engine][frm][0]) if frm in CAPS[engine] else ["(not in the table)"]
63
+ evidence = CAPS[engine][to][1]
64
+ RESOLUTIONS.append({"engine": engine, "where": where, "from": frm, "to": to, "missing": missing})
65
+ print(f"[entail] resolved {where}: {engine} backend '{frm}' does not honour {', '.join(missing)}; "
66
+ f"using '{to}' instead (evidence: {evidence})", flush=True)
67
+
68
+
69
+ def note(record, message):
70
+ """A resolution that is not a backend switch (a value converted to the form its consumer reads). Recorded
71
+ and always printed, for the same reason as note_resolution."""
72
+ RESOLUTIONS.append(record)
73
+ print(f"[entail] resolved {message}", flush=True)
74
+
75
+
76
+ def report(said, where=""):
77
+ """Raise or warn according to the mode. Returns True when it warned."""
78
+ from .. import core
79
+
80
+ if said is None:
81
+ return False
82
+ kind, msg = said
83
+ if where:
84
+ msg = f"{where}: {msg}"
85
+ if kind == "violation" or core.mode() == "debug":
86
+ raise core.RoleError(msg)
87
+ print(f"[entail] {msg}", flush=True)
88
+ return True
@@ -0,0 +1,2 @@
1
+ """The start-up hook lives in sitecustomize.py (see its docstring). This file makes the directory a package so the
2
+ wheel ships the hook; putting the directory itself on PYTHONPATH still works for a source checkout."""