Are hyperparameter types lost because of this?
In scikit-byom (and none of the other APIs), this is giving me some headaches. Say, if I write hyperparameter = {'a':False}, the code converts it to {'a':'False'} and then my training script interprets it as a=True.
I was quite confused why such conversions must happen. If so in certain scenarios, could it be better documented? What are the recommended deserialization steps?
Thanks.
https://github.com/aws/sagemaker-python-sdk/blob/235e5c51c1f023f725e470142fa630c2c5db7720/src/sagemaker/amazon/hyperparameter.py#L66
https://github.com/aws/sagemaker-python-sdk/blob/c3095d5a8763f844fb32014e77294fa10b99fbae/src/sagemaker/amazon/amazon_estimator.py#L57
When I was beginning with sagemaker I had some hiccups with the hyperparameters too. Always remember that the hyperparameters are passed via json and in json False is written as 'false'. 'False' on the other hand is then interpreted as a normal string which gives you a True when converting it back to bool.
In my opinion there are two best practises for this:
- Define everything directly in json:
{'a':'false'} - Dump all entries in json format yourself:
{'a': json.dumps(False)}
Thanks — did you mean that each value is a json dump, not the entire hyperparameter dictionary? That might be an explanation.
Btw, the code is written incorrectly anyways. It calls “str” on the value and we may not correctly recover from it.
Maybe the codes are correct -- if I want to support both typed and untyped values, then calling str seems to be the only solution. Closing out this ticket and thanks for the explanations!