@@ -102,38 +102,38 @@ def check_tensors(
102102 if isinstance (in_out_list , (list , tuple )):
103103 assert len (in_out_list ) > 0 , f"{ name } cannot be empty"
104104 for each_var in in_out_list :
105- assert isinstance (
106- each_var , paddle .Tensor
107- ), f"Elements of { name } must be paddle.Tensor"
105+ assert isinstance (each_var , paddle . Tensor ), (
106+ f"Elements of { name } must be paddle.Tensor"
107+ )
108108 return in_out_list
109109 else :
110- assert isinstance (
111- in_out_list , paddle . Tensor
112- ), f" { name } must be Tensor or list of Tensor"
110+ assert isinstance (in_out_list , paddle . Tensor ), (
111+ f" { name } must be Tensor or list of Tensor"
112+ )
113113 return [in_out_list ]
114114
115115 tensors = check_tensors (tensors , "tensors" )
116116
117- assert len (tensors ) == len (
118- set ( tensors )
119- ), "The argument 'tensors' of paddle.autograd.backward contains duplicate paddle.Tensor object."
117+ assert len (tensors ) == len (set ( tensors )), (
118+ "The argument ' tensors' of paddle.autograd.backward contains duplicate paddle.Tensor object."
119+ )
120120
121121 if grad_tensors is not None :
122122 if not isinstance (grad_tensors , (list , tuple )):
123123 grad_tensors = [grad_tensors ]
124124
125125 for each_tensor in grad_tensors :
126126 if each_tensor is not None :
127- assert isinstance (
128- each_tensor , paddle .Tensor
129- ), "The argument 'grad_tensors' of paddle.autograd.backward is invalid, it can be 'None', 'paddle.Tensor' or 'list[None/paddle.Tensor]'."
127+ assert isinstance (each_tensor , paddle . Tensor ), (
128+ "The argument 'grad_tensors' of paddle.autograd.backward is invalid, it can be 'None', ' paddle.Tensor' or 'list[None/paddle.Tensor]'."
129+ )
130130 else :
131131 grad_tensors = []
132132
133133 if len (grad_tensors ) > 0 :
134- assert len (tensors ) == len (
135- grad_tensors
136- ), "The length of grad_tensors must be equal to tensors"
134+ assert len (tensors ) == len (grad_tensors ), (
135+ "The length of grad_tensors must be equal to tensors"
136+ )
137137
138138 assert isinstance (retain_graph , bool ), "retain_graph must be True or False"
139139
0 commit comments