Schaalbare AI-modellen met PyTorch Lightning
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]]) # Voor pruning
tensor([[ 0.25, -0.13, 0.00, 0.70],
[ 0.00, 0.31, 0.00, 0.44]]) # Na pruning (40% gewichten op 0)
$$
$$
$$
Sequential(
(fc): Linear(
in_features=128, out_features=64,
bias=True
(weight): PrunedParam()
)
) # Voor prune.remove
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)
) # Na prune.remove

Schaalbare AI-modellen met PyTorch Lightning