question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Python 3.8: "an integer is required (got type bytes)" when loading models saved under older Python versions

See original GitHub issue

Describe the bug

There is an issue loading trained agent files in Python 3.8.

Code example

I checked this on the rl-baselines3-zoo repository.

(base) manifold$ python enjoy.py --algo sac --env Pendulum-v0
Loading latest experiment, id=1
Traceback (most recent call last):
  File "enjoy.py", line 225, in <module>
    main()
  File "enjoy.py", line 141, in main
    model = ALGOS[algo].load(model_path, env=env, **kwargs)
  File "/home/manifold/stable-baselines3/stable_baselines3/common/base_class.py", line 561, in load
    data, params, pytorch_variables = load_from_zip_file(path, device=device)
  File "/home/manifold/stable-baselines3/stable_baselines3/common/save_util.py", line 390, in load_from_zip_file
    data = json_to_data(json_data)
  File "/home/manifold/stable-baselines3/stable_baselines3/common/save_util.py", line 164, in json_to_data
    deserialized_object = cloudpickle.loads(base64_object)
TypeError: an integer is required (got type bytes)

System Info Describe the characteristic of your environment:

  • SB3 downloaded from git trunk
  • Python version 3.8.5
  • PyTorch version 1.6.0
  • Gym version: latest from git
  • Cloudpickle 1.6.0

Additional context

I printed out info and saw that it occurs when loading the data key learning_rate on the SAC example above. For policies trained using recent versions of SB3 it happens for lr_schedule.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
pablogsalcommented, Oct 1, 2020

Seeing this I agree having a nice fallback would be more elegant until things are sorted out upstream.

✋ Hi, CPython maintainer here. Unfortunately, there is nothing to be done in our side, as the signature of code objects is not considered stable between versions. The constructor is purpously not even documented and we have this advice here:

If you instantiate any of these types, note that signatures may vary between Python versions.

(https://docs.python.org/3/library/types.html#standard-interpreter-types)

You can also use this new convenience method that we added to make the transition easier for people using code objects:

https://docs.python.org/3/library/types.html#types.CodeType.replace

0reactions
araffincommented, Oct 3, 2020

closing this in favor of #172 (and as it is not an issue coming from SB3)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix 'TypeError: an integer is required (got type bytes ...
This is happening because you're using python 3.8. The latest pip release of pyspark (pyspark 2.4.4 at time of writing) doesn't support ...
Read more >
Fix - TypeError: an integer is required (got type bytes) - Kontext
When running PySpark 2.4.8 script in Python 3.8 environment with Anaconda, the following issue occurs: TypeError: an integer is required (got ...
Read more >
ctypes — A foreign function library for Python — Python 3.11.1 ...
ctypes is a foreign function library for Python. It provides C compatible data types, and allows calling functions in DLLs or shared libraries....
Read more >
mlflow.pyfunc — MLflow 2.0.1 documentation
pyfunc module defines a generic filesystem format for Python models and provides utilities for saving to and loading from this format. The format...
Read more >
an integer is required (got type bytes) on python 3.8.5 ... - Reddit
i don't seem to locate how to upgrade my spark in ubuntu. I am using jupyter notebook. My java version is 11.0.11. ubuntu@ip-172-31-15-155:~$ ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found