Why is it necessary to specify subcommands in the yaml config for the model in CLI mode? #17209
-
|
I am currently upgrading from Test Project StructureIn my bigger project, I have an (partial) abstract base class inheriting from from pytorch_lightning.demos.boring_classes import BoringModel
class BaseModel(BoringModel):
def __init__(self,
base: int):
super().__init__()
self._base = base
class ChildModelA(BaseModel):
def __init__(self,
base: int,
child: Optional[int] = None):
super().__init__(base)
if child is None:
child = "None"
self._child = child
print(f"A,base| {self._base}")
print(f"A,child| {self._child}")
class ChildModelB(BaseModel):
def __init__(self,
base: int,
child: Optional[int] = None):
super().__init__(base)
if child is None:
child = "Null"
self._child = child
print(f"B,base| {self._base}")
print(f"B,child| {self._child}")and the instantiation of the CLI as follows: cli = LightningCLI(model_class=test_lightning.BaseModel,
datamodule_class=BoringDataModule,
subclass_mode_model=True,
parser_kwargs={'default_config_files': ["test_cfg.yaml"]})The model:
class_path: test_lightning.base_model.BaseModel
init_args:
base: 2
child: 5ProblemHowever, this configuration works ONLY when
QuestionMy question now is: Why do I need to specify the subcommands within the With the following fit:
model:
class_path: test_lightning.base_model.BaseModel
init_args:
base: 1
child: 2
test:
model:
class_path: test_lightning.base_model.BaseModel
init_args:
base: 1
child: 2Wouldn't it suffice to have a single configuration that applies to all subcommands and only have the subcommands IF an individual behaviour is wanted? I am clearly doing something wrong here but I was not able to distinguish which behaviour is required based on the Documentation. I appreciate any help or a hint to the right direction! Cheers, Envrionment
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
There are many possibilities to provide settings to a CLI, and having one yaml where you can specify all subcommand is just one of them. With python main.py fit --config=test_cfg.yamlNote that in the command, the config is given after python main.py --config=test_cfg.yaml fiti.e. the config is given before |
Beta Was this translation helpful? Give feedback.
There are many possibilities to provide settings to a CLI, and having one yaml where you can specify all subcommand is just one of them. With
run=Trueyou can give to the CLI a single config that does not require a subcommand as:Note that in the command, the config is given after
fit. The subcommand is already known, so the config is expected to not specify it. If the command isi.e. the config is given before
fit, then the config must specify the subcommand. Similarly it is possible to specifydefault_config_filesfor each subcommand (see lightning_cli_advanced_2.html#set-default-config-files), in which …