PyTorch Lightning ile Ölçeklenebilir AI Modelleri
Sergiy Tkachuk
Director, GenAI Productivity
$$
$$
$$
$$

import torch.nn.utils.prune as prune
prune.l1_unstructured(model.fc, name="weight",
amount=0.4)
print(model.fc.weight.data)
tensor([[ 0.25, -0.13, 0.05, 0.70],
[-0.88, 0.31, -0.02, 0.44]]) # Budama öncesi
tensor([[ 0.25, -0.13, 0.00, 0.70],
[ 0.00, 0.31, 0.00, 0.44]]) # Budama sonrası (ağırlıkların %40'ı 0)
$$
$$
$$
Sequential(
(fc): Linear(
in_features=128, out_features=64,
bias=True
(weight): PrunedParam()
)
) # prune.remove öncesi
import torch.nn.utils.prune as prune
prune.remove(model.fc, 'weight')
# Print model structure
print(model)
Sequential(
(fc): Linear(in_features=128,
out_features=64,
bias=True)
) # prune.remove sonrası

PyTorch Lightning ile Ölçeklenebilir AI Modelleri