kinfer 0.3.3__cp311-cp311-macosx_11_0_arm64.whl → 0.4.0__cp311-cp311-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.
Files changed (45) hide show
  1. kinfer/__init__.py +0 -5
  2. kinfer/common/__init__.py +0 -0
  3. kinfer/common/types.py +11 -0
  4. kinfer/export/common.py +35 -0
  5. kinfer/export/jax.py +51 -0
  6. kinfer/export/pytorch.py +42 -110
  7. kinfer/export/serialize.py +86 -0
  8. kinfer/requirements.txt +3 -4
  9. kinfer/rust/Cargo.toml +8 -6
  10. kinfer/rust/src/lib.rs +2 -11
  11. kinfer/rust/src/model.rs +271 -121
  12. kinfer/rust/src/runtime.rs +104 -0
  13. kinfer/rust_bindings/Cargo.toml +8 -1
  14. kinfer/rust_bindings/rust_bindings.pyi +35 -0
  15. kinfer/rust_bindings/src/lib.rs +310 -1
  16. kinfer/rust_bindings.cpython-311-darwin.so +0 -0
  17. kinfer/rust_bindings.pyi +29 -1
  18. kinfer-0.4.0.dist-info/METADATA +55 -0
  19. kinfer-0.4.0.dist-info/RECORD +26 -0
  20. {kinfer-0.3.3.dist-info → kinfer-0.4.0.dist-info}/WHEEL +2 -1
  21. kinfer/inference/__init__.py +0 -2
  22. kinfer/inference/base.py +0 -64
  23. kinfer/inference/python.py +0 -66
  24. kinfer/proto/__init__.py +0 -40
  25. kinfer/proto/kinfer_pb2.py +0 -103
  26. kinfer/proto/kinfer_pb2.pyi +0 -1097
  27. kinfer/requirements-dev.txt +0 -8
  28. kinfer/rust/build.rs +0 -16
  29. kinfer/rust/src/kinfer_proto.rs +0 -14
  30. kinfer/rust/src/main.rs +0 -6
  31. kinfer/rust/src/onnx_serializer.rs +0 -804
  32. kinfer/rust/src/serializer.rs +0 -221
  33. kinfer/rust/src/tests/onnx_serializer_tests.rs +0 -212
  34. kinfer/serialize/__init__.py +0 -60
  35. kinfer/serialize/base.py +0 -536
  36. kinfer/serialize/json.py +0 -399
  37. kinfer/serialize/numpy.py +0 -426
  38. kinfer/serialize/pytorch.py +0 -402
  39. kinfer/serialize/schema.py +0 -125
  40. kinfer/serialize/types.py +0 -17
  41. kinfer/serialize/utils.py +0 -177
  42. kinfer-0.3.3.dist-info/METADATA +0 -57
  43. kinfer-0.3.3.dist-info/RECORD +0 -40
  44. {kinfer-0.3.3.dist-info → kinfer-0.4.0.dist-info/licenses}/LICENSE +0 -0
  45. {kinfer-0.3.3.dist-info → kinfer-0.4.0.dist-info}/top_level.txt +0 -0
