shardac 1.0.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.
- shardac-1.0.0/.gitignore +7 -0
- shardac-1.0.0/CONTRACT.md +76 -0
- shardac-1.0.0/LICENSE +202 -0
- shardac-1.0.0/PKG-INFO +132 -0
- shardac-1.0.0/README.md +95 -0
- shardac-1.0.0/pyproject.toml +60 -0
- shardac-1.0.0/src/shard/__init__.py +48 -0
- shardac-1.0.0/src/shard/_collect.py +72 -0
- shardac-1.0.0/src/shard/_engine.py +90 -0
- shardac-1.0.0/src/shard/_hub.py +24 -0
- shardac-1.0.0/src/shard/_model.py +85 -0
- shardac-1.0.0/src/shard/_protocol.py +164 -0
- shardac-1.0.0/src/shard/_result.py +37 -0
- shardac-1.0.0/src/shard/_runtime.py +75 -0
- shardac-1.0.0/src/shard/_spec.py +132 -0
- shardac-1.0.0/src/shard/_ticks.py +51 -0
- shardac-1.0.0/src/shard/_weights/__init__.py +0 -0
- shardac-1.0.0/src/shard/_weights/shard-2-nano/metadata.json +68 -0
- shardac-1.0.0/src/shard/_weights/shard-2-nano/model.onnx +0 -0
- shardac-1.0.0/src/shard/py.typed +0 -0
- shardac-1.0.0/tests/test_collect.py +64 -0
- shardac-1.0.0/tests/test_features.py +79 -0
- shardac-1.0.0/tests/test_model.py +194 -0
- shardac-1.0.0/tests/vectors/shard-2-nano.json +7331 -0
shardac-1.0.0/.gitignore
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Model format 1
|
|
2
|
+
|
|
3
|
+
This document specifies how a model packaged for shardac is run, so that it can be reimplemented in other languages. An implementation that follows it reproduces the reference vectors in `tests/vectors/` within the tolerances stated there.
|
|
4
|
+
|
|
5
|
+
## Model files
|
|
6
|
+
|
|
7
|
+
A model is a directory, a Hugging Face repository or a package resource with two files:
|
|
8
|
+
|
|
9
|
+
| File | Content |
|
|
10
|
+
|---|---|
|
|
11
|
+
| `model.onnx` | ONNX graph with one float32 input of shape `[batch, window, features]` and one output of shape `[batch, 1]` holding the probability of each window. Clipping, normalisation and the output sigmoid are part of the graph. The graph requires `batch >= 1`, so it is not run when there are no windows. |
|
|
12
|
+
| `metadata.json` | The description below. |
|
|
13
|
+
|
|
14
|
+
## metadata.json
|
|
15
|
+
|
|
16
|
+
| Key | Content |
|
|
17
|
+
|---|---|
|
|
18
|
+
| `format` | `1`, the version of this document. |
|
|
19
|
+
| `protocol` | The input protocol, `shard-2`. |
|
|
20
|
+
| `name`, `version` | Model identifier and version. |
|
|
21
|
+
| `io` | `{"input": {"name": ...}, "output": {"name": ...}}`, the tensor names in the graph. |
|
|
22
|
+
| `window`, `stride` | Window length in rows and the step between window starts. |
|
|
23
|
+
| `threshold` | Decision threshold in (0, 1). A window is suspicious when `prob > threshold`. |
|
|
24
|
+
| `features` | Ordered list of `{"name", "op", "column"}`. The order is the order of the last input dimension. |
|
|
25
|
+
| `schedule` | Optional. `{"type": "slide", "event": <column>}` selects the windows described below. Without it, windows start every `stride` rows. |
|
|
26
|
+
| `sha256` | SHA-256 of `model.onnx`. |
|
|
27
|
+
|
|
28
|
+
Unknown top-level keys are ignored. Unknown keys inside a feature, an unknown `op` and an unknown `protocol` are errors, and a model that uses them needs a newer implementation.
|
|
29
|
+
|
|
30
|
+
## Protocol `shard-2`
|
|
31
|
+
|
|
32
|
+
The input is the per-tick data recorded by the Shard 2 plugin for one player, one row per client tick, oldest first. A row corresponds to one movement packet received by the server, nominally 20 per second. Column names and wire types are those of the plugin's tick schema. The package lists them in `src/shard/_protocol.py`. Values of `bool` columns are 0 or 1, values of integer columns are whole numbers within the range of their type, and values of `f32` columns are finite and within the float32 range.
|
|
33
|
+
|
|
34
|
+
Columns with a special role:
|
|
35
|
+
|
|
36
|
+
| Column | Role |
|
|
37
|
+
|---|---|
|
|
38
|
+
| `sequence_id` | Optional. Rows with different values belong to different segments. |
|
|
39
|
+
| `segment` | Optional, not part of the plugin schema. Rows with different values belong to different segments. |
|
|
40
|
+
| `tick_index` | Optional. Counter of the recording, strictly increasing within a segment, used for the ticks reported with windows. It may skip values, for example on rows the plugin does not record, and a skip does not start a segment. Without it, rows are numbered `0, 1, ..., n - 1`. |
|
|
41
|
+
| `teleport_tick` | Optional. 1 on the first recorded row after the client applied a server teleport or a server-set rotation, otherwise 0. That row already carries the position and rotation set by the server. |
|
|
42
|
+
|
|
43
|
+
Columns used by Shard 2 Nano:
|
|
44
|
+
|
|
45
|
+
| Column | Definition |
|
|
46
|
+
|---|---|
|
|
47
|
+
| `yaw` | Yaw in degrees as sent by the client, not normalised to [-180, 180). |
|
|
48
|
+
| `pitch` | Pitch in degrees as sent by the client. |
|
|
49
|
+
| `attack_this_tick` | 1 if the player attacked an entity in this row, otherwise 0. |
|
|
50
|
+
| `ticks_since_attack` | Rows since the most recent attack: 0 on the attack row, 255 before the first attack, saturating at 255. |
|
|
51
|
+
|
|
52
|
+
## Segments
|
|
53
|
+
|
|
54
|
+
A segment is a maximal run of consecutive rows with equal `sequence_id` and equal `segment`. Features and windows are computed for each segment independently.
|
|
55
|
+
|
|
56
|
+
## Features
|
|
57
|
+
|
|
58
|
+
Each column is converted to float32 before any arithmetic, and all arithmetic is in float32. For row `t` of a segment, with `t = 0` its first row:
|
|
59
|
+
|
|
60
|
+
| `op` | Value |
|
|
61
|
+
|---|---|
|
|
62
|
+
| `value` | `x[t]` |
|
|
63
|
+
| `delta` | `d[t] = x[t] - x[t-1]`, 0 for `t = 0` and on rows with `teleport_tick = 1` |
|
|
64
|
+
| `accel` | `d[t] - d[t-1]` with `d` as above, 0 for `t = 0`, on rows with `teleport_tick = 1` and on the row after each of them |
|
|
65
|
+
|
|
66
|
+
## Windows
|
|
67
|
+
|
|
68
|
+
Rows are numbered `0 .. n - 1` within a segment of `n` rows. With a `slide` schedule, a window ends at every row `e` such that `e` is a multiple of `stride`, `window - 1 <= e < n`, and the rows `e - window + 1 .. e` contain at least one row where the `event` column is not 0. This is the sliding schedule of the Shard service. The service aligns `e` to its own row counter, so a reimplementation reproduces the set of windows up to that phase. Without a schedule, windows start at rows `0, stride, 2 * stride, ...` while `start + window <= n`. A window holds `window` consecutive rows of the features in the order of `features`. Windows of all segments are ordered by their start. A window reports the `tick_index` of its first and last row.
|
|
69
|
+
|
|
70
|
+
## Collect recordings
|
|
71
|
+
|
|
72
|
+
A recording of the Shard 2 plugin's collect mode is a directory of window files `w0.csv`, `w1.csv`, ... with one header line of column names. Windows overlap. They are merged by the key (`sequence_id`, `tick_index`), keeping the first copy in window order, and sorted by that key. The columns `ticks_to_attack` and `window_start` describe a window rather than a tick and are dropped. A new `segment` starts where two consecutive merged rows are not consecutive rows of any window file, which marks a hole in the recording.
|
|
73
|
+
|
|
74
|
+
## Reference vectors
|
|
75
|
+
|
|
76
|
+
`tests/vectors/<model>.json` gives, for each case, the per-tick input, the features of every row and, for every window, `start_tick`, `end_tick` and `prob`. Features must match within `tolerance.features` and probabilities within `tolerance.prob`, both absolute.
|
shardac-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
shardac-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: shardac
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Open-weight models for detecting cheats in Minecraft: Java Edition
|
|
5
|
+
Project-URL: Homepage, https://shard.ac
|
|
6
|
+
Project-URL: Source, https://github.com/kaelusai/shardac
|
|
7
|
+
Project-URL: Model card, https://huggingface.co/kaelusai/shard-2-nano
|
|
8
|
+
Project-URL: Methodology, https://shard.ac/methodology/shard-2
|
|
9
|
+
Author: Shard
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: anticheat,minecraft,onnx,time-series,transformer
|
|
13
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Topic :: Games/Entertainment
|
|
24
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: >=3.10
|
|
27
|
+
Requires-Dist: numpy>=1.21
|
|
28
|
+
Requires-Dist: onnxruntime>=1.15
|
|
29
|
+
Provides-Extra: hub
|
|
30
|
+
Requires-Dist: huggingface-hub>=0.20; extra == 'hub'
|
|
31
|
+
Provides-Extra: pandas
|
|
32
|
+
Requires-Dist: pandas>=1.3; extra == 'pandas'
|
|
33
|
+
Provides-Extra: test
|
|
34
|
+
Requires-Dist: pandas>=1.3; extra == 'test'
|
|
35
|
+
Requires-Dist: pytest>=7; extra == 'test'
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
# shardac
|
|
39
|
+
|
|
40
|
+
Open-weight models from Shard for detecting cheats in Minecraft: Java Edition from player data received by the server.
|
|
41
|
+
|
|
42
|
+
The package ships Shard 2 Nano, the smallest model of the Shard 2 family. The model card, evaluation and limitations are published on [Hugging Face](https://huggingface.co/kaelusai/shard-2-nano).
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install shardac
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The bundled model weights are included in the package. Loading models from Hugging Face requires the `hub` extra:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install "shardac[hub]"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The distribution is named `shardac` and is imported as `shard`. It cannot be installed in the same environment as the unrelated `shard` package from PyPI, which uses the same import name.
|
|
57
|
+
|
|
58
|
+
## Quick start
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
import shard
|
|
62
|
+
|
|
63
|
+
model = shard.load("shard-2-nano")
|
|
64
|
+
windows = model.predict(ticks)
|
|
65
|
+
|
|
66
|
+
for start, end, prob in zip(windows.start_tick, windows.end_tick, windows.prob):
|
|
67
|
+
print(f"ticks {start}-{end}: {prob:.3f}")
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`ticks` holds the data of one player with one row per client tick, oldest first, as a pandas DataFrame or a mapping of column name to array. Column names follow the tick schema of the Shard 2 plugin. Shard 2 Nano reads:
|
|
71
|
+
|
|
72
|
+
| Column | Required | Definition |
|
|
73
|
+
|---|---|---|
|
|
74
|
+
| `yaw` | yes | View yaw in degrees as sent by the client, not normalised to [-180, 180). |
|
|
75
|
+
| `pitch` | yes | View pitch in degrees. |
|
|
76
|
+
| `attack_this_tick` | yes | 1 if the player attacked an entity during the tick, otherwise 0. |
|
|
77
|
+
| `ticks_since_attack` | yes | Ticks elapsed since the most recent attack, 0 on the attack tick, 255 before the first attack, saturating at 255. |
|
|
78
|
+
| `teleport_tick` | no | 1 on the first tick after the client applied a server teleport or a server-set rotation, otherwise 0. |
|
|
79
|
+
| `tick_index` | no | Tick counter, reported with windows. |
|
|
80
|
+
| `sequence_id`, `segment` | no | A change of either value starts a new segment, and windows never span segments. |
|
|
81
|
+
|
|
82
|
+
A session directory written by the plugin's collect mode is read directly:
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
ticks = shard.read_collect("path/to/collect/<session>")
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Results
|
|
89
|
+
|
|
90
|
+
`model.predict` cuts windows by the schedule in the model's metadata. For Shard 2 Nano these are windows of 32 ticks around attacks, with the attack on the 17th tick and at least 16 ticks between the attacks of consecutive windows. It returns `Windows`:
|
|
91
|
+
|
|
92
|
+
- `windows.prob`: the probability of each window.
|
|
93
|
+
- `windows.start_tick`, `windows.end_tick`: the first and last tick each window covers.
|
|
94
|
+
- `windows.suspicious`: windows with a probability above the 0.9 threshold.
|
|
95
|
+
- `windows.to_pandas()`: one row per window, requires pandas.
|
|
96
|
+
|
|
97
|
+
A single window above the threshold is not sufficient grounds for punishing a player. How window probabilities are aggregated over a session is described in the [Shard 2 methodology](https://shard.ac/methodology/shard-2).
|
|
98
|
+
|
|
99
|
+
## Lower-level API
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
features = model.features(ticks)
|
|
103
|
+
batch = model.windows(features, starts=[100, 340, 512]) # windows starting at given rows
|
|
104
|
+
batch = model.windows(features) # a window every stride rows
|
|
105
|
+
prob = model(batch)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Deltas and accelerations of a row depend on the two rows before it, so windows are cut from features computed over the whole recording. Features computed over exactly one window's rows differ on its first two rows.
|
|
109
|
+
|
|
110
|
+
`model.features` computes the features of every row, `model.windows` treats its input as one contiguous segment, and calling the model on a batch of shape `[n, window, features]` returns the probability of each window. `model.feature_names`, `model.columns`, `model.window`, `model.stride` and `model.threshold` describe the model.
|
|
111
|
+
|
|
112
|
+
## Loading
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
shard.models() # names of the bundled models
|
|
116
|
+
shard.load("shard-2-nano") # bundled model
|
|
117
|
+
shard.load("./models/shard-2-nano") # local directory with model.onnx and metadata.json
|
|
118
|
+
shard.load("kaelusai/shard-2-nano", revision="v1.0.0")
|
|
119
|
+
shard.load("shard-2-nano", providers=["CUDAExecutionProvider"])
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
A model is an ONNX graph and a `metadata.json` that declares its features from the plugin's tick schema, so models of other authors in this format load the same way. The loader verifies the SHA-256 of `model.onnx` against `metadata.json`, which guards against corrupted files but not against a malicious repository. For repositories of other authors, pin `revision` to a commit. A string of the form `owner/name` that is neither a bundled model nor an existing directory is treated as a Hugging Face repository id, so relative paths should start with `./`.
|
|
123
|
+
|
|
124
|
+
GPU execution requires `onnxruntime-gpu` in place of `onnxruntime`. The two packages cannot be installed in the same environment.
|
|
125
|
+
|
|
126
|
+
## Ports
|
|
127
|
+
|
|
128
|
+
[CONTRACT.md](CONTRACT.md) specifies the model format, the protocol columns, the feature operations, windowing and the reading of collect recordings for implementations in other languages. Reference vectors are in [tests/vectors](tests/vectors).
|
|
129
|
+
|
|
130
|
+
## License
|
|
131
|
+
|
|
132
|
+
The code, the model weights and the metadata are released under the Apache License 2.0.
|
shardac-1.0.0/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# shardac
|
|
2
|
+
|
|
3
|
+
Open-weight models from Shard for detecting cheats in Minecraft: Java Edition from player data received by the server.
|
|
4
|
+
|
|
5
|
+
The package ships Shard 2 Nano, the smallest model of the Shard 2 family. The model card, evaluation and limitations are published on [Hugging Face](https://huggingface.co/kaelusai/shard-2-nano).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install shardac
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The bundled model weights are included in the package. Loading models from Hugging Face requires the `hub` extra:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install "shardac[hub]"
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The distribution is named `shardac` and is imported as `shard`. It cannot be installed in the same environment as the unrelated `shard` package from PyPI, which uses the same import name.
|
|
20
|
+
|
|
21
|
+
## Quick start
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
import shard
|
|
25
|
+
|
|
26
|
+
model = shard.load("shard-2-nano")
|
|
27
|
+
windows = model.predict(ticks)
|
|
28
|
+
|
|
29
|
+
for start, end, prob in zip(windows.start_tick, windows.end_tick, windows.prob):
|
|
30
|
+
print(f"ticks {start}-{end}: {prob:.3f}")
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`ticks` holds the data of one player with one row per client tick, oldest first, as a pandas DataFrame or a mapping of column name to array. Column names follow the tick schema of the Shard 2 plugin. Shard 2 Nano reads:
|
|
34
|
+
|
|
35
|
+
| Column | Required | Definition |
|
|
36
|
+
|---|---|---|
|
|
37
|
+
| `yaw` | yes | View yaw in degrees as sent by the client, not normalised to [-180, 180). |
|
|
38
|
+
| `pitch` | yes | View pitch in degrees. |
|
|
39
|
+
| `attack_this_tick` | yes | 1 if the player attacked an entity during the tick, otherwise 0. |
|
|
40
|
+
| `ticks_since_attack` | yes | Ticks elapsed since the most recent attack, 0 on the attack tick, 255 before the first attack, saturating at 255. |
|
|
41
|
+
| `teleport_tick` | no | 1 on the first tick after the client applied a server teleport or a server-set rotation, otherwise 0. |
|
|
42
|
+
| `tick_index` | no | Tick counter, reported with windows. |
|
|
43
|
+
| `sequence_id`, `segment` | no | A change of either value starts a new segment, and windows never span segments. |
|
|
44
|
+
|
|
45
|
+
A session directory written by the plugin's collect mode is read directly:
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
ticks = shard.read_collect("path/to/collect/<session>")
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Results
|
|
52
|
+
|
|
53
|
+
`model.predict` cuts windows by the schedule in the model's metadata. For Shard 2 Nano these are windows of 32 ticks around attacks, with the attack on the 17th tick and at least 16 ticks between the attacks of consecutive windows. It returns `Windows`:
|
|
54
|
+
|
|
55
|
+
- `windows.prob`: the probability of each window.
|
|
56
|
+
- `windows.start_tick`, `windows.end_tick`: the first and last tick each window covers.
|
|
57
|
+
- `windows.suspicious`: windows with a probability above the 0.9 threshold.
|
|
58
|
+
- `windows.to_pandas()`: one row per window, requires pandas.
|
|
59
|
+
|
|
60
|
+
A single window above the threshold is not sufficient grounds for punishing a player. How window probabilities are aggregated over a session is described in the [Shard 2 methodology](https://shard.ac/methodology/shard-2).
|
|
61
|
+
|
|
62
|
+
## Lower-level API
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
features = model.features(ticks)
|
|
66
|
+
batch = model.windows(features, starts=[100, 340, 512]) # windows starting at given rows
|
|
67
|
+
batch = model.windows(features) # a window every stride rows
|
|
68
|
+
prob = model(batch)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Deltas and accelerations of a row depend on the two rows before it, so windows are cut from features computed over the whole recording. Features computed over exactly one window's rows differ on its first two rows.
|
|
72
|
+
|
|
73
|
+
`model.features` computes the features of every row, `model.windows` treats its input as one contiguous segment, and calling the model on a batch of shape `[n, window, features]` returns the probability of each window. `model.feature_names`, `model.columns`, `model.window`, `model.stride` and `model.threshold` describe the model.
|
|
74
|
+
|
|
75
|
+
## Loading
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
shard.models() # names of the bundled models
|
|
79
|
+
shard.load("shard-2-nano") # bundled model
|
|
80
|
+
shard.load("./models/shard-2-nano") # local directory with model.onnx and metadata.json
|
|
81
|
+
shard.load("kaelusai/shard-2-nano", revision="v1.0.0")
|
|
82
|
+
shard.load("shard-2-nano", providers=["CUDAExecutionProvider"])
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
A model is an ONNX graph and a `metadata.json` that declares its features from the plugin's tick schema, so models of other authors in this format load the same way. The loader verifies the SHA-256 of `model.onnx` against `metadata.json`, which guards against corrupted files but not against a malicious repository. For repositories of other authors, pin `revision` to a commit. A string of the form `owner/name` that is neither a bundled model nor an existing directory is treated as a Hugging Face repository id, so relative paths should start with `./`.
|
|
86
|
+
|
|
87
|
+
GPU execution requires `onnxruntime-gpu` in place of `onnxruntime`. The two packages cannot be installed in the same environment.
|
|
88
|
+
|
|
89
|
+
## Ports
|
|
90
|
+
|
|
91
|
+
[CONTRACT.md](CONTRACT.md) specifies the model format, the protocol columns, the feature operations, windowing and the reading of collect recordings for implementations in other languages. Reference vectors are in [tests/vectors](tests/vectors).
|
|
92
|
+
|
|
93
|
+
## License
|
|
94
|
+
|
|
95
|
+
The code, the model weights and the metadata are released under the Apache License 2.0.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "shardac"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Open-weight models for detecting cheats in Minecraft: Java Edition"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
authors = [{ name = "Shard" }]
|
|
14
|
+
keywords = ["minecraft", "anticheat", "onnx", "transformer", "time-series"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 5 - Production/Stable",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Intended Audience :: Science/Research",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Programming Language :: Python :: 3.14",
|
|
26
|
+
"Topic :: Games/Entertainment",
|
|
27
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
28
|
+
"Typing :: Typed",
|
|
29
|
+
]
|
|
30
|
+
dependencies = ["numpy>=1.21", "onnxruntime>=1.15"]
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
hub = ["huggingface_hub>=0.20"]
|
|
34
|
+
pandas = ["pandas>=1.3"]
|
|
35
|
+
test = ["pytest>=7", "pandas>=1.3"]
|
|
36
|
+
|
|
37
|
+
[project.urls]
|
|
38
|
+
Homepage = "https://shard.ac"
|
|
39
|
+
Source = "https://github.com/kaelusai/shardac"
|
|
40
|
+
"Model card" = "https://huggingface.co/kaelusai/shard-2-nano"
|
|
41
|
+
Methodology = "https://shard.ac/methodology/shard-2"
|
|
42
|
+
|
|
43
|
+
[tool.hatch.version]
|
|
44
|
+
path = "src/shard/__init__.py"
|
|
45
|
+
|
|
46
|
+
[tool.hatch.build.targets.wheel]
|
|
47
|
+
packages = ["src/shard"]
|
|
48
|
+
|
|
49
|
+
[tool.hatch.build.targets.sdist]
|
|
50
|
+
include = ["src", "tests", "CONTRACT.md", "README.md", "LICENSE"]
|
|
51
|
+
|
|
52
|
+
[tool.pytest.ini_options]
|
|
53
|
+
testpaths = ["tests"]
|
|
54
|
+
|
|
55
|
+
[tool.ruff]
|
|
56
|
+
line-length = 120
|
|
57
|
+
target-version = "py310"
|
|
58
|
+
|
|
59
|
+
[tool.ruff.lint]
|
|
60
|
+
select = ["E", "F", "W", "I", "B", "UP", "SIM", "RUF"]
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from importlib.resources import files as _package_files
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from . import _hub
|
|
8
|
+
from ._collect import read_collect
|
|
9
|
+
from ._model import Model
|
|
10
|
+
from ._result import Windows
|
|
11
|
+
from ._runtime import METADATA_FILE, MODEL_FILE, ModelFiles, read_dir
|
|
12
|
+
|
|
13
|
+
__version__ = "1.0.0"
|
|
14
|
+
__all__ = ["Model", "Windows", "load", "models", "read_collect"]
|
|
15
|
+
|
|
16
|
+
_WEIGHTS = _package_files("shard._weights")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def models() -> tuple[str, ...]:
|
|
20
|
+
return tuple(sorted(d.name for d in _WEIGHTS.iterdir() if d.is_dir() and d.joinpath(METADATA_FILE).is_file()))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _bundled(name: str) -> ModelFiles:
|
|
24
|
+
d = _WEIGHTS.joinpath(name)
|
|
25
|
+
return ModelFiles(
|
|
26
|
+
d.joinpath(MODEL_FILE).read_bytes(),
|
|
27
|
+
json.loads(d.joinpath(METADATA_FILE).read_text(encoding="utf-8")),
|
|
28
|
+
f"shardac:{name}",
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def load(source: str | Path, *, revision: str | None = None, providers=None) -> Model:
|
|
33
|
+
"""Accepts a bundled model name, a local directory or a Hugging Face repository id."""
|
|
34
|
+
if isinstance(source, str) and source in models():
|
|
35
|
+
if revision is not None:
|
|
36
|
+
raise ValueError("revision applies only to a Hugging Face repository id")
|
|
37
|
+
return Model(_bundled(source), providers)
|
|
38
|
+
path = Path(source).expanduser()
|
|
39
|
+
if path.is_dir():
|
|
40
|
+
if revision is not None:
|
|
41
|
+
raise ValueError("revision applies only to a Hugging Face repository id")
|
|
42
|
+
return Model(read_dir(path, str(path)), providers)
|
|
43
|
+
text = str(source)
|
|
44
|
+
if text.count("/") == 1 and not text.startswith((".", "/", "~")):
|
|
45
|
+
return Model(_hub.download(text, revision), providers)
|
|
46
|
+
raise FileNotFoundError(
|
|
47
|
+
f"{source} is not a bundled model ({', '.join(models())}), a model directory or a Hugging Face repository id"
|
|
48
|
+
)
|