sagemaker-python-sdk icon indicating copy to clipboard operation
sagemaker-python-sdk copied to clipboard

Are hyperparameter types lost because of this?

Open yifeim opened this issue 8 years ago • 3 comments

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

yifeim avatar Jul 18 '18 04:07 yifeim

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:

  1. Define everything directly in json: {'a':'false'}
  2. Dump all entries in json format yourself: {'a': json.dumps(False)}

dennis-ec avatar Jul 18 '18 11:07 dennis-ec

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.

yifeim avatar Jul 18 '18 16:07 yifeim

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!

yifeim avatar Jul 19 '18 00:07 yifeim