Giter Site home page Giter Site logo

Comments (8)

amyeroberts avatar amyeroberts commented on June 26, 2024

cc @ydshieh

from transformers.

dannikay avatar dannikay commented on June 26, 2024

I can no longer reproduce this after restarting my notebook kernel. I suppose that the pytorch detection relies on some system environment which requires notebook kernel to restart to pickup. Feel free to close this.

from transformers.

dannikay avatar dannikay commented on June 26, 2024

It seems that _torch_available is a global variable and set at initialization time: https://github.com/huggingface/transformers/blob/02300273e220932a449a47ebbe453e7789be454b/src/transformers/utils/import_utils.py#L180C1-L180C17

So it won't be re-evaluated in the same notebook kernel when it was re-evaluated (until I restart my kernel). One improvement I can think of is to reevaluate this variable in is_torch_available() but I don't know if that breaks other things or not.

from transformers.

amyeroberts avatar amyeroberts commented on June 26, 2024

So it won't be re-evaluated in the same notebook kernel when it was re-evaluated (until I restart my kernel).

Does this mean that torch is installed in the notebook after importing transformers?

from transformers.

ydshieh avatar ydshieh commented on June 26, 2024

In general, for notebook (well, I usually use Google Colab), if there is/are some installation(s), it is recommended to restart the kernel.

reevaluate this variable in is_torch_available()

We make use of _torch_available is (probably) and similar ideas for many other is_xxx_available is we try to avoid re-evaluation which might slowdown a lot.

I am open to a PR that improve stuff (the mentioned issue) but keep things fast (regarding what I mentioned above)

from transformers.

dannikay avatar dannikay commented on June 26, 2024

@amyeroberts torch is installed in the notebook kernel ("!pip install ...") and I re-executed the block to import transformer multiple times (with no avail).

from transformers.

amyeroberts avatar amyeroberts commented on June 26, 2024

orch is installed in the notebook kernel ("!pip install ...") and I re-executed the block to import transformer multiple times (with no avail).

@dannikay Just to be clear, this means that transformers was already imported, torch installed, then the cell to import transformers re-executed?

As @ydshieh notes above, we have a cache which means is_torch_available is executed once and its result stored within a python session. This helps speed things up within the transformers library - we have lots of is_xxx_available flags which enable us to safely guard for different framework and modality usage e.g. PyTorch vs TensorFlow.

If you or anyone else wants to submit a PR which would make this more dynamic whilst maintaining speed, we'd be very happy to review!

from transformers.

dannikay avatar dannikay commented on June 26, 2024

@amyeroberts correct.

from transformers.

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.