Giter Club home page Giter Club logo

Comments (10)

SunMarc avatar SunMarc commented on August 16, 2024 1

Sorry for the delay @DonggeunYu ! As you saw from your investigation, the issue is that we are using the weight of the embedding layer that is offloaded to cpu, meaning that the weights are on meta device. To fix the issue, we would need to use the layer instead of just getting the weights. Another solution would be to make sure that this specific layer stays on the cuda.

from transformers.

amyeroberts avatar amyeroberts commented on August 16, 2024

Hi @DonggeunYu, thanks for reporting!

We'll look into it. Out of interest, how did you discover this? Was is modifying the tests, or are the tests just an easy way to demonstrate this behaviour?

from transformers.

DonggeunYu avatar DonggeunYu commented on August 16, 2024

Easy way to demonstrate this behavior.
While using a private model, I discovered that there was a problem with nn.Embedding.

from transformers.

DonggeunYu avatar DonggeunYu commented on August 16, 2024

I may be wrong, as I still need to understand the transformers and accelerate code fully.
When offload is used, it becomes a meta device during the init process. The weight of nn.Embedding created in __init__ becomes the meta device. If i use nn.Embedding callable, the pre_forward hook of accelerate will match the device of args, kwrags, and embedding.

However, because the embedding weight is inserted into the forward of another module, it enters the pre_forward hook as a meta device.
To prove this, the log that the pre_forward of accelerate hook.py outputs the module device and the device of the args.
Until the nn.embedding weight in the problem, the module device is meta device, and the args device is cuda. If the nn.embedding weight in the problem enters another module's args, the module device is meta and the args device is meta (embedding weight). An error occurs when performing meta to cuda using send_to_device (args, self.execution_device).

module.__class__.__name__, device of module, device of args
Linear [device(type='meta')] [device(type='cuda', index=0)]
LayerNorm [device(type='meta')] [device(type='cuda', index=0)]
Linear [device(type='meta')] [device(type='cuda', index=0)]
Linear [device(type='meta')] [device(type='cuda', index=0)]
LayerNorm [device(type='meta')] [device(type='cuda', index=0)]
Linear [device(type='meta')] [device(type='meta')]

def pre_forward of accelerate
nn.Embedding of transformers

from transformers.

amyeroberts avatar amyeroberts commented on August 16, 2024

@DonggeunYu Thanks for the update. Indeed, the structure of using the embedding weights rather than the layer in the forward pass is quite odd. cc @muellerzr who knows more about the pre_forward hook of accelerate

from transformers.

DonggeunYu avatar DonggeunYu commented on August 16, 2024

@amyeroberts @muellerz
How is the progress?

from transformers.

muellerzr avatar muellerzr commented on August 16, 2024

cc @SunMarc

from transformers.

DonggeunYu avatar DonggeunYu commented on August 16, 2024

@SunMarc
I would appreciate it if you could check the issue.

from transformers.

DonggeunYu avatar DonggeunYu commented on August 16, 2024

I would appreciate it if you could check the issue. 🥲

from transformers.

DonggeunYu avatar DonggeunYu commented on August 16, 2024

@SunMarc
Is there any solution?
Is it possible to keep certain layers in cuda when using accelerate offload?

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.