cyd0806 commited on
Commit
1947df9
·
verified ·
1 Parent(s): a79a2c7

Upload apex-master/tests/distributed/synced_batchnorm/test_batchnorm1d.py with huggingface_hub

Browse files
apex-master/tests/distributed/synced_batchnorm/test_batchnorm1d.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import apex
3
+
4
+ model = apex.parallel.SyncBatchNorm(4).cuda()
5
+ model.weight.data.uniform_()
6
+ model.bias.data.uniform_()
7
+ data = torch.rand((8,4)).cuda()
8
+
9
+ model_ref = torch.nn.BatchNorm1d(4).cuda()
10
+ model_ref.load_state_dict(model.state_dict())
11
+ data_ref = data.clone()
12
+
13
+ output = model(data)
14
+ output_ref = model_ref(data_ref)
15
+
16
+ assert(output.allclose(output_ref))
17
+ assert(model.running_mean.allclose(model_ref.running_mean))
18
+ assert(model.running_var.allclose(model_ref.running_var))