Revise error message for invalid Reduction (#22160)

Summary:
Say the user inputs reduction=False. Of course, we can't add a bool and a string, so the ValueError itself will error -which is more confusing to the user. Instead, we should use string formatting. I would use `f"{reduction} is not..."` but unsure whether we are ok with using f"" strings.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/22160

Differential Revision: D15981826

Pulled By: soumith

fbshipit-source-id: 279f34bb64a72578c36bdbabe2da83d2fa4b93d8
This commit is contained in:
Ashwinee Panda 2019-06-28 22:26:08 -07:00 committed by Facebook Github Bot
parent 9e18234109
commit b52621c870

View File

@ -18,7 +18,7 @@ def get_enum(reduction):
ret = 2
else:
ret = -1 # TODO: remove once JIT exceptions support control flow
raise ValueError(reduction + " is not a valid value for reduction")
raise ValueError("{} is not a valid value for reduction".format(reduction))
return ret
# In order to support previous versions, accept boolean size_average and reduce