TorchConfig
TorchConfig is a Python package that simplifies configuring PyTorch.
Suppose that you want to test multiple optimizers to find which optimizer works best with your model. Here is one way you could achieve this:
if CONFIG["optimizer_name"] == "SGD":
optimizer = optim.SGD(
net.parameters(),
lr=CONFIG["optimizer_lr"],
momentum=CONFIG["optimizer_momentum"],
dampening=CONFIG["optimizer_dampening"],
weight_decay=CONFIG["optimizer_weight_decay"],
nesterov=CONFIG["optimizer_nesterov"],
)
...
elif CONFIG["optimizer_name"] == "Adam":
optimizer = optim.Adam(
net.parameters(),
lr=CONFIG["optimizer_lr"],
betas=CONFIG["optimizer_betas"],
eps=CONFIG["optimizer_eps"],
weight_decay=CONFIG["optimizer_weight_decay"],
amsgrad=CONFIG["optimizer_amsgrad"],
)
}
With TorchConfig, this is just one line!
optimizer = torchconfig.get_optimizer_from_dict(net.parameters(), CONFIG)
Installation
pip install torchconfig
How to Use
You can specify any optimizer or lr_scheduler by specifying its name through a dictionary key-value pair or an argument.
optimizer_config = {"name": "SGD", "lr": 0.1 }
optimizer = torchconfig.get_optimizer_from_args(net.parameters(), name="SGD", lr=0.1)
# or
optimizer = torchconfig.get_optimizer_from_args(net.parameters(), **optimizer_config)
# or
optimizer = torchconfig.get_optimizer_from_dict(net.parameters(), optimizer_config)
lr_scheduler_config = { "name": "CyclicLR", "base_lr": 0.01, "max_lr": 1 }
lr_scheduler = torchconfig.get_lr_scheduler_from_args(optimizer, **CONFIG["lr_scheduler"])
# or
lr_scheduler = torchconfig.get_lr_scheduler_from_args(optimizer, name="CyclicLR", base_lr=0.01, max_lr=1)
# or
lr_scheduler = torchconfig.get_lr_scheduler_from_dict(optimizer, CONFIG["lr_scheduler"])
Release files for torchconfig 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| torchconfig-0.1.3.tar.gz | 3.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| torchconfig-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.1 kB
Release files / torchconfig-0.1.3.tar.gz
| Download URL | torchconfig-0.1.3.tar.gz |
|---|---|
| Size | 3.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d2a9706a425e8bc6107545f6c4c723572eedce262454fdc3612e0ee9c6d33d66
|
|
BLAKE2b-256 checksum How to use checksums |
f995871685ec4d41a8307cc3b694116409febc8aef2d586571b8b47aa9dd7911
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
|
Release files / torchconfig-0.1.3-py3-none-any.whl
| Download URL | torchconfig-0.1.3-py3-none-any.whl |
|---|---|
| Size | 3.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
624173b4e5b3a0a2c8c15bb86d1eb102303664ac2cc7e82c7bc82de7eb70faee
|
|
BLAKE2b-256 checksum How to use checksums |
7987d5ff3fc8b1c768a80a62461b8a00b0920becdaa3d6c96f875593ded35c97
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
|