/
vuron
/
adept
Обзор
Документация
Войти
/
vuron
/
adept
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
python/torch_refs/torch_dot.py
61 строка
1 KB
kolkir
Refactor python folder structure
01 мар 2025, 22:16
01 мар 2025, 22:16
ef25f05
Код
Авторство
О чём код?
import torch x = torch.tensor([[1.0, 2.0], [5.0, 6.0]], requires_grad=True) print(x) print(x.shape) y = torch.tensor([[7.0, 8.0, 1.0, 3.0], [9.0, 4.0, 5.0, 2.0]], requires_grad=True) print(y) print(y.shape) z = torch.matmul(x, y) print(z) # ---------------------------------------------------- x = torch.tensor([[1.0, 2.0, 3.0, 4.0], [5.0, 6.0, 7.0, 8.0]], requires_grad=True) print(x) print(x.shape) y = torch.tensor([[7.0, 8.0], [1.0, 3.0], [9.0, 4.0], [5.0, 2.0]], requires_grad=True) print(y) print(y.shape) z = torch.matmul(x, y) print(z) z.sum().backward() print(f"x grad = {x.grad}") print(f"y grad = {y.grad}") # ------------------------------------------------------------------ x = torch.tensor( [ [[1.0, 2.0, 3.0, 4.0], [5.0, 6.0, 7.0, 8.0]], [[1.0, 2.0, 3.0, 4.0], [5.0, 6.0, 7.0, 8.0]], ], requires_grad=True, ) print(x) print(x.shape) y = torch.tensor( [ [[7.0, 8.0], [1.0, 3.0], [9.0, 4.0], [5.0, 2.0]], [[7.0, 8.0], [1.0, 3.0], [9.0, 4.0], [5.0, 2.0]], ], requires_grad=True, ) print(y) print(y.shape) z = torch.matmul(x, y) print(z) z.sum().backward() print(f"x grad = {x.grad}") print(f"y grad = {y.grad}")