diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 092b39111aa5d7ac2f71df9abd36fcbf9dba2cf6..4132618ab7b7db1b6f6575d2b9c4205706ffacfc 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()