GithubHelp home page GithubHelp logo

Comments (7)

justusschock avatar justusschock commented on May 11, 2024 1

Yes, that's something I thought of. This might be a good replacement for flash packages, but in lightning we sometimes also have in-code dependencies on these variables, meaning that I would define them again no-matter if we replaced them globally.
I don't know yet, if that's the case for flash as well (it could be for example if the supported models depend on that). So in general I like the idea, in lightning it won't make sense to use this and in flash it depends on the condition I just mentioned :)

from lightning-flash.

justusschock avatar justusschock commented on May 11, 2024

not sure if that really helps, since otherwise we may have to mock them with None in some cases.

from lightning-flash.

akihironitta avatar akihironitta commented on May 11, 2024

@justusschock Thank you for your feedback. Do you mean like this in pytorch_lightning/loggers/wandb?

except ImportError:
    wandb, Run = None, None

It will still be possible in that case, too, by:

if not cm.is_successful():
    wandb, Run = None, None

from lightning-flash.

carmocca avatar carmocca commented on May 11, 2024

I like it. We could call it OptionalImport.

Some questions:

  • Can you do more than one import inside the context manager? What if they all fail?
  • How do you plan to pass the install it with 'pip install lightning-flash[image]' message?

from lightning-flash.

kaushikb11 avatar kaushikb11 commented on May 11, 2024

Hi @akihironitta, do you want to give it a try?

from lightning-flash.

akihironitta avatar akihironitta commented on May 11, 2024

Sorry for the delay, I missed your message.

Can you do more than one import inside the context manager? What if they all fail?

Yes, but in case of multiple packages like the below case, if import kornia fails, import transformers will be skipped, so we need to split the import statements per individual package:

with try_import() as _import:
    import kornia        # if kornia not found
    import transformers  # this line will be skipped

# so, it needs to be divided
with try_import() as _import_kornia:
    import kornia
with try_import() as _import_transformers:
    import transformers

How do you plan to pass the install it with 'pip install lightning-flash[image]' message?

Currently, I came up with nothing except for hard-coding in flash/utils/imports.py as below. I thought of parsing requirements/*.txt, but packages can have different names than their pypi names. e.g. PIL for Pillow.

_extras = {
    "image": ["torchvision", "PIL", "kornia", ...],
    ...
}

I was thinking about this issue again, and I'm now not sure if my suggestion is reasonable enough because my suggestion itself cannot handle version checks...

from lightning-flash.

stale avatar stale commented on May 11, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from lightning-flash.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.