Skip to content

Error: Weights only load failed #19

@Cold7

Description

@Cold7

after running for a while, using tutorial data, the programsshow the message

Start adaptive training at high-resolution
followed by the error


UnpicklingError                           Traceback (most recent call last)
Cell In[5], line 2
      1 SignatureMatrix, CellFractionPrediction = \
----> 2     Deconvolution(sc_ref, bulkdata, sep='\t',
      3                   datatype='TPM', genelenfile='./GeneLength.txt',
      4                   mode='high-resolution', adaptive=True,
      5                   save_model_name=None,
      6                   batch_size=128, epochs=128)

File ~/TAPE/lib/python3.12/site-packages/TAPE/deconvolution.py:84, in Deconvolution(necessary_data, real_bulk, sep, variance_threshold, scaler, datatype, genelenfile, d_prior, mode, adaptive, save_model_name, sparse, batch_size, epochs, seed)
     81 if adaptive is True:
     82     if mode == 'high-resolution':
     83         CellTypeSigm, Pred = \
---> 84             predict(test_x=test_x, genename=genename, celltypes=celltypes, samplename=samplename,
     85                     model=model, model_name=save_model_name,
     86                     adaptive=adaptive, mode=mode)
     87         return CellTypeSigm, Pred
     89     elif mode == 'overall':

File ~/TAPE/lib/python3.12/site-packages/TAPE/train.py:114, in predict(test_x, genename, celltypes, samplename, model_name, model, adaptive, mode)
    112     model = torch.load(model_name + ".pth")
    113 elif model is not None and model_name is None:
--> 114     model = torch.load("model.pth")
    115 decoder_parameters = [{'params': [p for n, p in model.named_parameters() if 'decoder' in n]}]
    116 encoder_parameters = [{'params': [p for n, p in model.named_parameters() if 'encoder' in n]}]

File ~/TAPE/lib/python3.12/site-packages/torch/serialization.py:1470, in load(f, map_location, pickle_module, weights_only, mmap, **pickle_load_args)
   1462                 return _load(
   1463                     opened_zipfile,
   1464                     map_location,
   (...)   1467                     **pickle_load_args,
   1468                 )
   1469             except pickle.UnpicklingError as e:
-> 1470                 raise pickle.UnpicklingError(_get_wo_message(str(e))) from None
   1471         return _load(
   1472             opened_zipfile,
   1473             map_location,
   (...)   1476             **pickle_load_args,
   1477         )
   1478 if mmap:

UnpicklingError: Weights only load failed. This file can still be loaded, to do so you have two options, do those steps only if you trust the source of the checkpoint. 
	(1) In PyTorch 2.6, we changed the default value of the `weights_only` argument in `torch.load` from `False` to `True`. Re-running `torch.load` with `weights_only` set to `False` will likely succeed, but it can result in arbitrary code execution. Do it only if you got the file from a trusted source.
	(2) Alternatively, to load with `weights_only=True` please check the recommended steps in the following error message.
	WeightsUnpickler error: Unsupported global: GLOBAL TAPE.model.AutoEncoder was not an allowed global by default. Please use `torch.serialization.add_safe_globals([AutoEncoder])` or the `torch.serialization.safe_globals([AutoEncoder])` context manager to allowlist this global if you trust this class/function.

Check the documentation of torch.load to learn more about types accepted by default with weights_only https://pytorch.org/docs/stable/generated/torch.load.html.

Could you help me please to be able to run the code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions