You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To Reproduce
The rest of the training code can be found on the above link. The code that perform the read mlflow model file is shown below:
## define randomforest model model=RandomForestClassifier(n_estimators=300).fit(x_train, y_train)
##Model signature defines schema of model input and outputsignature=infer_signature(x_train, model.predict(x_train))
## log model score to mlflowscore=model.score(x_test, y_test)
print("Score: %s"%score)
mlflow.log_metric("score", score)
### log model mlflow.sklearn.log_model(model, "model", signature=signature)
print("Model saved in run %s"%mlflow.active_run().info.run_uuid)
mlPath=Path(f'./mlruns/1/{mlflow.active_run().info.run_uuid}/artifacts/model')
## get info aboud model variables ,input and outputvarDict, inputsDict, outputsDict=pzmm.MLFlowModel.read_mlflow_model_file(mlPath)
Expected behavior
Getting the dictionary successfully from pzmm.MLFlowModel.read_mlflow_model_file().
Stack Trace
If you're experiencing an exception, include the full stack trace and error message.
---------------------------------------------------------------------------JSONDecodeErrorTraceback (mostrecentcalllast)
CellIn[4], line41mlPath=Path(f'./mlruns/1/{mlflow.active_run().info.run_uuid}/artifacts/model')
3## get info aboud model variables ,input and output---->4varDict, inputsDict, outputsDict=pzmm.MLFlowModel.read_mlflow_model_file(mlPath)
File~\AppData\Local\miniconda3\envs\ml\Lib\site-packages\sasctl\pzmm\mlflow_model.py:56, inMLFlowModel.read_mlflow_model_file(cls, m_path)
53outputs=m_lines[ind_out[0] : -1]
55inputs_dict=json.loads("".join([s.strip() forsininputs])[9:-1])
--->56outputs_dict=json.loads("".join([s.strip() forsinoutputs])[10:-1])
57else:
58raiseValueError(
59"Improper or unset signature values for model. No input or output "60"dicts could be generated. "61 )
File~\AppData\Local\miniconda3\envs\ml\Lib\json\__init__.py:346, inloads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
341s=s.decode(detect_encoding(s), 'surrogatepass')
343if (clsisNoneandobject_hookisNoneand344parse_intisNoneandparse_floatisNoneand345parse_constantisNoneandobject_pairs_hookisNoneandnotkw):
-->346return_default_decoder.decode(s)
347ifclsisNone:
348cls=JSONDecoderFile~\AppData\Local\miniconda3\envs\ml\Lib\json\decoder.py:340, inJSONDecoder.decode(self, s, _w)
338end=_w(s, end).end()
339ifend!=len(s):
-->340raiseJSONDecodeError("Extra data", s, end)
341returnobjJSONDecodeError: Extradata: line1column73 (char72)
Version
1.10.0
The text was updated successfully, but these errors were encountered:
The MLmodel file has an extra line params in the end like below. Since the code is parsing outputs until the end of line, this params is giving theJSONDecodeError: Extra data error. If I remove the params from the MLmodel. I could read the file just fine.
This seems to be a new specification from MLflow 2.6.0 when they add the "Inference params support". This would affect all MLmodel created since MLflow 2.6.0 release. mlflow/mlflow#9068
I believe this is the problematic line of code in sasctl, it assumes no other field after outputs and reads the whole line.
Perhaps a better solution is to parse the MLmodel file natively in YAML? Since it is apparently in YAML format. That way you can keep forward compatibility if MLflow decides to add another field. https://mlflow.org/docs/latest/models.html#id28
I'll stick with MLflow 2.5.0 for now, it seems to be working fine.
Describe the issue
Trying to read mlflow model using pzmm.MLFlowModel.read_mlflow_model_file result in JSONDecodeError. I'm just using a simple example from here:
https://medium.com/@rehabreda/registering-mlflow-models-to-sas-model-manager-using-sasctl-a-comprehensive-guide-a47dbf183338
To Reproduce
The rest of the training code can be found on the above link. The code that perform the read mlflow model file is shown below:
Expected behavior
Getting the dictionary successfully from pzmm.MLFlowModel.read_mlflow_model_file().
Stack Trace
If you're experiencing an exception, include the full stack trace and error message.
Version
1.10.0
The text was updated successfully, but these errors were encountered: