environ¶
- trojanzoo.environ.add_argument(parser)[source]¶
- Add environ arguments to argument parser.For specific arguments implementation, see
Env.add_argument()
.- Parameters:
parser (argparse.ArgumentParser) – The parser to add arguments.
- Returns:
argparse._ArgumentGroup – The argument group.
- trojanzoo.environ.create(cmd_config_path=None, dataset_name=None, dataset=None, seed=None, data_seed=None, cudnn_benchmark=None, config=config, cache_threshold=None, verbose=None, color=None, device=None, tqdm=None, **kwargs)[source]¶
- Load
env
values from config and command line.- Parameters:
dataset_name (str) – The dataset name.
dataset (str | trojanzoo.datasets.Dataset) – Dataset instance (required for
model_ema
) or dataset name (as the alias of dataset_name).model (trojanzoo.models.Model) – Model instance.
config (Config) – The default parameter config.
**kwargs – The keyword arguments in keys of
['optim_args', 'train_args', 'writer_args']
.
- Returns:
Env – The
env
instance.
- class trojanzoo.environ.Env(*args, device='auto', **kwargs)[source]¶
The dict-like environment class that inherits
trojanzoo.utils.module.Param
. It should be singleton in most cases.Warning
There is already an environ instance
trojanzoo.environ.env
. callcreate()
to set its value.NEVER call the class init method to create a new instance (unless you know what you’re doing).
- Parameters:
device (str | device) –
Defaults to
'auto'
.'auto'
(use gpu if available)'cpu'
'gpu' | 'cuda'
- Variables:
color (bool) – Whether to show colorful outputs in console using ASNI escape characters. Defaults to
False
.num_gpus (int) – Number of available GPUs.
tqdm (bool) – Whether to use
tqdm.tqdm
to show progress bar. Defaults toFalse
.verbose (int) – The output level. Defaults to
0
.cudnn_benchmark (bool) – Whether to use
torch.backends.cudnn.benchmark
to accelerate without deterministic. Defaults toFalse
.cache_threshold (float) – the threshold (MB) to call
torch.cuda.empty_cache
. Defaults toNone
(never).seed (int) – The random seed for numpy, torch and cuda.
data_seed (int) – Seed to process data (e.g.,
trojanzoo.datasets.Dataset.split_dataset()
)device (device) – The default device to store tensors.
world_size (int) – Number of distributed machines. Defaults to
1
.
- classmethod add_argument(group)[source]¶
Add environ arguments to argument parser group. View source to see specific arguments.
Note
This is the implementation of adding arguments. For users, please use
add_argument()
instead, which is more user-friendly.