kinfer/serialize/base.py DELETED
@@ -1,536 +0,0 @@
1
- """Defines functions for serializing and deserializing signatures."""
2
-
3
- from abc import ABC, abstractmethod
4
- from typing import Generic, Literal, Sequence, TypeVar, overload
5
-
6
- from kinfer import proto as K
7
-
8
- T = TypeVar("T")
9
-
10
-
11
- class JointPositionsSerializer(ABC, Generic[T]):
12
- @abstractmethod
13
- def serialize_joint_positions(
14
- self: "JointPositionsSerializer[T]",
15
- schema: K.JointPositionsSchema,
16
- value: K.JointPositionsValue,
17
- ) -> T:
18
- """Serialize a joint positions value.
19
-
20
- Args:
21
- schema: The schema of the joint positions.
22
- value: The joint positions to serialize.
23
-
24
- Returns:
25
- The serialized joint positions.
26
- """
27
-
28
- @abstractmethod
29
- def deserialize_joint_positions(
30
- self: "JointPositionsSerializer[T]",
31
- schema: K.JointPositionsSchema,
32
- value: T,
33
- ) -> K.JointPositionsValue:
34
- """Deserialize a joint positions value.
35
-
36
- Args:
37
- schema: The schema of the joint positions.
38
- value: The serialized joint positions.
39
- radians: Whether the serialized joint positions are radians.
40
-
41
- Returns:
42
- The deserialized joint positions.
43
- """
44
-
45
-
46
- class JointVelocitiesSerializer(ABC, Generic[T]):
47
- @abstractmethod
48
- def serialize_joint_velocities(
49
- self: "JointVelocitiesSerializer[T]",
50
- schema: K.JointVelocitiesSchema,
51
- value: K.JointVelocitiesValue,
52
- ) -> T:
53
- """Serialize a joint velocities value.
54
-
55
- Args:
56
- schema: The schema of the joint velocities.
57
- value: The joint velocities to serialize.
58
-
59
- Returns:
60
- The serialized joint velocities.
61
- """
62
-
63
- @abstractmethod
64
- def deserialize_joint_velocities(
65
- self: "JointVelocitiesSerializer[T]",
66
- schema: K.JointVelocitiesSchema,
67
- value: T,
68
- ) -> K.JointVelocitiesValue:
69
- """Deserialize a joint velocities value.
70
-
71
- Args:
72
- schema: The schema of the joint velocities.
73
- value: The serialized joint velocities.
74
-
75
- Returns:
76
- The deserialized joint velocities.
77
- """
78
-
79
-
80
- class JointTorquesSerializer(ABC, Generic[T]):
81
- @abstractmethod
82
- def serialize_joint_torques(
83
- self: "JointTorquesSerializer[T]",
84
- schema: K.JointTorquesSchema,
85
- value: K.JointTorquesValue,
86
- ) -> T:
87
- """Serialize a joint torques value.
88
-
89
- Args:
90
- schema: The schema of the joint torques.
91
- value: The joint torques to serialize.
92
-
93
- Returns:
94
- The serialized joint torques.
95
- """
96
-
97
- @abstractmethod
98
- def deserialize_joint_torques(
99
- self: "JointTorquesSerializer[T]",
100
- schema: K.JointTorquesSchema,
101
- value: T,
102
- ) -> K.JointTorquesValue:
103
- """Deserialize a joint torques value.
104
-
105
- Args:
106
- schema: The schema of the joint torques.
107
- value: The serialized joint torques.
108
-
109
- Returns:
110
- The deserialized joint torques.
111
- """
112
-
113
-
114
- class JointCommandsSerializer(ABC, Generic[T]):
115
- @abstractmethod
116
- def serialize_joint_commands(
117
- self: "JointCommandsSerializer[T]",
118
- schema: K.JointCommandsSchema,
119
- value: K.JointCommandsValue,
120
- ) -> T:
121
- """Serialize a joint commands value.
122
-
123
- Args:
124
- schema: The schema of the joint commands.
125
- value: The joint commands to serialize.
126
-
127
- Returns:
128
- The serialized joint commands.
129
- """
130
-
131
- @abstractmethod
132
- def deserialize_joint_commands(
133
- self: "JointCommandsSerializer[T]",
134
- schema: K.JointCommandsSchema,
135
- value: T,
136
- ) -> K.JointCommandsValue:
137
- """Deserialize a joint commands value.
138
-
139
- Args:
140
- schema: The schema of the joint commands.
141
- value: The serialized joint commands.
142
-
143
- Returns:
144
- The deserialized joint commands.
145
- """
146
-
147
-
148
- class CameraFrameSerializer(ABC, Generic[T]):
149
- @abstractmethod
150
- def serialize_camera_frame(
151
- self: "CameraFrameSerializer[T]",
152
- schema: K.CameraFrameSchema,
153
- value: K.CameraFrameValue,
154
- ) -> T:
155
- """Serialize a camera frame value.
156
-
157
- Args:
158
- schema: The schema of the camera frame.
159
- value: The frame of camera to serialize.
160
-
161
- Returns:
162
- The serialized camera frame.
163
- """
164
-
165
- @abstractmethod
166
- def deserialize_camera_frame(
167
- self: "CameraFrameSerializer[T]",
168
- schema: K.CameraFrameSchema,
169
- value: T,
170
- ) -> K.CameraFrameValue:
171
- """Deserialize a camera frame value.
172
-
173
- Args:
174
- schema: The schema of the camera frame.
175
- value: The serialized camera frame.
176
-
177
- Returns:
178
- The deserialized camera frame.
179
- """
180
-
181
-
182
- class AudioFrameSerializer(ABC, Generic[T]):
183
- @abstractmethod
184
- def serialize_audio_frame(
185
- self: "AudioFrameSerializer[T]",
186
- schema: K.AudioFrameSchema,
187
- value: K.AudioFrameValue,
188
- ) -> T:
189
- """Serialize an audio frame value.
190
-
191
- Args:
192
- schema: The schema of the audio frame.
193
- value: The frame of audio to serialize.
194
-
195
- Returns:
196
- The serialized audio frame.
197
- """
198
-
199
- @abstractmethod
200
- def deserialize_audio_frame(
201
- self: "AudioFrameSerializer[T]",
202
- schema: K.AudioFrameSchema,
203
- value: T,
204
- ) -> K.AudioFrameValue:
205
- """Deserialize an audio frame value.
206
-
207
- Args:
208
- schema: The schema of the audio frame.
209
- value: The serialized audio frame.
210
-
211
- Returns:
212
- The deserialized audio frame.
213
- """
214
-
215
-
216
- class ImuSerializer(ABC, Generic[T]):
217
- @abstractmethod
218
- def serialize_imu(
219
- self: "ImuSerializer[T]",
220
- schema: K.ImuSchema,
221
- value: K.ImuValue,
222
- ) -> T:
223
- """Serialize an IMU value.
224
-
225
- Args:
226
- schema: The schema of the IMU.
227
- value: The IMU to serialize.
228
-
229
- Returns:
230
- The serialized IMU.
231
- """
232
-
233
- @abstractmethod
234
- def deserialize_imu(
235
- self: "ImuSerializer[T]",
236
- schema: K.ImuSchema,
237
- value: T,
238
- ) -> K.ImuValue:
239
- """Deserialize an IMU value.
240
-
241
- Args:
242
- schema: The schema of the IMU.
243
- value: The serialized IMU.
244
-
245
- Returns:
246
- The deserialized IMU.
247
- """
248
-
249
-
250
- class TimestampSerializer(ABC, Generic[T]):
251
- @abstractmethod
252
- def serialize_timestamp(
253
- self: "TimestampSerializer[T]",
254
- schema: K.TimestampSchema,
255
- value: K.TimestampValue,
256
- ) -> T:
257
- """Serialize a timestamp value.
258
-
259
- Args:
260
- schema: The schema of the timestamp.
261
- value: The timestamp to serialize.
262
-
263
- Returns:
264
- The serialized timestamp.
265
- """
266
-
267
- @abstractmethod
268
- def deserialize_timestamp(
269
- self: "TimestampSerializer[T]",
270
- schema: K.TimestampSchema,
271
- value: T,
272
- ) -> K.TimestampValue:
273
- """Deserialize a timestamp value.
274
-
275
- Args:
276
- schema: The schema of the timestamp.
277
- value: The serialized timestamp.
278
-
279
- Returns:
280
- The deserialized timestamp.
281
- """
282
-
283
-
284
- class VectorCommandSerializer(ABC, Generic[T]):
285
- @abstractmethod
286
- def serialize_vector_command(
287
- self: "VectorCommandSerializer[T]",
288
- schema: K.VectorCommandSchema,
289
- value: K.VectorCommandValue,
290
- ) -> T:
291
- """Serialize an XY command value.
292
-
293
- Args:
294
- schema: The schema of the vector command.
295
- value: The vector command to serialize.
296
-
297
- Returns:
298
- The serialized vector command.
299
- """
300
-
301
- @abstractmethod
302
- def deserialize_vector_command(
303
- self: "VectorCommandSerializer[T]",
304
- schema: K.VectorCommandSchema,
305
- value: T,
306
- ) -> K.VectorCommandValue:
307
- """Deserialize a vector command value.
308
-
309
- Args:
310
- schema: The schema of the vector command.
311
- value: The serialized vector command.
312
-
313
- Returns:
314
- The deserialized vector command.
315
- """
316
-
317
-
318
- class StateTensorSerializer(ABC, Generic[T]):
319
- @abstractmethod
320
- def serialize_state_tensor(
321
- self: "StateTensorSerializer[T]",
322
- schema: K.StateTensorSchema,
323
- value: K.StateTensorValue,
324
- ) -> T:
325
- """Serialize a state tensor value.
326
-
327
- Args:
328
- schema: The schema of the state.
329
- value: The state to serialize.
330
-
331
- Returns:
332
- The serialized state.
333
- """
334
-
335
- @abstractmethod
336
- def deserialize_state_tensor(
337
- self: "StateTensorSerializer[T]",
338
- schema: K.StateTensorSchema,
339
- value: T,
340
- ) -> K.StateTensorValue:
341
- """Deserialize a state tensor value.
342
-
343
- Args:
344
- schema: The schema of the state.
345
- value: The serialized state.
346
-
347
- Returns:
348
- The deserialized state.
349
- """
350
-
351
-
352
- class Serializer(
353
- JointPositionsSerializer[T],
354
- JointVelocitiesSerializer[T],
355
- JointTorquesSerializer[T],
356
- JointCommandsSerializer[T],
357
- CameraFrameSerializer[T],
358
- AudioFrameSerializer[T],
359
- ImuSerializer[T],
360
- TimestampSerializer[T],
361
- VectorCommandSerializer[T],
362
- StateTensorSerializer[T],
363
- Generic[T],
364
- ):
365
- def __init__(self: "Serializer[T]", schema: K.ValueSchema) -> None:
366
- self.schema = schema
367
-
368
- def serialize(self: "Serializer[T]", value: K.Value) -> T:
369
- value_type = value.WhichOneof("value")
370
-
371
- match value_type:
372
- case "joint_positions":
373
- return self.serialize_joint_positions(
374
- schema=self.schema.joint_positions,
375
- value=value.joint_positions,
376
- )
377
- case "joint_velocities":
378
- return self.serialize_joint_velocities(
379
- schema=self.schema.joint_velocities,
380
- value=value.joint_velocities,
381
- )
382
- case "joint_torques":
383
- return self.serialize_joint_torques(
384
- schema=self.schema.joint_torques,
385
- value=value.joint_torques,
386
- )
387
- case "joint_commands":
388
- return self.serialize_joint_commands(
389
- schema=self.schema.joint_commands,
390
- value=value.joint_commands,
391
- )
392
- case "camera_frame":
393
- return self.serialize_camera_frame(
394
- schema=self.schema.camera_frame,
395
- value=value.camera_frame,
396
- )
397
- case "audio_frame":
398
- return self.serialize_audio_frame(
399
- schema=self.schema.audio_frame,
400
- value=value.audio_frame,
401
- )
402
- case "imu":
403
- return self.serialize_imu(
404
- schema=self.schema.imu,
405
- value=value.imu,
406
- )
407
- case "timestamp":
408
- return self.serialize_timestamp(
409
- schema=self.schema.timestamp,
410
- value=value.timestamp,
411
- )
412
- case "vector_command":
413
- return self.serialize_vector_command(
414
- schema=self.schema.vector_command,
415
- value=value.vector_command,
416
- )
417
- case "state_tensor":
418
- return self.serialize_state_tensor(
419
- schema=self.schema.state_tensor,
420
- value=value.state_tensor,
421
- )
422
- case _:
423
- raise ValueError(f"Unsupported value type: {value_type}")
424
-
425
- def deserialize(self: "Serializer[T]", value: T) -> K.Value:
426
- value_type = self.schema.WhichOneof("value_type")
427
-
428
- match value_type:
429
- case "joint_positions":
430
- return K.Value(
431
- joint_positions=self.deserialize_joint_positions(
432
- schema=self.schema.joint_positions,
433
- value=value,
434
- ),
435
- )
436
- case "joint_velocities":
437
- return K.Value(
438
- joint_velocities=self.deserialize_joint_velocities(
439
- schema=self.schema.joint_velocities,
440
- value=value,
441
- ),
442
- )
443
- case "joint_torques":
444
- return K.Value(
445
- joint_torques=self.deserialize_joint_torques(
446
- schema=self.schema.joint_torques,
447
- value=value,
448
- ),
449
- )
450
- case "joint_commands":
451
- return K.Value(
452
- joint_commands=self.deserialize_joint_commands(
453
- schema=self.schema.joint_commands,
454
- value=value,
455
- ),
456
- )
457
- case "camera_frame":
458
- return K.Value(
459
- camera_frame=self.deserialize_camera_frame(
460
- schema=self.schema.camera_frame,
461
- value=value,
462
- ),
463
- )
464
- case "audio_frame":
465
- return K.Value(
466
- audio_frame=self.deserialize_audio_frame(
467
- schema=self.schema.audio_frame,
468
- value=value,
469
- ),
470
- )
471
- case "imu":
472
- return K.Value(
473
- imu=self.deserialize_imu(
474
- schema=self.schema.imu,
475
- value=value,
476
- ),
477
- )
478
- case "timestamp":
479
- return K.Value(
480
- timestamp=self.deserialize_timestamp(
481
- schema=self.schema.timestamp,
482
- value=value,
483
- ),
484
- )
485
- case "vector_command":
486
- return K.Value(
487
- vector_command=self.deserialize_vector_command(
488
- schema=self.schema.vector_command,
489
- value=value,
490
- ),
491
- )
492
- case "state_tensor":
493
- return K.Value(
494
- state_tensor=self.deserialize_state_tensor(
495
- schema=self.schema.state_tensor,
496
- value=value,
497
- ),
498
- )
499
- case _:
500
- raise ValueError(f"Unsupported value type: {value_type}")
501
-
502
-
503
- class MultiSerializer(Generic[T]):
504
- def __init__(self: "MultiSerializer[T]", serializers: Sequence[Serializer[T]]) -> None:
505
- self.serializers = list(serializers)
506
-
507
- @overload
508
- def serialize_io(self: "MultiSerializer[T]", io: K.IO, *, as_dict: Literal[True]) -> dict[str, T]: ...
509
-
510
- @overload
511
- def serialize_io(self: "MultiSerializer[T]", io: K.IO, *, as_dict: Literal[False] = False) -> list[T]: ...
512
-
513
- def serialize_io(self: "MultiSerializer[T]", io: K.IO, *, as_dict: bool = False) -> dict[str, T] | list[T]:
514
- if not isinstance(io, K.IO):
515
- raise ValueError(f"Inputs must be an IO protobuf, not {type(io)}")
516
- if as_dict:
517
- return {s.schema.value_name: s.serialize(i) for s, i in zip(self.serializers, io.values)}
518
- return [s.serialize(i) for s, i in zip(self.serializers, io.values)]
519
-
520
- def deserialize_io(self: "MultiSerializer[T]", io: dict[str, T] | list[T]) -> K.IO:
521
- if not isinstance(io, (dict, list)):
522
- raise ValueError(f"Inputs must be a dictionary or list, not {type(io)}")
523
- if isinstance(io, dict):
524
- return K.IO(values=[s.deserialize(i) for s, i in zip(self.serializers, io.values())])
525
- return K.IO(values=[s.deserialize(i) for s, i in zip(self.serializers, io)])
526
-
527
- def assign_names(self: "MultiSerializer[T]", values: Sequence[T]) -> dict[str, T]:
528
- if not isinstance(values, Sequence):
529
- raise ValueError(f"Values must be a sequence, not {type(values)}")
530
- if len(values) != len(self.serializers):
531
- raise ValueError(f"Expected {len(self.serializers)} values, got {len(values)}")
532
- return {s.schema.value_name: v for s, v in zip(self.serializers, values)}
533
-
534
- @property
535
- def names(self: "MultiSerializer[T]") -> list[str]:
536
- return [s.schema.value_name for s in self.serializers]