diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index c6a1c21891108f51ec284636f7e672ee678a9064..b6d089a9ab1672710983b091d106f47906c06395 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -355,9 +355,12 @@ def fc(input, "The type of 'input' in fc must be Variable, but received %s" % (type(input))) dtype = helper.input_dtype() - if convert_dtype(dtype) not in ['float32', 'float64']: + if convert_dtype(dtype) in ['float16']: + warnings.warn( + "The data type of 'input' in fc only support float16 in GPU now.") + if convert_dtype(dtype) not in ['float16', 'float32', 'float64']: raise TypeError( - "The data type of 'input' in fc must be float32 or float64, but received %s." + "The data type of 'input' in fc must be float16, float32 or float64, but received %s." % (convert_dtype(dtype))) mul_results = [] diff --git a/python/paddle/fluid/tests/unittests/test_fc_op.py b/python/paddle/fluid/tests/unittests/test_fc_op.py index e50579f76d65f1ab3e2f1ae230dc2a7aec58ea8c..0da0fd0789a770db20dd219273d5c21ec7572e29 100644 --- a/python/paddle/fluid/tests/unittests/test_fc_op.py +++ b/python/paddle/fluid/tests/unittests/test_fc_op.py @@ -148,6 +148,10 @@ class TestFCOpError(OpTest): self.assertRaises(TypeError, test_type) + # The input dtype of fc can be float16 in GPU, test for warning + x3 = fluid.layers.data(name='x3', shape=[4], dtype='float16') + fluid.layers.fc(input=x3, size=1) + if __name__ == "__main__": unittest.main()