kinfer 0.3.3__cp312-cp312-macosx_11_0_arm64.whl → 0.4.1__cp312-cp312-macosx_11_0_arm64.whl
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.
- kinfer/__init__.py +0 -5
- kinfer/common/__init__.py +0 -0
- kinfer/common/types.py +12 -0
- kinfer/export/common.py +41 -0
- kinfer/export/jax.py +53 -0
- kinfer/export/pytorch.py +45 -110
- kinfer/export/serialize.py +93 -0
- kinfer/requirements.txt +3 -4
- kinfer/rust/Cargo.toml +20 -8
- kinfer/rust/src/lib.rs +2 -11
- kinfer/rust/src/model.rs +286 -121
- kinfer/rust/src/runtime.rs +104 -0
- kinfer/rust_bindings/Cargo.toml +8 -1
- kinfer/rust_bindings/rust_bindings.pyi +36 -0
- kinfer/rust_bindings/src/lib.rs +326 -1
- kinfer/rust_bindings.cpython-312-darwin.so +0 -0
- kinfer/rust_bindings.pyi +30 -1
- kinfer-0.4.1.dist-info/METADATA +55 -0
- kinfer-0.4.1.dist-info/RECORD +26 -0
- {kinfer-0.3.3.dist-info → kinfer-0.4.1.dist-info}/WHEEL +2 -1
- kinfer/inference/__init__.py +0 -2
- kinfer/inference/base.py +0 -64
- kinfer/inference/python.py +0 -66
- kinfer/proto/__init__.py +0 -40
- kinfer/proto/kinfer_pb2.py +0 -103
- kinfer/proto/kinfer_pb2.pyi +0 -1097
- kinfer/requirements-dev.txt +0 -8
- kinfer/rust/build.rs +0 -16
- kinfer/rust/src/kinfer_proto.rs +0 -14
- kinfer/rust/src/main.rs +0 -6
- kinfer/rust/src/onnx_serializer.rs +0 -804
- kinfer/rust/src/serializer.rs +0 -221
- kinfer/rust/src/tests/onnx_serializer_tests.rs +0 -212
- kinfer/serialize/__init__.py +0 -60
- kinfer/serialize/base.py +0 -536
- kinfer/serialize/json.py +0 -399
- kinfer/serialize/numpy.py +0 -426
- kinfer/serialize/pytorch.py +0 -402
- kinfer/serialize/schema.py +0 -125
- kinfer/serialize/types.py +0 -17
- kinfer/serialize/utils.py +0 -177
- kinfer-0.3.3.dist-info/METADATA +0 -57
- kinfer-0.3.3.dist-info/RECORD +0 -40
- {kinfer-0.3.3.dist-info → kinfer-0.4.1.dist-info/licenses}/LICENSE +0 -0
- {kinfer-0.3.3.dist-info → kinfer-0.4.1.dist-info}/top_level.txt +0 -0
kinfer/serialize/utils.py
DELETED
@@ -1,177 +0,0 @@
|
|
1
|
-
"""Utility functions for serializing and deserializing Kinfer values."""
|
2
|
-
|
3
|
-
import math
|
4
|
-
from typing import Any, Collection
|
5
|
-
|
6
|
-
import numpy as np
|
7
|
-
import torch
|
8
|
-
|
9
|
-
from kinfer import proto as K
|
10
|
-
|
11
|
-
|
12
|
-
def numpy_dtype(dtype: K.DType.ValueType) -> type[np.floating] | type[np.integer]:
|
13
|
-
match dtype:
|
14
|
-
case K.DType.FP8:
|
15
|
-
raise NotImplementedError("FP8 is not supported")
|
16
|
-
case K.DType.FP16:
|
17
|
-
return np.float16
|
18
|
-
case K.DType.FP32:
|
19
|
-
return np.float32
|
20
|
-
case K.DType.FP64:
|
21
|
-
return np.float64
|
22
|
-
case K.DType.INT8:
|
23
|
-
return np.int8
|
24
|
-
case K.DType.INT16:
|
25
|
-
return np.int16
|
26
|
-
case K.DType.INT32:
|
27
|
-
return np.int32
|
28
|
-
case K.DType.INT64:
|
29
|
-
return np.int64
|
30
|
-
case K.DType.UINT8:
|
31
|
-
return np.uint8
|
32
|
-
case K.DType.UINT16:
|
33
|
-
return np.uint16
|
34
|
-
case K.DType.UINT32:
|
35
|
-
return np.uint32
|
36
|
-
case K.DType.UINT64:
|
37
|
-
return np.uint64
|
38
|
-
case _:
|
39
|
-
raise ValueError(f"Unsupported dtype: {dtype}")
|
40
|
-
|
41
|
-
|
42
|
-
def pytorch_dtype(dtype: K.DType.ValueType) -> torch.dtype:
|
43
|
-
match dtype:
|
44
|
-
case K.DType.FP8:
|
45
|
-
raise NotImplementedError("FP8 is not supported")
|
46
|
-
case K.DType.FP16:
|
47
|
-
return torch.float16
|
48
|
-
case K.DType.FP32:
|
49
|
-
return torch.float32
|
50
|
-
case K.DType.FP64:
|
51
|
-
return torch.float64
|
52
|
-
case K.DType.INT8:
|
53
|
-
return torch.int8
|
54
|
-
case K.DType.INT16:
|
55
|
-
return torch.int16
|
56
|
-
case K.DType.INT32:
|
57
|
-
return torch.int32
|
58
|
-
case K.DType.INT64:
|
59
|
-
return torch.int64
|
60
|
-
case K.DType.UINT8:
|
61
|
-
return torch.uint8
|
62
|
-
case K.DType.UINT16:
|
63
|
-
return torch.uint16
|
64
|
-
case K.DType.UINT32:
|
65
|
-
return torch.uint32
|
66
|
-
case K.DType.UINT64:
|
67
|
-
return torch.uint64
|
68
|
-
case _:
|
69
|
-
raise ValueError(f"Unsupported dtype: {dtype}")
|
70
|
-
|
71
|
-
|
72
|
-
def parse_bytes(data: bytes, dtype: K.DType.ValueType) -> np.ndarray:
|
73
|
-
return np.frombuffer(data, dtype=numpy_dtype(dtype))
|
74
|
-
|
75
|
-
|
76
|
-
def dtype_num_bytes(dtype: K.DType.ValueType) -> int:
|
77
|
-
match dtype:
|
78
|
-
case K.DType.FP8 | K.DType.INT8 | K.DType.UINT8:
|
79
|
-
return 1
|
80
|
-
case K.DType.FP16 | K.DType.INT16 | K.DType.UINT16:
|
81
|
-
return 2
|
82
|
-
case K.DType.FP32 | K.DType.INT32 | K.DType.UINT32:
|
83
|
-
return 4
|
84
|
-
case K.DType.FP64 | K.DType.INT64 | K.DType.UINT64:
|
85
|
-
return 8
|
86
|
-
case _:
|
87
|
-
raise ValueError(f"Unsupported dtype: {dtype}")
|
88
|
-
|
89
|
-
|
90
|
-
def dtype_range(dtype: K.DType.ValueType) -> tuple[int, int]:
|
91
|
-
match dtype:
|
92
|
-
case K.DType.FP8:
|
93
|
-
return -1, 1
|
94
|
-
case K.DType.FP16:
|
95
|
-
return -1, 1
|
96
|
-
case K.DType.FP32:
|
97
|
-
return -1, 1
|
98
|
-
case K.DType.FP64:
|
99
|
-
return -1, 1
|
100
|
-
case K.DType.INT8:
|
101
|
-
return -(2**7), 2**7 - 1
|
102
|
-
case K.DType.INT16:
|
103
|
-
return -(2**15), 2**15 - 1
|
104
|
-
case K.DType.INT32:
|
105
|
-
return -(2**31), 2**31 - 1
|
106
|
-
case K.DType.INT64:
|
107
|
-
return -(2**63), 2**63 - 1
|
108
|
-
case K.DType.UINT8:
|
109
|
-
return 0, 2**8 - 1
|
110
|
-
case K.DType.UINT16:
|
111
|
-
return 0, 2**16 - 1
|
112
|
-
case K.DType.UINT32:
|
113
|
-
return 0, 2**32 - 1
|
114
|
-
case K.DType.UINT64:
|
115
|
-
return 0, 2**64 - 1
|
116
|
-
case _:
|
117
|
-
raise ValueError(f"Unsupported dtype: {dtype}")
|
118
|
-
|
119
|
-
|
120
|
-
def convert_torque(
|
121
|
-
value: float,
|
122
|
-
from_unit: K.JointTorqueUnit.ValueType,
|
123
|
-
to_unit: K.JointTorqueUnit.ValueType,
|
124
|
-
) -> float:
|
125
|
-
if from_unit == to_unit:
|
126
|
-
return value
|
127
|
-
raise ValueError(f"Unsupported unit: {from_unit}")
|
128
|
-
|
129
|
-
|
130
|
-
def convert_angular_velocity(
|
131
|
-
value: float,
|
132
|
-
from_unit: K.JointVelocityUnit.ValueType,
|
133
|
-
to_unit: K.JointVelocityUnit.ValueType,
|
134
|
-
) -> float:
|
135
|
-
if from_unit == to_unit:
|
136
|
-
return value
|
137
|
-
if from_unit == K.JointVelocityUnit.DEGREES_PER_SECOND:
|
138
|
-
assert to_unit == K.JointVelocityUnit.RADIANS_PER_SECOND
|
139
|
-
return value * math.pi / 180
|
140
|
-
if from_unit == K.JointVelocityUnit.RADIANS_PER_SECOND:
|
141
|
-
assert to_unit == K.JointVelocityUnit.DEGREES_PER_SECOND
|
142
|
-
return value * 180 / math.pi
|
143
|
-
raise ValueError(f"Unsupported unit: {from_unit}")
|
144
|
-
|
145
|
-
|
146
|
-
def convert_angular_position(
|
147
|
-
value: float,
|
148
|
-
from_unit: K.JointPositionUnit.ValueType,
|
149
|
-
to_unit: K.JointPositionUnit.ValueType,
|
150
|
-
) -> float:
|
151
|
-
if from_unit == to_unit:
|
152
|
-
return value
|
153
|
-
if from_unit == K.JointPositionUnit.DEGREES:
|
154
|
-
return value * math.pi / 180
|
155
|
-
if from_unit == K.JointPositionUnit.RADIANS:
|
156
|
-
return value * 180 / math.pi
|
157
|
-
raise ValueError(f"Unsupported unit: {from_unit}")
|
158
|
-
|
159
|
-
|
160
|
-
def check_names_match(a_name: str, a: Collection[str], b_name: str, b: Collection[str]) -> None:
|
161
|
-
name_set_a = set(a)
|
162
|
-
name_set_b = set(b)
|
163
|
-
if name_set_a != name_set_b:
|
164
|
-
only_in_a = name_set_a - name_set_b
|
165
|
-
only_in_b = name_set_b - name_set_a
|
166
|
-
message = "Names must match!"
|
167
|
-
if only_in_a:
|
168
|
-
message += f" Only in {a_name}: {only_in_a}"
|
169
|
-
if only_in_b:
|
170
|
-
message += f" Only in {b_name}: {only_in_b}"
|
171
|
-
raise ValueError(message)
|
172
|
-
|
173
|
-
|
174
|
-
def as_float(value: Any) -> float: # noqa: ANN401
|
175
|
-
if not isinstance(value, (float, int)):
|
176
|
-
raise ValueError(f"Value must be a float or int: {value}")
|
177
|
-
return float(value)
|
kinfer-0.3.3.dist-info/METADATA
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: kinfer
|
3
|
-
Version: 0.3.3
|
4
|
-
Summary: Tool to make it easier to run a model on a real robot
|
5
|
-
Home-page: https://github.com/kscalelabs/kinfer.git
|
6
|
-
Author: K-Scale Labs
|
7
|
-
Requires-Python: >=3.11
|
8
|
-
Description-Content-Type: text/markdown
|
9
|
-
License-File: LICENSE
|
10
|
-
Requires-Dist: torch
|
11
|
-
Requires-Dist: onnx
|
12
|
-
Requires-Dist: onnxruntime
|
13
|
-
Requires-Dist: protobuf
|
14
|
-
Provides-Extra: dev
|
15
|
-
Requires-Dist: black; extra == "dev"
|
16
|
-
Requires-Dist: darglint; extra == "dev"
|
17
|
-
Requires-Dist: mypy; extra == "dev"
|
18
|
-
Requires-Dist: mypy-protobuf; extra == "dev"
|
19
|
-
Requires-Dist: pytest; extra == "dev"
|
20
|
-
Requires-Dist: ruff; extra == "dev"
|
21
|
-
|
22
|
-
# kinfer
|
23
|
-
|
24
|
-
This package is designed to support exporting and running inference on PyTorch models.
|
25
|
-
|
26
|
-
## Installation
|
27
|
-
|
28
|
-
```bash
|
29
|
-
pip install kinfer
|
30
|
-
```
|
31
|
-
|
32
|
-
### ONNX Runtime
|
33
|
-
|
34
|
-
You can install the latest version of ONNX Runtime on Mac with:
|
35
|
-
|
36
|
-
```bash
|
37
|
-
brew install onnxruntime
|
38
|
-
```
|
39
|
-
|
40
|
-
You may need to add the binary to your DYLD_LIBRARY_PATH:
|
41
|
-
|
42
|
-
```bash
|
43
|
-
$ brew ls onnxruntime
|
44
|
-
/opt/homebrew/Cellar/onnxruntime/1.20.1/include/onnxruntime/ (11 files)
|
45
|
-
/opt/homebrew/Cellar/onnxruntime/1.20.1/lib/libonnxruntime.1.20.1.dylib # <-- This is the binary
|
46
|
-
/opt/homebrew/Cellar/onnxruntime/1.20.1/lib/cmake/ (4 files)
|
47
|
-
/opt/homebrew/Cellar/onnxruntime/1.20.1/lib/pkgconfig/libonnxruntime.pc
|
48
|
-
/opt/homebrew/Cellar/onnxruntime/1.20.1/lib/libonnxruntime.dylib
|
49
|
-
/opt/homebrew/Cellar/onnxruntime/1.20.1/sbom.spdx.json
|
50
|
-
$ export DYLD_LIBRARY_PATH=/opt/homebrew/Cellar/onnxruntime/1.20.1/lib:$DYLD_LIBRARY_PATH
|
51
|
-
```
|
52
|
-
|
53
|
-
### Considerations for Exporting PyTorch Models
|
54
|
-
|
55
|
-
Don't use common names for the inputs to your forward pass. E.g. `input`, `output`, `state`, `state_tensor`, `buffer`, etc.
|
56
|
-
|
57
|
-
This is because ONNX has internal names for the model and if there's a conflict, the inputs will have a .1, .2, etc. suffix which makes it really hard to figure out what value_name to pass into your kinfer io values.
|
kinfer-0.3.3.dist-info/RECORD
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
kinfer/requirements.txt,sha256=-xI0a63Os_v2mkO0Cy5bA5envglD-2c4mdSeLG4movA,91
|
2
|
-
kinfer/__init__.py,sha256=Mt6PA3d3U9voePY0_GQ7rkc9Dgov93jY_OiFHcNDdBg,311
|
3
|
-
kinfer/requirements-dev.txt,sha256=jZzaEENgXPHkAjbnwdglVCaV_GDkwCWIX2BWX0e3uLc,70
|
4
|
-
kinfer/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
|
-
kinfer/rust_bindings.pyi,sha256=KFNalMmwkfoS8BwJfVAz5APaqlW1ryp0xpmnbfud5kc,118
|
6
|
-
kinfer/rust_bindings.cpython-312-darwin.so,sha256=BZR-t6bOln21TcAfBbG52_Fr-PpKF8XannDy1AeULjw,436120
|
7
|
-
kinfer/proto/kinfer_pb2.pyi,sha256=ogFIJ7p2G-ovFig6I0RfIpH4oZ4dd2MkxPznBXENkb8,34151
|
8
|
-
kinfer/proto/__init__.py,sha256=Zz2ApZaHIF375552y54X63XEq3XhZjyujmX_MsNjLmQ,848
|
9
|
-
kinfer/proto/kinfer_pb2.py,sha256=sng4W-ZOdBgCowYK3JcoxoFOmUhPac07YDaoi6noeq0,11968
|
10
|
-
kinfer/rust/Cargo.toml,sha256=3dY7WVXzcNDBinkC2NQ4XtRSXSrwID8k6Y404uCi4jo,296
|
11
|
-
kinfer/rust/build.rs,sha256=VTvGhCtvEPbr-w0mRptPyiAF8rPlPnmyFVThb6NUSPc,422
|
12
|
-
kinfer/rust/src/kinfer_proto.rs,sha256=gpgy5amhHroP40aQVSSQ8xlNFMwdvTAy3dkK-V8Z1Ms,801
|
13
|
-
kinfer/rust/src/lib.rs,sha256=t5ca5ZO4Ss41wSroBa5PIJ64ifc4LuEheRqgDs2Ev6A,236
|
14
|
-
kinfer/rust/src/main.rs,sha256=JQZRmmEQ4wKDmprbGrQUpvN7r8F03Asg-bIIhemSxUA,114
|
15
|
-
kinfer/rust/src/onnx_serializer.rs,sha256=Ti0iLoJi5VPkX_Yq7QPHzmtiJZPXvySUqRw8syAJFw4,29301
|
16
|
-
kinfer/rust/src/serializer.rs,sha256=jaSnb6K8DDynCLdgBU4Nl4Ig8ZrZRdQUXjdZF1Ew7qs,6151
|
17
|
-
kinfer/rust/src/model.rs,sha256=5IWOkl_yj8Ea7yZkFug18ALwKrOtUAg17d7RphrMP1Y,5243
|
18
|
-
kinfer/rust/src/tests/onnx_serializer_tests.rs,sha256=KdrysHqhYC27lIdkNTSUJ9CTBs0PN0-8aw2Xe3pqk4E,7481
|
19
|
-
kinfer/serialize/__init__.py,sha256=-_aNXvBDKh1LrLyF16Kkp3_Rmdd0EeQ3EUy_ZJJs4gk,1997
|
20
|
-
kinfer/serialize/numpy.py,sha256=AovEjcWBVTpRk1bERQtTIP6Ac5W0ivx02lkmkbH8lTU,16146
|
21
|
-
kinfer/serialize/types.py,sha256=op45q0NVrugS00fh0Zp7RNfETybxhF7daEp3dXhK-nE,427
|
22
|
-
kinfer/serialize/pytorch.py,sha256=KO-YRrl1H7pVwx1xWdOvkUSr7Zy6YZVweq16dzcpguI,16169
|
23
|
-
kinfer/serialize/utils.py,sha256=ptvNzyQTRe_ZI1Zc--WALVxHTbJRNaRuUE5P2dWREbI,5382
|
24
|
-
kinfer/serialize/json.py,sha256=QywCQhYAlsA5AY-tfwzmI_unN0znqQyPo-hBgfVT-m0,15081
|
25
|
-
kinfer/serialize/base.py,sha256=2nc0kmWyVqEIbSxpGqRuCgROUp0eciuRLz_-Dgny_YQ,16390
|
26
|
-
kinfer/serialize/schema.py,sha256=wx5Y9vykRvMC5BtMkGtKxvAKvjW4-56ZU449NKfETTE,4730
|
27
|
-
kinfer/inference/__init__.py,sha256=pn8nc2oy3UXdmD_Fm7BcrgE1Tw-LMrQHbHp7jIzw4d8,55
|
28
|
-
kinfer/inference/python.py,sha256=CQanHMPLwQ_LOikaL78wX5daW-lhE0XVSfPJSYIVNBM,2177
|
29
|
-
kinfer/inference/base.py,sha256=HHxYSfehICGDgVTfm9babZ1OKbjKyRuNUUDjx7cGmSU,1778
|
30
|
-
kinfer/export/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
31
|
-
kinfer/export/pytorch.py,sha256=6fBnyS6Q1xL8R5UtD3Zw4fU1sB-Ta6nmpJ8qg9UfryA,4529
|
32
|
-
kinfer/rust_bindings/Cargo.toml,sha256=VZ6MY1QpqUQnDC1ygeSScaf8X-m1zXye6yaODV4RE5o,387
|
33
|
-
kinfer/rust_bindings/pyproject.toml,sha256=jLcJuHCnQRh9HWR_R7a9qLHwj6LMBgnHyeKK_DruO1Y,135
|
34
|
-
kinfer/rust_bindings/src/lib.rs,sha256=rIq7S32Xjv83GXUW1ZNAd5Ex1HwDAYvG0quYJr6VaAQ,405
|
35
|
-
kinfer/rust_bindings/src/bin/stub_gen.rs,sha256=hhoVGnaSfazbSfj5a4x6mPicGPOgWQAfsDmiPej0B6Y,133
|
36
|
-
kinfer-0.3.3.dist-info/RECORD,,
|
37
|
-
kinfer-0.3.3.dist-info/LICENSE,sha256=Qw-Z0XTwS-diSW91e_jLeBPX9zZbAatOJTBLdPHPaC0,1069
|
38
|
-
kinfer-0.3.3.dist-info/WHEEL,sha256=7Wd-yga4fjSiXpUH443rsPZpiZ4h8-uNrXJrYRW_e14,109
|
39
|
-
kinfer-0.3.3.dist-info/top_level.txt,sha256=6mY_t3PYr3Dm0dpqMk80uSnArbvGfCFkxOh1QWtgDEo,7
|
40
|
-
kinfer-0.3.3.dist-info/METADATA,sha256=xmI3l8I2s-kqg-Zn_d37XGreHeb3twrEz0bArq1PMKQ,1884
|
File without changes
|
File without changes
|