model = SimpleNet(784, 256, 10)# 모든 파라미터 순회for name, param in model.named_parameters(): print(f"{name}: shape={param.shape}, requires_grad={param.requires_grad}")# 전체 파라미터 수total = sum(p.numel() for p in model.parameters())trainable = sum(p.numel() for p in model.parameters() if p.requires_grad)print(f"전체: {total:,}, 학습 가능: {trainable:,}")
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')# 모델 전체를 GPU로 이동model = SimpleNet(784, 256, 10).to(device)# 입력 데이터도 같은 디바이스로x = torch.randn(32, 784).to(device)output = model(x)
# 특정 레이어의 파라미터 동결for param in model.fc1.parameters(): param.requires_grad = False# 동결된 파라미터 확인trainable = sum(p.numel() for p in model.parameters() if p.requires_grad)print(f"학습 가능 파라미터: {trainable:,}")