- Notifications
You must be signed in to change notification settings - Fork3.6k
Conflict between Lightning and Huggingface Transformers (device_map).#17878
-
Hugginface will add For example, When
In these cases huggingface secretly send input tensors to cuda:0 or cuda:1, which conflicts with This conflict make lightning hard to train hugginface transformers in many cases, currently I manually remove huggingface's hook that send tensors to differnet device by
wonder if there is better way for use lightning and huggingface together... |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 4 comments 1 reply
-
how can i use this function? |
BetaWas this translation helpful?Give feedback.
All reactions
-
fromaccelerate.hooksimportAlignDevicesHookdefremove_hook_from_module(module:torch.nn.Module,recurse=False,hook_cls=AlignDevicesHook):ifhasattr(module,"_hf_hook")andisinstance(module._hf_hook,hook_cls):module._hf_hook.detach_hook(module)delattr(module,"_hf_hook")ifhasattr(module,"_old_forward"):module.forward=module._old_forwarddelattr(module,"_old_forward")ifrecurse:forchildinmodule.children():remove_hook_from_module(child,recurse)returnmodulemodel=auto_cls.from_pretrained(model_name,**config_kwargs)remove_hook_from_module(model,recurse=True) |
BetaWas this translation helpful?Give feedback.
All reactions
👍 5❤️ 4🚀 4
-
Legend |
BetaWas this translation helpful?Give feedback.
All reactions
-
Question, how can i make this one works with peft model as:
as for now getting this error:
|
BetaWas this translation helpful?Give feedback.
All reactions
-
So if we specify the device with a number instead of a list, this problem can be avoided? |
BetaWas this translation helpful?Give feedback.