chengchingwen / Pickle.jl

An experimental package for loading and saving object in Python Pickle format.
MIT License
50 stars 9 forks source link

Error in loading pickled file. #17

Closed Mobius1D closed 2 years ago

Mobius1D commented 2 years ago

Hello everyone,

I am working on loading pickled RL models from deep_ope repository.

using Pickle
policy_file="../deep-ope-d4rl-maze2d_umaze_dapg_1/maze2d_umaze_dapg_1.pkl"
Pickle.load(open(policy_file, "r"))

Which showed the following error.

MethodError: no method matching iterate(::Nothing)
Closest candidates are:
  iterate(::Union{LinRange, StepRangeLen}) at range.jl:664
  iterate(::Union{LinRange, StepRangeLen}, ::Int64) at range.jl:664
  iterate(::T) where T<:Union{Base.KeySet{var"#s79", var"#s78"} where {var"#s79", var"#s78"<:Dict}, Base.ValueIterator{var"#s77"} where var"#s77"<:Dict} at dict.jl:693
  ...

Stacktrace:
  [1] join(io::IOBuffer, strings::Nothing, delim::Char)
    @ Base ./strings/io.jl:286
  [2] sprint(::Function, ::Nothing, ::Vararg{Any, N} where N; context::Nothing, sizehint::Int64)
    @ Base ./strings/io.jl:105
  [3] sprint(::Function, ::Nothing, ::Vararg{Any, N} where N)
    @ Base ./strings/io.jl:101
  [4] join(strings::Nothing, delim::Char)
    @ Base ./strings/io.jl:293
  [5] execute!(p::Pickler{4}, #unused#::Val{Pickle.OpCodes.STACK_GLOBAL}, arg::Nothing)
    @ Pickle ~/.julia/packages/Pickle/rcLYp/src/deserializer.jl:165
  [6] run!(p::Pickler{4}, op::Pickle.OpCodes.OpCode, io::IOStream)
    @ Pickle ~/.julia/packages/Pickle/rcLYp/src/deserializer.jl:24
  [7] load(p::Pickler{4}, io::IOStream)
    @ Pickle ~/.julia/packages/Pickle/rcLYp/src/deserializer.jl:14
  [8] load(io::IOStream; proto::Int64)
    @ Pickle ~/.julia/packages/Pickle/rcLYp/src/deserializer.jl:10
  [9] load(io::IOStream)
    @ Pickle ~/.julia/packages/Pickle/rcLYp/src/deserializer.jl:10
 [10] top-level scope
    @ In[60]:1
 [11] eval
    @ ./boot.jl:360 [inlined]
 [12] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
    @ Base ./loading.jl:1094

I have tried loading the same file using Python.

policy_file = open('maze2d_umaze_dapg_1.pkl', 'rb')
model = pickle.load(policy_file)
print(model)

Which returns the following:

fc0/weight => [[-0.24976324  0.02437236 -0.13451922  0.07889866]
 [-0.53558046  0.5883652  -0.19739033 -0.16334525]
 [-0.38254845  0.3677665  -0.10093256  0.0787777 ]
 [-0.5146043  -0.46268237 -0.10182711 -0.04299398]
 [-0.4736085   0.5314663  -0.06363042  0.06900128]
 [ 0.4288675   0.14218563  0.07521334  0.20351692]
 [-0.27548894  0.258233   -0.1213172   0.15027781]
 [ 0.47798803 -0.73750746  0.23239346  0.09987929]
 [ 0.25950828  0.33356923  0.22576034 -0.02864336]
 [-0.51958764 -0.22652565 -0.19191699  0.01157673]
 [-0.11735617 -0.44748864 -0.02307078  0.1985095 ]
 [-0.04275223  0.03435304 -0.04326518  0.03403548]
 [ 0.5357944   0.49095502  0.09662168  0.04577622]
 [ 0.14307804  0.31630656 -0.03563361 -0.19463634]
 [-0.3701961   0.6845941   0.01581602 -0.16911715]
 [ 0.09547024  0.6651718  -0.2574737  -0.14071995]
 [-0.24312998  0.01630853 -0.06215848 -0.02291733]
 [-0.58513385  0.4039137   0.2366426   0.12698461]
 [-0.42868817 -0.6517625   0.11353958  0.00513366]
 [ 0.23700784 -0.7936197  -0.01457596  0.14769368]
 [ 0.27631235  0.02761534  0.05386561 -0.02002349]
 [-0.3440193  -0.31986403 -0.16465965  0.17149112]
 [ 0.33395344  0.28971633 -0.20870605  0.16085033]
 [ 0.19742166  0.5844986  -0.1087171   0.04309114]
 [ 0.59509915  0.502237    0.22219571 -0.03991415]
 [ 0.46829808 -0.6197952   0.02224959 -0.11874475]
 [-0.14272685 -0.21322297  0.02081869  0.19030513]
 [ 0.2969574  -0.00845975  0.19320524 -0.10876715]
 [ 0.30850515 -0.07802062 -0.04723085  0.0243715 ]
 [-0.48390365  0.0630404   0.09478311  0.1775121 ]
 [-0.18655996  0.2838944   0.27196538 -0.08971012]
 [ 0.58963346 -0.39905787  0.11861027  0.08021008]]
fc0/bias => [ 0.41530126 -0.59055674 -0.49963677  1.855684   -0.51024556 -1.0412135
 -0.2587467   1.0614333  -0.758762    1.1835232   1.5155529  -0.17334643
 -1.8301266  -1.4096544  -1.0993707  -1.7068022   0.3184883   0.1444739
  2.0448809   1.7235751  -0.8289041   0.941183   -1.5700719  -1.9387597
 -1.8648595   0.9672202   1.179919    0.02272806 -0.6302358   0.97102815
 -0.63470566  0.5484067 ]
fc1/weight => [[ 0.03681079  0.17590876 -0.12201395 ... -0.17369545 -0.14963931
  -0.17601143]
 [ 0.0670159   0.14675426 -0.13332872 ... -0.1301669   0.06820913
  -0.05573252]
 [ 0.10509223 -0.17618981 -0.08891096 ... -0.14426515 -0.00874319
   0.00545316]
 ...
 [-0.13222335  0.10653168 -0.09875119 ...  0.06573778  0.05210264
   0.090635  ]
 [ 0.08668216  0.1494593   0.02815944 ... -0.14645971 -0.07039493
  -0.09636194]
 [ 0.1517955  -0.12940426  0.09024821 ...  0.05272954 -0.05095834
  -0.02838428]]
fc1/bias => [-0.13527088  0.03376016 -0.10870697  0.16506091  0.02930634 -0.15753521
 -0.09177818  0.11914993  0.11890119 -0.07656047  0.04759691  0.08041812
 -0.1700538   0.08336495 -0.11649194 -0.04706557  0.01633543  0.11377233
 -0.12523565  0.11884112  0.08723914  0.1675515  -0.028143   -0.00844942
  0.11440591 -0.16548513 -0.09489578 -0.06005363 -0.1631514  -0.08003259
 -0.14809734 -0.16444357]
last_fc/weight => [[ 0.00673631  0.01413694 -0.00696984 -0.00902766  0.01298066  0.02159753
  -0.0028894   0.01533838  0.00964644  0.0133761   0.01154869 -0.00666417
   0.01423531 -0.01783827 -0.01042892 -0.00318304 -0.01241771  0.01417851
   0.00187902  0.00030713  0.01319259 -0.00275538  0.02433095  0.00278308
   0.00125651  0.01227244 -0.01359816 -0.00589145 -0.00100457 -0.00385595
  -0.01805476  0.00214499]
 [-0.05304925 -0.04802239  0.02065142  0.01589528  0.00344929  0.06642718
   0.05225306  0.01067475 -0.07255157  0.02742405  0.0879996  -0.00142437
   0.1088362   0.04344097  0.02228971  0.0012648  -0.02052769 -0.01876453
   0.06056302  0.01321525 -0.05854758  0.04102954  0.04996042 -0.04249883
  -0.00037383  0.09299558  0.02015056  0.0460965   0.02722585 -0.00878787
  -0.05665134  0.00801087]]
last_fc/bias => [ 0.00880095 -0.12818849]
last_fc_log_std/weight => [[ 0.00673631  0.01413694 -0.00696984 -0.00902766  0.01298066  0.02159753
  -0.0028894   0.01533838  0.00964644  0.0133761   0.01154869 -0.00666417
   0.01423531 -0.01783827 -0.01042892 -0.00318304 -0.01241771  0.01417851
   0.00187902  0.00030713  0.01319259 -0.00275538  0.02433095  0.00278308
   0.00125651  0.01227244 -0.01359816 -0.00589145 -0.00100457 -0.00385595
  -0.01805476  0.00214499]
 [-0.05304925 -0.04802239  0.02065142  0.01589528  0.00344929  0.06642718
   0.05225306  0.01067475 -0.07255157  0.02742405  0.0879996  -0.00142437
   0.1088362   0.04344097  0.02228971  0.0012648  -0.02052769 -0.01876453
   0.06056302  0.01321525 -0.05854758  0.04102954  0.04996042 -0.04249883
  -0.00037383  0.09299558  0.02015056  0.0460965   0.02722585 -0.00878787
  -0.05665134  0.00801087]]
last_fc_log_std/bias => [ 0.00880095 -0.12818849]
nonlinearity => tanh
output_distribution => gaussian

I am not sure about the problem here. It would be great if I could get help regarding this.

Thanks in advance.

chengchingwen commented 2 years ago

Hi,

~Currently It's a little hard to debug the pickle. Is the file shareable so that I can test it locally?~

Looks there are some behavior change, either in julia or the datastructure.jl, so the CI are actually failed.

chengchingwen commented 2 years ago

@Mobius1D The error should be fix with the new release (0.2.3). However, since we haven't support numpy pickle, some of the file might not be fully loaded

Mobius1D commented 2 years ago

I will try the fix.

Thanks a lot for your response.

Mobius1D commented 2 years ago

@chengchingwen Hi,

The error still happens to persist.

MethodError: no method matching iterate(::Nothing)
Closest candidates are:
  iterate(::Union{LinRange, StepRangeLen}) at range.jl:664
  iterate(::Union{LinRange, StepRangeLen}, ::Int64) at range.jl:664
  iterate(::T) where T<:Union{Base.KeySet{var"#s79", var"#s78"} where {var"#s79", var"#s78"<:Dict}, Base.ValueIterator{var"#s77"} where var"#s77"<:Dict} at dict.jl:693
  ...

Stacktrace:
  [1] join(io::IOBuffer, strings::Nothing, delim::Char)
    @ Base ./strings/io.jl:286
  [2] sprint(::Function, ::Nothing, ::Vararg{Any, N} where N; context::Nothing, sizehint::Int64)
    @ Base ./strings/io.jl:105
  [3] sprint(::Function, ::Nothing, ::Vararg{Any, N} where N)
    @ Base ./strings/io.jl:101
  [4] join(strings::Nothing, delim::Char)
    @ Base ./strings/io.jl:293
  [5] execute!(p::Pickler{4}, #unused#::Val{Pickle.OpCodes.STACK_GLOBAL}, arg::Nothing)
    @ Pickle ~/.julia/packages/Pickle/vqUU4/src/deserializer.jl:165
  [6] run!(p::Pickler{4}, op::Pickle.OpCodes.OpCode, io::IOStream)
    @ Pickle ~/.julia/packages/Pickle/vqUU4/src/deserializer.jl:24
  [7] load(p::Pickler{4}, io::IOStream)
    @ Pickle ~/.julia/packages/Pickle/vqUU4/src/deserializer.jl:14
  [8] load(io::IOStream; proto::Int64)
    @ Pickle ~/.julia/packages/Pickle/vqUU4/src/deserializer.jl:10
  [9] load(io::IOStream)
    @ Pickle ~/.julia/packages/Pickle/vqUU4/src/deserializer.jl:10
 [10] top-level scope
    @ In[30]:1
 [11] eval
    @ ./boot.jl:360 [inlined]
 [12] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
    @ Base ./loading.jl:1094

And the version of Pickle is:

Status `~/.julia/environments/v1.6/Project.toml`
[fbb45041] Pickle v0.2.3

maze2d_umaze_dapg_1.zip This is the pickled file. It would be great if you could fix it because I am working on a project called ReinforcementLearningDatasets as a part of my open source promotion program and the project's success depends on this package.

Thanks in advance.

chengchingwen commented 2 years ago

I pushed the new version (0.2.4) with a new function Pickle.npyload. Since the file contain numpy array, it can not be loaded by regular Pickle.load. Therefore I made a quick hack to make loading numpy array work. You should be able to call Pickle.npyload("../deep-ope-d4rl-maze2d_umaze_dapg_1/maze2d_umaze_dapg_1.pkl") and get the desired output.

notice: Currently, I only fix the load part, which mean you still can't save julia object as numpy array. Also, I'll recommend manually check the loaded result since it a quick hack, and let me know if anything has the wrong result or even unloadable.

Mobius1D commented 2 years ago

It works beautifully. Thanks so much for your time and efforts.

I am fine with the load part and am incredibly happy that it works.

chengchingwen commented 2 years ago

Glad to hear that! If there aren't other problems, I'll close this issue.

findmyway commented 2 years ago

Thanks to @chengchingwen 's help! ❤️