opengradient 0.4.12__py3-none-any.whl → 0.4.13__py3-none-any.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.
- opengradient/client.py +53 -5
- opengradient/utils.py +5 -14
- {opengradient-0.4.12.dist-info → opengradient-0.4.13.dist-info}/METADATA +1 -1
- {opengradient-0.4.12.dist-info → opengradient-0.4.13.dist-info}/RECORD +8 -8
- {opengradient-0.4.12.dist-info → opengradient-0.4.13.dist-info}/WHEEL +0 -0
- {opengradient-0.4.12.dist-info → opengradient-0.4.13.dist-info}/entry_points.txt +0 -0
- {opengradient-0.4.12.dist-info → opengradient-0.4.13.dist-info}/licenses/LICENSE +0 -0
- {opengradient-0.4.12.dist-info → opengradient-0.4.13.dist-info}/top_level.txt +0 -0
opengradient/client.py
CHANGED
|
@@ -2,6 +2,7 @@ import json
|
|
|
2
2
|
import logging
|
|
3
3
|
import os
|
|
4
4
|
import time
|
|
5
|
+
import base64
|
|
5
6
|
from pathlib import Path
|
|
6
7
|
from typing import Any, Dict, List, Optional, Union, Callable
|
|
7
8
|
|
|
@@ -318,8 +319,8 @@ class Client:
|
|
|
318
319
|
# check inference directly from node
|
|
319
320
|
parsed_logs = precompile_contract.events.ModelInferenceEvent().process_receipt(tx_receipt, errors=DISCARD)
|
|
320
321
|
inference_id = parsed_logs[0]["args"]["inferenceID"]
|
|
321
|
-
inference_result = self.
|
|
322
|
-
model_output = inference_result
|
|
322
|
+
inference_result = self._get_inference_result_from_node(inference_id, inference_mode)
|
|
323
|
+
model_output = convert_to_model_output(inference_result)
|
|
323
324
|
|
|
324
325
|
return InferenceResult(tx_hash.hex(), model_output)
|
|
325
326
|
|
|
@@ -971,7 +972,7 @@ class Client:
|
|
|
971
972
|
return [convert_array_to_model_output(result) for result in results]
|
|
972
973
|
|
|
973
974
|
|
|
974
|
-
def
|
|
975
|
+
def _get_inference_result_from_node(self, inference_id: str, inference_mode: InferenceMode) -> Dict:
|
|
975
976
|
"""
|
|
976
977
|
Get the inference result from node.
|
|
977
978
|
|
|
@@ -979,7 +980,7 @@ class Client:
|
|
|
979
980
|
inference_id (str): Inference id for a inference request
|
|
980
981
|
|
|
981
982
|
Returns:
|
|
982
|
-
|
|
983
|
+
Dict: The inference result as returned by the node
|
|
983
984
|
|
|
984
985
|
Raises:
|
|
985
986
|
OpenGradientError: If the request fails or returns an error
|
|
@@ -990,7 +991,54 @@ class Client:
|
|
|
990
991
|
|
|
991
992
|
response = requests.get(url)
|
|
992
993
|
if response.status_code == 200:
|
|
993
|
-
|
|
994
|
+
resp = response.json()
|
|
995
|
+
inference_result = resp.get("inference_results", {})
|
|
996
|
+
if inference_result:
|
|
997
|
+
decoded_bytes = base64.b64decode(inference_result[0])
|
|
998
|
+
decoded_string = decoded_bytes.decode('utf-8')
|
|
999
|
+
output = json.loads(decoded_string).get("InferenceResult",{})
|
|
1000
|
+
if output is None:
|
|
1001
|
+
raise OpenGradientError("Missing InferenceResult in inference output")
|
|
1002
|
+
|
|
1003
|
+
match inference_mode:
|
|
1004
|
+
case InferenceMode.VANILLA:
|
|
1005
|
+
if "VanillaResult" not in output:
|
|
1006
|
+
raise OpenGradientError("Missing VanillaResult in inference output")
|
|
1007
|
+
if "model_output" not in output["VanillaResult"]:
|
|
1008
|
+
raise OpenGradientError("Missing model_output in VanillaResult")
|
|
1009
|
+
return {
|
|
1010
|
+
"output": output["VanillaResult"]["model_output"]
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
case InferenceMode.TEE:
|
|
1014
|
+
if "TeeNodeResult" not in output:
|
|
1015
|
+
raise OpenGradientError("Missing TeeNodeResult in inference output")
|
|
1016
|
+
if "Response" not in output["TeeNodeResult"]:
|
|
1017
|
+
raise OpenGradientError("Missing Response in TeeNodeResult")
|
|
1018
|
+
if "VanillaResponse" in output["TeeNodeResult"]["Response"]:
|
|
1019
|
+
if "model_output" not in output["TeeNodeResult"]["Response"]["VanillaResponse"]:
|
|
1020
|
+
raise OpenGradientError("Missing model_output in VanillaResponse")
|
|
1021
|
+
return {
|
|
1022
|
+
"output": output["TeeNodeResult"]["Response"]["VanillaResponse"]["model_output"]
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
else:
|
|
1026
|
+
raise OpenGradientError("Missing VanillaResponse in TeeNodeResult Response")
|
|
1027
|
+
|
|
1028
|
+
case InferenceMode.ZKML:
|
|
1029
|
+
if "ZkmlResult" not in output:
|
|
1030
|
+
raise OpenGradientError("Missing ZkmlResult in inference output")
|
|
1031
|
+
if "model_output" not in output["ZkmlResult"]:
|
|
1032
|
+
raise OpenGradientError("Missing model_output in ZkmlResult")
|
|
1033
|
+
return {
|
|
1034
|
+
"output": output["ZkmlResult"]["model_output"]
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
case _:
|
|
1038
|
+
raise OpenGradientError(f"Invalid inference mode: {inference_mode}")
|
|
1039
|
+
else:
|
|
1040
|
+
return None
|
|
1041
|
+
|
|
994
1042
|
else:
|
|
995
1043
|
error_message = f"Failed to get inference result: HTTP {response.status_code}"
|
|
996
1044
|
if response.text:
|
opengradient/utils.py
CHANGED
|
@@ -122,24 +122,18 @@ def convert_to_model_output(event_data: AttributeDict) -> Dict[str, np.ndarray]:
|
|
|
122
122
|
We need to reshape each output array using the shape parameter in order to get the array
|
|
123
123
|
back into its original shape.
|
|
124
124
|
"""
|
|
125
|
-
logging.debug(f"Parsing event data: {event_data}")
|
|
126
|
-
|
|
127
125
|
output_dict = {}
|
|
128
|
-
|
|
129
126
|
output = event_data.get("output", {})
|
|
130
|
-
logging.debug(f"Output data: {output}")
|
|
131
127
|
|
|
132
|
-
if isinstance(output, AttributeDict):
|
|
133
|
-
# Parse numbers
|
|
128
|
+
if isinstance(output, (AttributeDict, dict)):
|
|
134
129
|
for tensor in output.get("numbers", []):
|
|
135
|
-
|
|
136
|
-
if isinstance(tensor, AttributeDict):
|
|
130
|
+
if isinstance(tensor, (AttributeDict, dict)):
|
|
137
131
|
name = tensor.get("name")
|
|
138
132
|
shape = tensor.get("shape")
|
|
139
133
|
values = []
|
|
140
134
|
# Convert from fixed point back into np.float32
|
|
141
135
|
for v in tensor.get("values", []):
|
|
142
|
-
if isinstance(v, AttributeDict):
|
|
136
|
+
if isinstance(v, (AttributeDict, dict)):
|
|
143
137
|
values.append(convert_to_float32(value=int(v.get("value")), decimals=int(v.get("decimals"))))
|
|
144
138
|
else:
|
|
145
139
|
logging.warning(f"Unexpected number type: {type(v)}")
|
|
@@ -149,8 +143,7 @@ def convert_to_model_output(event_data: AttributeDict) -> Dict[str, np.ndarray]:
|
|
|
149
143
|
|
|
150
144
|
# Parse strings
|
|
151
145
|
for tensor in output.get("strings", []):
|
|
152
|
-
|
|
153
|
-
if isinstance(tensor, AttributeDict):
|
|
146
|
+
if isinstance(tensor, (AttributeDict, dict)):
|
|
154
147
|
name = tensor.get("name")
|
|
155
148
|
shape = tensor.get("shape")
|
|
156
149
|
values = tensor.get("values", [])
|
|
@@ -160,8 +153,7 @@ def convert_to_model_output(event_data: AttributeDict) -> Dict[str, np.ndarray]:
|
|
|
160
153
|
|
|
161
154
|
# Parse JSON dicts
|
|
162
155
|
for tensor in output.get("jsons", []):
|
|
163
|
-
|
|
164
|
-
if isinstance(tensor, AttributeDict):
|
|
156
|
+
if isinstance(tensor, (AttributeDict, dict)):
|
|
165
157
|
name = tensor.get("name")
|
|
166
158
|
value = tensor.get("value")
|
|
167
159
|
output_dict[name] = np.array(json.loads(value))
|
|
@@ -172,7 +164,6 @@ def convert_to_model_output(event_data: AttributeDict) -> Dict[str, np.ndarray]:
|
|
|
172
164
|
logging.warning(f"Unexpected output type: {type(output)}")
|
|
173
165
|
|
|
174
166
|
logging.debug(f"Parsed output: {output_dict}")
|
|
175
|
-
|
|
176
167
|
return output_dict
|
|
177
168
|
|
|
178
169
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
opengradient/__init__.py,sha256=hFvN9sCEIQGWjT4Qnel6oQjadgAhDXMti72tdrP3sIo,12611
|
|
2
2
|
opengradient/account.py,sha256=5wrYpws_1lozjOFjLCTHtxgoxK-LmObDAaVy9eDcJY4,1145
|
|
3
3
|
opengradient/cli.py,sha256=dSIX6ieOh8ql9GdtE-mn_exSQFywh7Os0rt1ZRoHROk,25488
|
|
4
|
-
opengradient/client.py,sha256=
|
|
4
|
+
opengradient/client.py,sha256=b8JUJ2NH2Qq6gBwoh1qV70-ZupTrjXu21eUQWoKQlvg,48701
|
|
5
5
|
opengradient/defaults.py,sha256=IRk9aWFgctSKEQrF4Gm_D07AFy2dHCa3rKsMf0BYAls,552
|
|
6
6
|
opengradient/exceptions.py,sha256=88tfegboGtlehQcwhxsl6ZzhLJWZWlkf_bkHTiCtXpo,3391
|
|
7
7
|
opengradient/types.py,sha256=JH8hjpcq4H7gQki74cuJpH4PcyQpwivLiqn9iq0evrI,5715
|
|
8
|
-
opengradient/utils.py,sha256=
|
|
8
|
+
opengradient/utils.py,sha256=ZUq4OBIml2vsC0tRqus4Zwb_e3g4woo00apByrafuVw,8058
|
|
9
9
|
opengradient/abi/InferencePrecompile.abi,sha256=reepTHg6Q01UrFP0Gexc-JayplsvOLPfG7jrEZ-cV28,10197
|
|
10
10
|
opengradient/abi/PriceHistoryInference.abi,sha256=ZB3fZdx1kaFlp2wt1vTbTZZG1k8HPvmNtkG5Q8Bnajw,5098
|
|
11
11
|
opengradient/abi/WorkflowScheduler.abi,sha256=yEGs76qO4S1z980KL5hBdfyXiJ6k-kERcB1O_o73AEU,416
|
|
@@ -27,9 +27,9 @@ opengradient/workflow_models/constants.py,sha256=viIkb_LGcfVprqQNaA80gBTj6cfYam0
|
|
|
27
27
|
opengradient/workflow_models/types.py,sha256=Z22hF6c8Y4D2GlzVEIBODGwsqSjSrQvUcpZ7R-mIJdI,409
|
|
28
28
|
opengradient/workflow_models/utils.py,sha256=ySfpuiOBqLTlfto6ZxZf2vc7K6RGIja0l4eaVm5AOzY,1503
|
|
29
29
|
opengradient/workflow_models/workflow_models.py,sha256=d4C_gs39DAfy4cdY9Ee6GMXpPfzwvKFpmxzK1A7LNgU,3900
|
|
30
|
-
opengradient-0.4.
|
|
31
|
-
opengradient-0.4.
|
|
32
|
-
opengradient-0.4.
|
|
33
|
-
opengradient-0.4.
|
|
34
|
-
opengradient-0.4.
|
|
35
|
-
opengradient-0.4.
|
|
30
|
+
opengradient-0.4.13.dist-info/licenses/LICENSE,sha256=xEcvQ3AxZOtDkrqkys2Mm6Y9diEnaSeQRKvxi-JGnNA,1069
|
|
31
|
+
opengradient-0.4.13.dist-info/METADATA,sha256=Kr7GXWGbmBa9YlTImIaO5AeIqW6XYj3BEJEjJuo9i_4,5237
|
|
32
|
+
opengradient-0.4.13.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
33
|
+
opengradient-0.4.13.dist-info/entry_points.txt,sha256=yUKTaJx8RXnybkob0J62wVBiCp_1agVbgw9uzsmaeJc,54
|
|
34
|
+
opengradient-0.4.13.dist-info/top_level.txt,sha256=oC1zimVLa2Yi1LQz8c7x-0IQm92milb5ax8gHBHwDqU,13
|
|
35
|
+
opengradient-0.4.13.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|