Skip to content

Commit

Permalink
Fix dropout accuracy by setting seed in forward function (#2933)
Browse files Browse the repository at this point in the history
* fix dropout accuracy by setting seed in forward function

* fix

* change seed to 33
  • Loading branch information
Hongqing-work authored Aug 28, 2024
1 parent 36ea86f commit e935f90
Show file tree
Hide file tree
Showing 75 changed files with 150 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def forward(
self,
var_0, # (shape: [86, 198, 192], dtype: paddle.float32, stop_gradient: False)
):
paddle.seed(33)
var_1 = paddle.nn.functional.norm.layer_norm(var_0, normalized_shape=[192], weight=self.parameter_0, bias=self.parameter_1, epsilon=1e-06)
var_2 = paddle.nn.functional.common.linear(x=var_1, weight=self.parameter_5, bias=self.parameter_3, name=None)
var_3 = var_2.reshape((-1, 198, 3, 3, 64,))
Expand Down Expand Up @@ -89,7 +90,7 @@ def train(self, net, to_static, with_prim=False, with_cinn=False):
net = paddle.jit.to_static(net, build_strategy=build_strategy, full_graph=True)
else:
net = paddle.jit.to_static(net, full_graph=True)
paddle.seed(123)
paddle.seed(33)
outs = net(*self.inputs)
return outs
def test_ast_prim_cinn(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def forward(
self,
var_0, # (shape: [54, 198, 192], dtype: paddle.float32, stop_gradient: False)
):
paddle.seed(33)
var_1 = paddle.nn.functional.norm.layer_norm(var_0, normalized_shape=[192], weight=self.parameter_3, bias=self.parameter_4, epsilon=1e-06)
var_2 = paddle.nn.functional.common.linear(x=var_1, weight=self.parameter_0, bias=self.parameter_5, name=None)
var_3 = var_2.reshape((-1, 198, 3, 3, 64,))
Expand Down Expand Up @@ -89,7 +90,7 @@ def train(self, net, to_static, with_prim=False, with_cinn=False):
net = paddle.jit.to_static(net, build_strategy=build_strategy, full_graph=True)
else:
net = paddle.jit.to_static(net, full_graph=True)
paddle.seed(123)
paddle.seed(33)
outs = net(*self.inputs)
return outs
def test_ast_prim_cinn(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def forward(
self,
var_0, # (shape: [86, 197, 192], dtype: paddle.float32, stop_gradient: False)
):
paddle.seed(33)
var_1 = paddle.nn.functional.norm.layer_norm(var_0, normalized_shape=[192], weight=self.parameter_1, bias=self.parameter_4, epsilon=1e-06)
var_2 = paddle.nn.functional.common.linear(x=var_1, weight=self.parameter_2, bias=self.parameter_0, name=None)
var_3 = var_2.reshape((-1, 197, 3, 3, 64,))
Expand Down Expand Up @@ -89,7 +90,7 @@ def train(self, net, to_static, with_prim=False, with_cinn=False):
net = paddle.jit.to_static(net, build_strategy=build_strategy, full_graph=True)
else:
net = paddle.jit.to_static(net, full_graph=True)
paddle.seed(123)
paddle.seed(33)
outs = net(*self.inputs)
return outs
def test_ast_prim_cinn(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def forward(
self,
var_0, # (shape: [54, 197, 192], dtype: paddle.float32, stop_gradient: False)
):
paddle.seed(33)
var_1 = paddle.nn.functional.norm.layer_norm(var_0, normalized_shape=[192], weight=self.parameter_4, bias=self.parameter_1, epsilon=1e-06)
var_2 = paddle.nn.functional.common.linear(x=var_1, weight=self.parameter_3, bias=self.parameter_2, name=None)
var_3 = var_2.reshape((-1, 197, 3, 3, 64,))
Expand Down Expand Up @@ -89,7 +90,7 @@ def train(self, net, to_static, with_prim=False, with_cinn=False):
net = paddle.jit.to_static(net, build_strategy=build_strategy, full_graph=True)
else:
net = paddle.jit.to_static(net, full_graph=True)
paddle.seed(123)
paddle.seed(33)
outs = net(*self.inputs)
return outs
def test_ast_prim_cinn(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def forward(
self,
var_0, # (shape: [11, 1280, 7, 7], dtype: paddle.float32, stop_gradient: False)
):
paddle.seed(33)
var_1 = paddle.nn.functional.pooling.adaptive_avg_pool2d(var_0, output_size=1, data_format='NCHW', name=None)
var_2 = paddle.nn.functional.common.dropout(var_1, p=0.2, axis=None, training=True, mode='upscale_in_train', name=None)
var_3 = paddle.tensor.manipulation.squeeze(var_2, axis=[2, 3])
Expand Down Expand Up @@ -60,7 +61,7 @@ def train(self, net, to_static, with_prim=False, with_cinn=False):
net = paddle.jit.to_static(net, build_strategy=build_strategy, full_graph=True)
else:
net = paddle.jit.to_static(net, full_graph=True)
paddle.seed(123)
paddle.seed(33)
outs = net(*self.inputs)
return outs
def test_ast_prim_cinn(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def forward(
self,
var_0, # (shape: [43, 1280, 7, 7], dtype: paddle.float32, stop_gradient: False)
):
paddle.seed(33)
var_1 = paddle.nn.functional.pooling.adaptive_avg_pool2d(var_0, output_size=1, data_format='NCHW', name=None)
var_2 = paddle.nn.functional.common.dropout(var_1, p=0.2, axis=None, training=True, mode='upscale_in_train', name=None)
var_3 = paddle.tensor.manipulation.squeeze(var_2, axis=[2, 3])
Expand Down Expand Up @@ -60,7 +61,7 @@ def train(self, net, to_static, with_prim=False, with_cinn=False):
net = paddle.jit.to_static(net, build_strategy=build_strategy, full_graph=True)
else:
net = paddle.jit.to_static(net, full_graph=True)
paddle.seed(123)
paddle.seed(33)
outs = net(*self.inputs)
return outs
def test_ast_prim_cinn(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def forward(
self,
var_0, # (shape: [22, 1536, 8, 8], dtype: paddle.float32, stop_gradient: False)
):
paddle.seed(33)
var_1 = paddle.nn.functional.pooling.adaptive_avg_pool2d(var_0, output_size=1, data_format='NCHW', name=None)
var_2 = paddle.tensor.manipulation.squeeze(var_1, axis=[2, 3])
var_3 = paddle.nn.functional.common.dropout(var_2, p=0.2, axis=None, training=True, mode='downscale_in_infer', name=None)
Expand Down Expand Up @@ -60,7 +61,7 @@ def train(self, net, to_static, with_prim=False, with_cinn=False):
net = paddle.jit.to_static(net, build_strategy=build_strategy, full_graph=True)
else:
net = paddle.jit.to_static(net, full_graph=True)
paddle.seed(123)
paddle.seed(33)
outs = net(*self.inputs)
return outs
def test_ast_prim_cinn(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def forward(
self,
var_0, # (shape: [10, 1536, 8, 8], dtype: paddle.float32, stop_gradient: False)
):
paddle.seed(33)
var_1 = paddle.nn.functional.pooling.adaptive_avg_pool2d(var_0, output_size=1, data_format='NCHW', name=None)
var_2 = paddle.tensor.manipulation.squeeze(var_1, axis=[2, 3])
var_3 = paddle.nn.functional.common.dropout(var_2, p=0.2, axis=None, training=True, mode='downscale_in_infer', name=None)
Expand Down Expand Up @@ -60,7 +61,7 @@ def train(self, net, to_static, with_prim=False, with_cinn=False):
net = paddle.jit.to_static(net, build_strategy=build_strategy, full_graph=True)
else:
net = paddle.jit.to_static(net, full_graph=True)
paddle.seed(123)
paddle.seed(33)
outs = net(*self.inputs)
return outs
def test_ast_prim_cinn(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def forward(
self,
var_0, # (shape: [43, 320, 8, 8], dtype: paddle.float32, stop_gradient: False)
):
paddle.seed(33)
var_1 = paddle.nn.functional.pooling.adaptive_avg_pool2d(var_0, output_size=1, data_format='NCHW', name=None)
var_2 = var_1.reshape([43, 320])
var_3 = paddle.nn.functional.common.dropout(var_2, p=0.1, axis=None, training=True, mode='upscale_in_train', name=None)
Expand Down Expand Up @@ -60,7 +61,7 @@ def train(self, net, to_static, with_prim=False, with_cinn=False):
net = paddle.jit.to_static(net, build_strategy=build_strategy, full_graph=True)
else:
net = paddle.jit.to_static(net, full_graph=True)
paddle.seed(123)
paddle.seed(33)
outs = net(*self.inputs)
return outs
def test_ast_prim_cinn(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def forward(
self,
var_0, # (shape: [11, 320, 8, 8], dtype: paddle.float32, stop_gradient: False)
):
paddle.seed(33)
var_1 = paddle.nn.functional.pooling.adaptive_avg_pool2d(var_0, output_size=1, data_format='NCHW', name=None)
var_2 = var_1.reshape([11, 320])
var_3 = paddle.nn.functional.common.dropout(var_2, p=0.1, axis=None, training=True, mode='upscale_in_train', name=None)
Expand Down Expand Up @@ -60,7 +61,7 @@ def train(self, net, to_static, with_prim=False, with_cinn=False):
net = paddle.jit.to_static(net, build_strategy=build_strategy, full_graph=True)
else:
net = paddle.jit.to_static(net, full_graph=True)
paddle.seed(123)
paddle.seed(33)
outs = net(*self.inputs)
return outs
def test_ast_prim_cinn(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def forward(
self,
var_0, # (shape: [43, 704, 7, 7], dtype: paddle.float32, stop_gradient: False)
):
paddle.seed(33)
var_1 = paddle.nn.functional.pooling.avg_pool2d(var_0, kernel_size=[7, 7])
var_2 = var_1.flatten(1)
var_3 = paddle.nn.functional.common.dropout(var_2, p=0.05, training=True)
Expand Down Expand Up @@ -60,7 +61,7 @@ def train(self, net, to_static, with_prim=False, with_cinn=False):
net = paddle.jit.to_static(net, build_strategy=build_strategy, full_graph=True)
else:
net = paddle.jit.to_static(net, full_graph=True)
paddle.seed(123)
paddle.seed(33)
outs = net(*self.inputs)
return outs
def test_ast_prim_cinn(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def forward(
self,
var_0, # (shape: [11, 704, 7, 7], dtype: paddle.float32, stop_gradient: False)
):
paddle.seed(33)
var_1 = paddle.nn.functional.pooling.avg_pool2d(var_0, kernel_size=[7, 7])
var_2 = var_1.flatten(1)
var_3 = paddle.nn.functional.common.dropout(var_2, p=0.05, training=True)
Expand Down Expand Up @@ -60,7 +61,7 @@ def train(self, net, to_static, with_prim=False, with_cinn=False):
net = paddle.jit.to_static(net, build_strategy=build_strategy, full_graph=True)
else:
net = paddle.jit.to_static(net, full_graph=True)
paddle.seed(123)
paddle.seed(33)
outs = net(*self.inputs)
return outs
def test_ast_prim_cinn(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def forward(
self,
var_0, # (shape: [22, 3840, 1, 1], dtype: paddle.float32, stop_gradient: False)
):
paddle.seed(33)
var_1 = paddle.nn.functional.common.dropout(var_0, p=0.2, axis=None, training=True, mode='upscale_in_train', name=None)
var_2 = paddle.nn.functional.conv._conv_nd(var_1, self.parameter_1, bias=self.parameter_0, stride=[1, 1], padding=[0, 0], padding_algorithm='EXPLICIT', dilation=[1, 1], groups=1, data_format='NCHW', channel_dim=1, op_type='conv2d', use_cudnn=True)
var_3 = var_2.squeeze(axis=-1)
Expand Down Expand Up @@ -60,7 +61,7 @@ def train(self, net, to_static, with_prim=False, with_cinn=False):
net = paddle.jit.to_static(net, build_strategy=build_strategy, full_graph=True)
else:
net = paddle.jit.to_static(net, full_graph=True)
paddle.seed(123)
paddle.seed(33)
outs = net(*self.inputs)
return outs
def test_ast_prim_cinn(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def forward(
self,
var_0, # (shape: [10, 3840, 1, 1], dtype: paddle.float32, stop_gradient: False)
):
paddle.seed(33)
var_1 = paddle.nn.functional.common.dropout(var_0, p=0.2, axis=None, training=True, mode='upscale_in_train', name=None)
var_2 = paddle.nn.functional.conv._conv_nd(var_1, self.parameter_0, bias=self.parameter_1, stride=[1, 1], padding=[0, 0], padding_algorithm='EXPLICIT', dilation=[1, 1], groups=1, data_format='NCHW', channel_dim=1, op_type='conv2d', use_cudnn=True)
var_3 = var_2.squeeze(axis=-1)
Expand Down Expand Up @@ -60,7 +61,7 @@ def train(self, net, to_static, with_prim=False, with_cinn=False):
net = paddle.jit.to_static(net, build_strategy=build_strategy, full_graph=True)
else:
net = paddle.jit.to_static(net, full_graph=True)
paddle.seed(123)
paddle.seed(33)
outs = net(*self.inputs)
return outs
def test_ast_prim_cinn(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def forward(
self,
var_0, # (shape: [43, 3, 224, 224], dtype: paddle.float32, stop_gradient: True)
):
paddle.seed(33)
var_1 = paddle.nn.functional.conv._conv_nd(var_0, self.parameter_13, bias=self.parameter_10, stride=[2, 2], padding=[0, 0], padding_algorithm='EXPLICIT', dilation=[1, 1], groups=1, data_format='NCHW', channel_dim=1, op_type='conv2d', use_cudnn=True)
var_2 = paddle.nn.functional.activation.relu(var_1)
var_3 = paddle.nn.functional.pooling.max_pool2d(var_2, kernel_size=3, stride=2, padding=0, return_mask=False, ceil_mode=False, data_format='NCHW', name=None)
Expand Down Expand Up @@ -322,7 +323,7 @@ def train(self, net, to_static, with_prim=False, with_cinn=False):
net = paddle.jit.to_static(net, build_strategy=build_strategy, full_graph=True)
else:
net = paddle.jit.to_static(net, full_graph=True)
paddle.seed(123)
paddle.seed(33)
outs = net(*self.inputs)
return outs
def test_ast_prim_cinn(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def forward(
self,
var_0, # (shape: [11, 3, 224, 224], dtype: paddle.float32, stop_gradient: True)
):
paddle.seed(33)
var_1 = paddle.nn.functional.conv._conv_nd(var_0, self.parameter_34, bias=self.parameter_2, stride=[2, 2], padding=[0, 0], padding_algorithm='EXPLICIT', dilation=[1, 1], groups=1, data_format='NCHW', channel_dim=1, op_type='conv2d', use_cudnn=True)
var_2 = paddle.nn.functional.activation.relu(var_1)
var_3 = paddle.nn.functional.pooling.max_pool2d(var_2, kernel_size=3, stride=2, padding=0, return_mask=False, ceil_mode=False, data_format='NCHW', name=None)
Expand Down Expand Up @@ -322,7 +323,7 @@ def train(self, net, to_static, with_prim=False, with_cinn=False):
net = paddle.jit.to_static(net, build_strategy=build_strategy, full_graph=True)
else:
net = paddle.jit.to_static(net, full_graph=True)
paddle.seed(123)
paddle.seed(33)
outs = net(*self.inputs)
return outs
def test_ast_prim_cinn(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def forward(
self,
var_0, # (shape: [22, 3, 224, 224], dtype: paddle.float32, stop_gradient: True)
):
paddle.seed(33)
var_1 = paddle.nn.functional.conv._conv_nd(var_0, self.parameter_1, bias=self.parameter_42, stride=[2, 2], padding=[0, 0], padding_algorithm='EXPLICIT', dilation=[1, 1], groups=1, data_format='NCHW', channel_dim=1, op_type='conv2d', use_cudnn=True)
var_2 = paddle.nn.functional.activation.relu(var_1)
var_3 = paddle.nn.functional.pooling.max_pool2d(var_2, kernel_size=3, stride=2, padding=0, return_mask=False, ceil_mode=False, data_format='NCHW', name=None)
Expand Down Expand Up @@ -322,7 +323,7 @@ def train(self, net, to_static, with_prim=False, with_cinn=False):
net = paddle.jit.to_static(net, build_strategy=build_strategy, full_graph=True)
else:
net = paddle.jit.to_static(net, full_graph=True)
paddle.seed(123)
paddle.seed(33)
outs = net(*self.inputs)
return outs
def test_ast_prim_cinn(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def forward(
self,
var_0, # (shape: [10, 3, 224, 224], dtype: paddle.float32, stop_gradient: True)
):
paddle.seed(33)
var_1 = paddle.nn.functional.conv._conv_nd(var_0, self.parameter_24, bias=self.parameter_46, stride=[2, 2], padding=[0, 0], padding_algorithm='EXPLICIT', dilation=[1, 1], groups=1, data_format='NCHW', channel_dim=1, op_type='conv2d', use_cudnn=True)
var_2 = paddle.nn.functional.activation.relu(var_1)
var_3 = paddle.nn.functional.pooling.max_pool2d(var_2, kernel_size=3, stride=2, padding=0, return_mask=False, ceil_mode=False, data_format='NCHW', name=None)
Expand Down Expand Up @@ -322,7 +323,7 @@ def train(self, net, to_static, with_prim=False, with_cinn=False):
net = paddle.jit.to_static(net, build_strategy=build_strategy, full_graph=True)
else:
net = paddle.jit.to_static(net, full_graph=True)
paddle.seed(123)
paddle.seed(33)
outs = net(*self.inputs)
return outs
def test_ast_prim_cinn(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def forward(
self,
var_0, # (shape: [11, 192, 28, 28], dtype: paddle.float32, stop_gradient: False)
):
paddle.seed(33)
var_1 = paddle.nn.functional.conv._conv_nd(var_0, self.parameter_0, bias=self.parameter_3, stride=[2, 2], padding=[0, 0], padding_algorithm='EXPLICIT', dilation=[1, 1], groups=1, data_format='NCHW', channel_dim=1, op_type='conv2d', use_cudnn=True)
var_2 = var_1.flatten(2)
var_3 = var_2.transpose([0, 2, 1])
Expand Down Expand Up @@ -69,7 +70,7 @@ def train(self, net, to_static, with_prim=False, with_cinn=False):
net = paddle.jit.to_static(net, build_strategy=build_strategy, full_graph=True)
else:
net = paddle.jit.to_static(net, full_graph=True)
paddle.seed(123)
paddle.seed(33)
outs = net(*self.inputs)
return outs
def test_ast_prim_cinn(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def forward(
self,
var_0, # (shape: [11, 384, 14, 14], dtype: paddle.float32, stop_gradient: False)
):
paddle.seed(33)
var_1 = paddle.nn.functional.conv._conv_nd(var_0, self.parameter_1, bias=self.parameter_2, stride=[2, 2], padding=[0, 0], padding_algorithm='EXPLICIT', dilation=[1, 1], groups=1, data_format='NCHW', channel_dim=1, op_type='conv2d', use_cudnn=True)
var_2 = var_1.flatten(2)
var_3 = var_2.transpose([0, 2, 1])
Expand Down Expand Up @@ -69,7 +70,7 @@ def train(self, net, to_static, with_prim=False, with_cinn=False):
net = paddle.jit.to_static(net, build_strategy=build_strategy, full_graph=True)
else:
net = paddle.jit.to_static(net, full_graph=True)
paddle.seed(123)
paddle.seed(33)
outs = net(*self.inputs)
return outs
def test_ast_prim_cinn(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def forward(
self,
var_0, # (shape: [43, 96, 56, 56], dtype: paddle.float32, stop_gradient: False)
):
paddle.seed(33)
var_1 = paddle.nn.functional.conv._conv_nd(var_0, self.parameter_1, bias=self.parameter_0, stride=[2, 2], padding=[0, 0], padding_algorithm='EXPLICIT', dilation=[1, 1], groups=1, data_format='NCHW', channel_dim=1, op_type='conv2d', use_cudnn=True)
var_2 = var_1.flatten(2)
var_3 = var_2.transpose([0, 2, 1])
Expand Down Expand Up @@ -69,7 +70,7 @@ def train(self, net, to_static, with_prim=False, with_cinn=False):
net = paddle.jit.to_static(net, build_strategy=build_strategy, full_graph=True)
else:
net = paddle.jit.to_static(net, full_graph=True)
paddle.seed(123)
paddle.seed(33)
outs = net(*self.inputs)
return outs
def test_ast_prim_cinn(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def forward(
self,
var_0, # (shape: [43, 3, 224, 224], dtype: paddle.float32, stop_gradient: True)
):
paddle.seed(33)
var_1 = paddle.nn.functional.conv._conv_nd(var_0, self.parameter_3, bias=self.parameter_2, stride=[4, 4], padding=[0, 0], padding_algorithm='EXPLICIT', dilation=[1, 1], groups=1, data_format='NCHW', channel_dim=1, op_type='conv2d', use_cudnn=True)
var_2 = var_1.flatten(2)
var_3 = var_2.transpose([0, 2, 1])
Expand Down Expand Up @@ -69,7 +70,7 @@ def train(self, net, to_static, with_prim=False, with_cinn=False):
net = paddle.jit.to_static(net, build_strategy=build_strategy, full_graph=True)
else:
net = paddle.jit.to_static(net, full_graph=True)
paddle.seed(123)
paddle.seed(33)
outs = net(*self.inputs)
return outs
def test_ast_prim_cinn(self):
Expand Down
Loading

0 comments on commit e935f90

Please sign in to comment.