admin管理员组

文章数量:1287577

AttributeError: module 'numpy.random._pickle' has no attribute '_Forecast_model__randomstate_ctor'

I am trying to do this as I got error while loading the saved model -

model = NHiTSModel.load(model_path)

This gives me this error

"(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 numpy.random._pickle.__randomstate_ctor was not an allowed global by default. Please use torch.serialization.add_safe_globals([__randomstate_ctor]) or the torch.serialization.safe_globals([__randomstate_ctor]) context manager to allowlist this global if you trust this class/function"

class Forecast_model:
    #Class to perform forecasting and scenario analysis.

    def __init__(self):
        
        #This constructor initializes the Preprocess object. It doesn't require any arguments 
        #and currently performs no actions. 
    def model_run({Arguments}):
        ### CODE #### 
        with torch.serialization.add_safe_globals([np.random._pickle.__randomstate_ctor]):
             model = NHiTSModel.load(model_path, weights_only=False) 

本文标签: pytorchinit function is appending the class name to quotrandomstatectorquotStack Overflow