This repository has been archived by the owner on Nov 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix LightningCLI compatibility (#288)
Change AutoModel type hint to fix LightningCLI compatibility.
- Loading branch information
Showing
12 changed files
with
78 additions
and
57 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
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
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,32 @@ | ||
from importlib.util import find_spec | ||
from unittest import mock | ||
|
||
import pytest | ||
from pytorch_lightning.cli import LightningCLI | ||
|
||
from lightning_transformers.task.vision.image_classification import ( | ||
ImageClassificationDataModule, | ||
ImageClassificationTransformer, | ||
) | ||
|
||
|
||
@pytest.mark.skipif(find_spec("jsonargparse") is None, reason="jsonargparse is required") | ||
def test_lightning_cli_image_classification(): | ||
config = { | ||
"data": { | ||
"dataset_name": "beans", # Resolve from TransformerDataModule.__init__ | ||
}, | ||
"model": { | ||
"pretrained_model_name_or_path": "nateraw/tiny-vit-random", # Resolve from TaskTransformer.__init__ | ||
}, | ||
} | ||
with mock.patch("sys.argv", ["any.py", f"--config={config}"]): | ||
cli = LightningCLI( | ||
ImageClassificationTransformer, | ||
ImageClassificationDataModule, | ||
run=False, | ||
) | ||
assert cli.config.data.dataset_name == "beans" | ||
assert cli.config.model.pretrained_model_name_or_path == "nateraw/tiny-vit-random" | ||
assert isinstance(cli.config_init.data, ImageClassificationDataModule) | ||
assert isinstance(cli.config_init.model, ImageClassificationTransformer) |
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