Lightning-AI / pytorch-lightning

Pretrain, finetune and deploy AI models on multiple GPUs, TPUs with zero code changes.
https://lightning.ai
Apache License 2.0
27.47k stars 3.3k forks source link

No module named 'flash.core' and mentionning packages versions #19702

Open Antoine101 opened 3 months ago

Antoine101 commented 3 months ago

📚 Documentation

Hi guys,

I am trying to run this finetuning with flash tutorial: https://lightning-flash.readthedocs.io/en/stable/general/finetuning.html I pip installed flash package but as you can see below it doesn't find the core and image modules. image

Your code doesn't mention the version of the flash package used for this tutorial. I don't know if it is what's causing the issue here but it would be great if you could mention the versions of packages you used to be able to reproduce your tutorials. Even though it would be ideal to have your doc the most up to date as possible, mentionning packages versions would make your doc more relevant through time.

Cheers

cc @borda

EDIT: I actually didn't install the right package. I installed flash instead of lightning-flash, which is different (still the remark on the version of packages still stands).

When lauching the tutorial, I get a missing "requests" package (shouldn't it get installed as well automatically)? And also the following error (I would expect to copy paste and run a tutorial without any problem):

PS D:\Dev\lightning_finetuning> & C:/Users/APU/.conda/envs/lightning-finetuning/python.exe d:/Dev/lightning_finetuning/main.py
C:\Users\APU\.conda\envs\lightning-finetuning\lib\site-packages\flash\__init__.py:21: FutureWarning: In the future `np.object` will be defined as the corresponding NumPy scalar.
  if not hasattr(numpy, tp_name):
C:\Users\APU\.conda\envs\lightning-finetuning\lib\site-packages\flash\__init__.py:21: FutureWarning: In the future `np.bool` will be defined as the corresponding NumPy scalar.
  if not hasattr(numpy, tp_name):
Global seed set to 42
data/hymenoptera_data.zip: 67335KB [00:09, 7266.38KB/s]
sys:1: FutureWarning: Please pass an instantiated object of the `InputTransform` class. Passing the Class and keyword arguments separately has been deprecated since v0.8.0 and will be removed in v0.9.0.
Traceback (most recent call last):
  File "d:\Dev\lightning_finetuning\main.py", line 16, in <module>
    datamodule = ImageClassificationData.from_folders(
  File "C:\Users\APU\.conda\envs\lightning-finetuning\lib\site-packages\flash\image\classification\data.py", line 280, in from_folders
    return cls(
  File "C:\Users\APU\.conda\envs\lightning-finetuning\lib\site-packages\flash\core\data\data_module.py", line 132, in __init__
    self.input_transform = create_or_configure_input_transform(
  File "C:\Users\APU\.conda\envs\lightning-finetuning\lib\site-packages\flash\core\data\io\input_transform.py", line 726, in create_or_configure_input_transform
    return transform(**transform_kwargs)
  File "<string>", line 6, in __init__
  File "C:\Users\APU\.conda\envs\lightning-finetuning\lib\site-packages\flash\core\data\io\input_transform.py", line 57, in __post_init__
    self._populate_transforms_for_stage(stage)
  File "C:\Users\APU\.conda\envs\lightning-finetuning\lib\site-packages\flash\core\data\io\input_transform.py", line 650, in _populate_transforms_for_stage
    transform=self.__resolve_transforms(running_stage),
  File "C:\Users\APU\.conda\envs\lightning-finetuning\lib\site-packages\flash\core\data\io\input_transform.py", line 670, in __resolve_transforms
    fn = getattr(self, method_name)()
  File "C:\Users\APU\.conda\envs\lightning-finetuning\lib\site-packages\flash\image\classification\input_transform.py", line 62, in train_per_sample_transform
    return T.Compose(
NameError: name 'T' is not defined

EDIT2: NameError in EDIT comes from the fact that I didn't have torchvision installed, only torch (it should be mentionned to install torchvision as well). So in input_transform.py, it wasn't entering the if: image

After that, the code fails at model creation as shown below: image I have lightning-flash installed now but it is not sufficient apparently. Running: image doesn't work, nor runing without quotes.

EDIT3: Managed to do a pip install lightning-flash[image] (without quotes contrary to what is written in this doc https://lightning-flash.readthedocs.io/en/stable/installation.html) after uninstalling lightning-flash. But the code still doesn't find this dependency.

EDIT4: It works if I create an environment and only pip install "lightning-flash[image]==0.8.2" with double quotes instead of single ones, and without installing torch and torchvision separately first. However I am now left with the following error:

GPU available: False, used: False
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
Missing logger folder: D:\Dev\lightning_finetuning\lightning_logs

  | Name          | Type           | Params
-------------------------------------------------
0 | train_metrics | ModuleDict     | 0
1 | val_metrics   | ModuleDict     | 0
2 | test_metrics  | ModuleDict     | 0
3 | adapter       | DefaultAdapter | 11.2 M
-------------------------------------------------
10.6 K    Trainable params
11.2 M    Non-trainable params
11.2 M    Total params
44.710    Total estimated model params size (MB)
Traceback (most recent call last):
  File "C:\Users\APU\.conda\envs\flash\lib\site-packages\lightning_fabric\loggers\tensorboard.py", line 202, in log_metrics
    self.experiment.add_scalar(k, v, step)
  File "C:\Users\APU\.conda\envs\flash\lib\site-packages\lightning_fabric\loggers\logger.py", line 117, in experiment
    return get_experiment() or _DummyExperiment()
  File "C:\Users\APU\.conda\envs\flash\lib\site-packages\lightning_utilities\core\rank_zero.py", line 42, in wrapped_fn
    return fn(*args, **kwargs)
  File "C:\Users\APU\.conda\envs\flash\lib\site-packages\lightning_fabric\loggers\logger.py", line 115, in get_experiment
    return fn(self)
  File "C:\Users\APU\.conda\envs\flash\lib\site-packages\lightning_fabric\loggers\tensorboard.py", line 181, in experiment
    from torch.utils.tensorboard import SummaryWriter
  File "C:\Users\APU\.conda\envs\flash\lib\site-packages\torch\utils\tensorboard\__init__.py", line 4, in <module>
    LooseVersion = distutils.version.LooseVersion
AttributeError: module 'distutils' has no attribute 'version'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "d:\Dev\lightning_finetuning\main.py", line 50, in <module>
    trainer.finetune(model, datamodule=datamodule, strategy="freeze")
  File "C:\Users\APU\.conda\envs\flash\lib\site-packages\flash\core\trainer.py", line 164, in finetune
    return super().fit(model, train_dataloader, val_dataloaders, datamodule)
  File "C:\Users\APU\.conda\envs\flash\lib\site-packages\pytorch_lightning\trainer\trainer.py", line 608, in fit
    call._call_and_handle_interrupt(
  File "C:\Users\APU\.conda\envs\flash\lib\site-packages\pytorch_lightning\trainer\call.py", line 38, in _call_and_handle_interrupt
    return trainer_fn(*args, **kwargs)
  File "C:\Users\APU\.conda\envs\flash\lib\site-packages\pytorch_lightning\trainer\trainer.py", line 650, in _fit_impl
    self._run(model, ckpt_path=self.ckpt_path)
  File "C:\Users\APU\.conda\envs\flash\lib\site-packages\pytorch_lightning\trainer\trainer.py", line 1100, in _run
    self._log_hyperparams()
  File "C:\Users\APU\.conda\envs\flash\lib\site-packages\pytorch_lightning\trainer\trainer.py", line 1168, in _log_hyperparams
    logger.log_hyperparams(hparams_initial)
  File "C:\Users\APU\.conda\envs\flash\lib\site-packages\lightning_utilities\core\rank_zero.py", line 42, in wrapped_fn
    return fn(*args, **kwargs)
  File "C:\Users\APU\.conda\envs\flash\lib\site-packages\pytorch_lightning\loggers\tensorboard.py", line 181, in log_hyperparams
    return super().log_hyperparams(params=params, metrics=metrics)
  File "C:\Users\APU\.conda\envs\flash\lib\site-packages\lightning_utilities\core\rank_zero.py", line 42, in wrapped_fn
    return fn(*args, **kwargs)
  File "C:\Users\APU\.conda\envs\flash\lib\site-packages\lightning_fabric\loggers\tensorboard.py", line 233, in log_hyperparams
    self.log_metrics(metrics, 0)
  File "C:\Users\APU\.conda\envs\flash\lib\site-packages\lightning_utilities\core\rank_zero.py", line 42, in wrapped_fn
    return fn(*args, **kwargs)
  File "C:\Users\APU\.conda\envs\flash\lib\site-packages\lightning_fabric\loggers\tensorboard.py", line 206, in log_metrics
    raise ValueError(m) from ex
ValueError:
 you tried to log -1 which is currently not supported. Try a dict or a scalar/tensor.

Sorry if this is messy I am modifying the issue as I progress into the tutorial and see stuff to improve or clarify!

awaelchli commented 3 months ago

@Antoine101 Thanks for the docs feedback. You may not have seen it but Lightning Flash is discontinued and archived. It won't receive any updates anymore so we can't take action on this ticket. If you are starting a new project, please reconsider using Flash, or take the bits and pieces that you need and copy them to your project.

Antoine101 commented 3 months ago

Ok! thanks for the clarification. I would suggest you remove it from the doc then because it's still part of the 2.2.1 doc if I'm correct and I didn't see any indication it is discontinued and archived, even after double checking just now.

By taking bits and pieces, do you mean scavenge parts of what was done in flash for finetuning?

I already have a complete mid-level lightning architecture for training my model so I don't really need the abstraction of flash. I saw the BackboneFinetuning callback that could probably do what I need but I don't really know how to leverage it. I opened another issue for that to point the lack of detail in this callback's doc (issue 19711).

awaelchli commented 3 months ago

Can you show me where you found a reference to Flash in the Lightning docs?

By taking bits and pieces, do you mean scavenge parts of what was done in flash for finetuning?

Yes

Antoine101 commented 3 months ago

Any of the following links:

image

Third link, which is a lightning.ai page: image

None of these pages indicate a deprecation. Or am i mistaken?

Borda commented 3 months ago

well, if you explicitly search for Flash docs you will find it :)

Antoine101 commented 3 months ago

Well, yes, but originally I searched "lightning finetuning" and ended up on the third link which sends me to lightning.ai and shows doc version 2.2.1. So it's fair on my end to assume it's still a thing. :-)

carmocca commented 2 months ago

@Antoine101 raises a good point. https://lightning.ai/docs/pytorch/stable/ecosystem/flash.html is still getting served from somewhere and appears through Google