From b52621c870562bbac229770678045a0a513c966b Mon Sep 17 00:00:00 2001 From: Ashwinee Panda Date: Fri, 28 Jun 2019 22:26:08 -0700 Subject: [PATCH] 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 --- torch/nn/_reduction.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torch/nn/_reduction.py b/torch/nn/_reduction.py index 5e7f5ad782d..cc84a9bca95 100644 --- a/torch/nn/_reduction.py +++ b/torch/nn/_reduction.py @@ -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