-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from pytorch-lumo/dev1
Weakly update 2023.03.26
- Loading branch information
Showing
41 changed files
with
1,295 additions
and
725 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# Runtime Configuration and Params | ||
|
||
## Params | ||
|
||
`~lumo.Params`is used to specify the configuration required for the current experiment. In addition to defining parameters that support autocompletion, it also supports command-line parameters, inheritance, and reading from multiple configuration files. | ||
|
||
The simplest usage is as follows: | ||
|
||
```python | ||
from lumo import Params | ||
|
||
params = Params() | ||
params.lr = 1e-3 | ||
params.dataset = 'cifar10' | ||
params.from_args() # python main.py --dataset=cifar100 | ||
|
||
print(params.dataset) | ||
>>> "cifar100" | ||
``` | ||
|
||
Limit the value of parameters: | ||
|
||
```python | ||
params.dataset = params.choice('cifar10', 'cifar100') | ||
print(params.dataset) | ||
>>> "cifar10" # by default is the first value | ||
|
||
params.dataset = "imagenet" | ||
>>> raise BoundCheckError: value of param 'dataset' should in values ('cifar10', | ||
'cifar100'), but got imagenet | ||
``` | ||
|
||
Read from other locations: | ||
|
||
```python | ||
params.from_json("*.json") | ||
params.from_yaml("*.yaml") | ||
params.from_yaml("*.yml") | ||
params.from_dict({}) | ||
``` | ||
|
||
`params.config`or`params.c`is a built-in reserved parameter. When the values of these two variables are strings and the path judgment is a yaml or json file or file list, the configuration is read from the corresponding position: | ||
|
||
```json | ||
# cfg.json | ||
{ | ||
"dataset": "cifar100" | ||
} | ||
``` | ||
|
||
```python | ||
params.from_args(['--c','cfg.json']) | ||
print(params.dataset) | ||
>>> "cifar100" | ||
``` | ||
|
||
## Configuration | ||
|
||
`lumo` provides a multi-level configuration system, including three file locations: | ||
|
||
```arduino | ||
~/.lumorc.json -> user-level | ||
<repo>/.lumorc.json -> repo-level, private | ||
<repo>/.lumorc.public.json -> repo-level, public | ||
``` | ||
|
||
All configurations are loaded into`lumo.glob`at runtime for global settings: | ||
|
||
```css | ||
from lumo import glob | ||
|
||
glob['xxx'] | ||
``` | ||
|
||
## Difference between Configuration and Hyperparameters | ||
|
||
In `lumo`, configurations are mostly used for non-experiment-related content that is related to the computer environment and `lumo` behavior, such as the location of the dataset, GitHub access tokens, etc. All supported optional behaviors in`lumo`can be controlled by modifying the configuration in`glob`. The following are the currently supported configurable items: | ||
|
||
| Configuration | Description | | ||
| --- | --- | | ||
| github_access_token | Replaces the access_token parameter of the exp.backup() method. | | ||
| exp_root | One of several initial paths. | | ||
| db_root | One of several initial paths. | | ||
| progress_root | One of several initial paths. | | ||
| metric_root | One of several initial paths. | | ||
| cache_dir | One of several initial paths. | | ||
| blob_root | One of several initial paths. | | ||
| timezone | Determines the timezone used by lumo. Default is 'Asia/Shanghai'. | | ||
| TRAINER_LOGGER_STDIO | Controls whether the Logger outputs to the standard output stream. | | ||
| dev_branch | The branch used for saving code snapshots during version control. Default is 'lumo_experiments'. | | ||
| HOOK_LOCKFILE | Behavior control for loading LockFile ExpHook. | | ||
| HOOK_RECORDABORT | Behavior control for loading RecordAbort ExpHook. | | ||
| HOOK_GITCOMMIT | Behavior control for loading GitCommit ExpHook. | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Build your Dataset Easily | ||
|
||
lumo has designed`~lumo.DatasetBuilder`to provide a unified interface for constructing datasets. This can greatly reduce repetitive dataset design in most cases. | ||
|
||
Taking the CIFAR10 dataset as an example, if the dataset requires images to be output with two augmentations, either the Dataset class needs to be modified or the transform function needs to be rewritten: | ||
|
||
```python | ||
class MyCIFAR(CIFAR10): | ||
... | ||
|
||
def __getitem(self,index): | ||
sample = self.data[index] | ||
label = self.target[index] | ||
return self.transform1(sample), self.transform2(sample), label | ||
|
||
|
||
# or | ||
|
||
def two_transform(sample): | ||
... | ||
return transform1(sample), transform2(sample) | ||
``` | ||
|
||
When facing such changes in multiple datasets, this rewriting method can be time-consuming. Especially when the output format is not yet certain and may be subject to frequent changes. | ||
|
||
To solve this, lumo provides a universal and streaming solution through`DatasetBuilder`. You only need to prepare the raw data in the standard format and the standard one-to-one augmentation functions: | ||
|
||
```python | ||
... | ||
|
||
source = CIFAR10() | ||
transform1 = ... | ||
transform2 = ... | ||
``` | ||
|
||
Then, any output format can be defined through`DatasetBuilder`: | ||
|
||
```python | ||
from lumo import DatasetBuilder | ||
|
||
ds = ( | ||
DatasetBuilder() | ||
# Define input stream | ||
.add_input('xs', source.data) | ||
.add_input('ys', source.targets) | ||
# Define output stream | ||
.add_output('xs','xs1',transform1) | ||
.add_output('xs','xs2',transform2) | ||
.add_output('ys','ys') | ||
) | ||
|
||
print(ds[0]) | ||
>>> {'xs1': ..., 'xs2': ..., "ys": ...} | ||
``` |
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.