lightning-flash
lightning-flash copied to clipboard
Fix Flash CLI: in case of converting functions to classes + JIT tracing tests
What does this PR do?
- CI has been failing for Flash CI for the case when a function is converted to
ClassFromFunctionclass. We were not checking if its type is subclass ofCustomClassFunctionBase. - For JIT tracing, the model needs to be attached to the
Trainerclass, else it will give an error similar to:ImageClassifier is not attached to Trainer. - Baal integration fails on recent Lightning Trainer versions.
on_predict_dataloader, on_train_dataloader, on_test_dataloaderwere deprecated, and removed in PL 1.7. I'm not very sure if we need them, removing that works? - For BaaL integration,
probabilitiesneed to have a check if it's not empty elsetorch.catwill fail.
This PR attempts to fix both of the issues. Note that we should document that the best way to JIT trace the model in Flash is to:
# 2. Build the task
model = ImageClassifier(backbone="resnet18", labels=datamodule.labels)
# 3. Create the trainer and finetune the model
trainer = flash.Trainer(max_epochs=3, gpus=torch.cuda.device_count())
# Attach trainer to the model object
model.trainer = trainer
trace = torch.jit.trace(model, torch.randn((3, 196, 196))
Issue: #1413
Before submitting
- [ ] Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
- [ ] Did you read the contributor guideline, Pull Request section?
- [ ] Did you make sure your PR does only one thing, instead of bundling different changes together?
- [ ] Did you make sure to update the documentation with your changes?
- [ ] Did you write any new necessary tests? [not needed for typos/docs]
- [ ] Did you verify new and existing tests pass locally with your changes?
- [ ] If you made a notable change (that affects users), did you update the CHANGELOG?
PR review
- [ ] Is this pull request ready for review? (if not, please submit in draft mode)
Anyone in the community is free to review the PR once the tests have passed. If we didn't discuss your PR in Github issues there's a high chance it will not be merged.
Did you have fun?
Make sure you had fun coding 🙃
Codecov Report
Merging #1410 (8e03fd7) into master (8737ee8) will decrease coverage by
0.00%. The diff coverage is85.00%.
@@ Coverage Diff @@
## master #1410 +/- ##
==========================================
- Coverage 91.77% 91.76% -0.01%
==========================================
Files 286 286
Lines 12857 12861 +4
==========================================
+ Hits 11799 11802 +3
- Misses 1058 1059 +1
| Flag | Coverage Δ | |
|---|---|---|
| unittests | 91.76% <85.00%> (-0.01%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
| Impacted Files | Coverage Δ | |
|---|---|---|
| flash/core/utilities/lightning_cli.py | 98.16% <ø> (ø) |
|
| flash/core/integrations/icevision/adapter.py | 94.78% <80.00%> (-1.52%) |
:arrow_down: |
| ...ash/image/classification/integrations/baal/data.py | 87.96% <100.00%> (ø) |
|
| ...ash/image/classification/integrations/baal/loop.py | 94.81% <100.00%> (-0.12%) |
:arrow_down: |
| flash/image/embedding/model.py | 98.48% <100.00%> (ø) |
|
| flash/image/embedding/vissl/hooks.py | 98.24% <100.00%> (ø) |
|
| flash/text/question_answering/model.py | 94.55% <0.00%> (+0.68%) |
:arrow_up: |
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.
About the 5 failures left in the CI:
CI testing / pytest (ubuntu-20.04, 3.9, latest, stable, graph) (pull_request): This failure is flaky, and has been fixed in PL. Once there is another release of PL, we should be good.CI testing / pytest (ubuntu-20.04, 3.9, latest, stable, audio) (pull_request): PR https://github.com/Lightning-AI/lightning-flash/pull/1409 is opened to fix it.Lightning-AI.lightning-flash (Special): Horovod versioning error, but I also see/usr/bin/pipnot found error. I plan to fix this in a separate PR, doesn't seem to be very urgent as the first step was to support PL 1.7 with Flash.
Thanks to @otaj for his help with a few failures related to PL 1.7, it was very helpful. ❤️ Also @rohitgr7 for a fix! 🔥
cc: @ethanwharris @Borda @carmocca
Hi, @ethanwharris - The 5 failures are expected in the CI, only 1 of these is something that I haven't investigated yet. Fixes for others are either already merged in PL, or we have a PR opened in Flash. Could you please take a look again, and help merge if it all looks good? Thanks!