/
vuron
/
adept
Обзор
Документация
Войти
/
vuron
/
adept
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
with_cpu
python/torch_refs/torch_linear.py
33 строки
762 B
kolkir
Add tests for Linear layer and update matmul usage
28 мар 2025, 23:53
28 мар 2025, 23:53
bc788d8
Код
Авторство
О чём код?
import torch import torch.nn.functional as F # input = torch.tensor([[1, 2, 3, 4]], dtype=torch.float32) # print(input.shape) # weight = torch.tensor( # [[7, 8, 1, 3], [7, 8, 1, 3]], dtype=torch.float32, requires_grad=True # ) # print(weight.shape) # bias = torch.tensor([[3, 2]], dtype=torch.float32, requires_grad=True) input = torch.tensor([[1, 2, 3, 4], [5, 6, 7, 8]], dtype=torch.float32) print(input.shape) weight = torch.tensor( [[7, 8, 1, 3], [7, 8, 1, 3]], dtype=torch.float32, requires_grad=True ) print(weight.shape) bias = torch.tensor([[3, 2]], dtype=torch.float32, requires_grad=True) out = F.linear(input, weight, bias) print(out) weight.retain_grad() bias.retain_grad() out.mean().backward() print(weight.grad) print(bias.grad)