您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
20 行
684 B
20 行
684 B
import torch
|
|
|
|
from mlagents.trainers.torch.layers import Swish, linear_layer, Initialization
|
|
|
|
|
|
def test_swish():
|
|
layer = Swish()
|
|
input_tensor = torch.Tensor([[1, 2, 3], [4, 5, 6]])
|
|
target_tensor = torch.mul(input_tensor, torch.sigmoid(input_tensor))
|
|
assert torch.all(torch.eq(layer(input_tensor), target_tensor))
|
|
|
|
|
|
def test_initialization_layer():
|
|
torch.manual_seed(0)
|
|
# Test Zero
|
|
layer = linear_layer(
|
|
3, 4, kernel_init=Initialization.Zero, bias_init=Initialization.Zero
|
|
)
|
|
assert torch.all(torch.eq(layer.weight.data, torch.zeros_like(layer.weight.data)))
|
|
assert torch.all(torch.eq(layer.bias.data, torch.zeros_like(layer.bias.data)))
|