Skip to content

please add option to load fine-tuned file to CPU if trained on GPU #259

@bsugerman

Description

@bsugerman

I fine-tuned the pytorch_model.bin on a GPU machine (google cloud) but need to use it on my home computer (no GPU). When I tried to open it using model = BertForMaskedLM.from_pretrained(bert_version) I got the following error:

 RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() 
 is False. If you are running on a CPU-only machine, please use torch.load with map_location='cpu'
 to map your storages to the CPU.

Perhaps you can add an option into from_pretrained() such as cpu=True which will then call

torch.load(weights_path, map_location=lambda storage, location: 'cpu')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions