Skip to main content

Group PyTorch Parameters according to Rules

Project description

torch-parameter-groups Build Status codecov PyPI version

Group PyTorch Parameters according to Rules.

Installation

Need Python 3.6+.

pip install torch-parameter-groups

Usage

import torch
import torch.nn as nn
import torch_basic_models
import torch_parameter_groups


model = torch_basic_models.MobileNetV2.factory()
optimizer = torch_parameter_groups.optimizer_factory(
    model=model,
    config={
        'type': 'SGD',
        'kwargs': {
            'momentum': 0.9,
            'nesterov': True,
            'weight_decay': 0.0001,
        },
        'rules': [
            {
                'param_name_list': ['weight'],
                'kwargs': {
                    'weight_decay': 0
                }
            },
            {
            }
        ]
    },
)

criterion = nn.CrossEntropyLoss()
output = model(torch.randn(1, 3, 224, 224))
loss = criterion(output, torch.Tensor([0]).long())
loss.backward()
optimizer.step(closure=None)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torch-parameter-groups-0.0.5.post1.tar.gz (4.9 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page