facebookresearch/fairseq

Python API Transformer.from_pretrained support directly to load on GPU

Open

#2.480 geöffnet am 13. Aug. 2020

Auf GitHub ansehen
 (6 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Python (6.224 Forks)batch import
enhancementhelp wanted

Repository-Metriken

Stars
 (29.107 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

❓ Questions and Help

Hi,

I'm using the API command to load my finetuned mBART model, below is the command:

en2ar = TransformerModel.from_pretrained(
  '/home/ubuntu/mayub/models',
  checkpoint_file='checkpoint_best_en-ar_ft.pt',
  data_name_or_path='/home/ubuntu/mayub/models',
  bpe='sentencepiece',
  sentencepiece_vocab='sentencepiece.bpe.model'
)

Looks like this loads the model first on cpu and then I do en2ar.cuda() to replicate again on GPU device.

image

Is there a way I can avoid the loading on both devices and just directly load on GPU. Reason is I have 5 other models which I need to load and save on RAM.

Appreciate any help. Thanks !

Contributor Guide