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.

Ray integration yaml serialization error

See original GitHub issue

wandb --version && python --version && uname

  • Weights and Biases version: 0.8.12
  • Python version: 3.7.3
  • Operating System: Linux

Description

Tried to use the wandb Ray tune integration. Training fails when serializing config with following error: yaml.representer.RepresenterError: cannot represent an object: <function main.<locals>.<lambda> at 0x7fd0fc4bfbf8>

What I Did

  1. Started from simple cartpole example provided by Ray: https://raw.githubusercontent.com/ray-project/ray/master/rllib/examples/multiagent_cartpole.py

  2. Imported wandb from wandb.ray import WandbLogger

  3. Included wandb configuration and set it as logger

    tune.run(
        "PPO",
        stop={"training_iteration": args.num_iters},
        config={
            "env": "multi_cartpole",
            "monitor": True,
            "env_config": {
                "wandb": {"project": "rl", "monitor_gym": True}
            },
            "log_level": "DEBUG",
            "simple_optimizer": args.simple,
            "num_sgd_traceiter": 10,
            "multiagent": {
                "policies": policies,
                "policy_mapping_fn": (
                    lambda agent_id: random.choice(policy_ids)),
            },
        },
        loggers=[WandbLogger],
    )
  1. Fails with following stacktrace:
2019-09-30 17:45:01,241	ERROR trial_runner.py:560 -- Error processing event.
Traceback (most recent call last):
  File "/home/nacef/tools/anaconda3/envs/rl/lib/python3.7/site-packages/ray/tune/trial_runner.py", line 540, in _process_trial
    result, terminate=(decision == TrialScheduler.STOP))
  File "/home/nacef/tools/anaconda3/envs/rl/lib/python3.7/site-packages/ray/tune/trial.py", line 386, in update_last_result
    self.result_logger.on_result(self.last_result)
  File "/home/nacef/tools/anaconda3/envs/rl/lib/python3.7/site-packages/ray/tune/logger.py", line 333, in on_result
    _logger.on_result(result)
  File "/home/nacef/tools/anaconda3/envs/rl/lib/python3.7/site-packages/wandb/ray/__init__.py", line 24, in on_result
    wandb.config[k] = config[k]
  File "/home/nacef/tools/anaconda3/envs/rl/lib/python3.7/site-packages/wandb/wandb_config.py", line 184, in __setitem__
    self.persist()
  File "/home/nacef/tools/anaconda3/envs/rl/lib/python3.7/site-packages/wandb/wandb_config.py", line 171, in persist
    conf_file.write(str(self))
  File "/home/nacef/tools/anaconda3/envs/rl/lib/python3.7/site-packages/wandb/wandb_config.py", line 274, in __str__
    allow_unicode=True, encoding='utf-8')
  File "/home/nacef/tools/anaconda3/envs/rl/lib/python3.7/site-packages/yaml/__init__.py", line 200, in dump
    return dump_all([data], stream, Dumper=Dumper, **kwds)
  File "/home/nacef/tools/anaconda3/envs/rl/lib/python3.7/site-packages/yaml/__init__.py", line 188, in dump_all
    dumper.represent(data)
  File "/home/nacef/tools/anaconda3/envs/rl/lib/python3.7/site-packages/yaml/representer.py", line 26, in represent
    node = self.represent_data(data)
  File "/home/nacef/tools/anaconda3/envs/rl/lib/python3.7/site-packages/yaml/representer.py", line 47, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/home/nacef/tools/anaconda3/envs/rl/lib/python3.7/site-packages/yaml/representer.py", line 205, in represent_dict
    return self.represent_mapping('tag:yaml.o
wandb: Waiting for W&B process to finish, PID 20314
rg,2002:map', data)
  File "/home/nacef/tools/anaconda3/envs/rl/lib/python3.7/site-packages/yaml/representer.py", line 116, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/home/nacef/tools/anaconda3/envs/rl/lib/python3.7/site-packages/yaml/representer.py", line 47, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/home/nacef/tools/anaconda3/envs/rl/lib/python3.7/site-packages/yaml/representer.py", line 205, in represent_dict
    return self.represent_mapping('tag:yaml.org,2002:map', data)
  File "/home/nacef/tools/anaconda3/envs/rl/lib/python3.7/site-packages/yaml/representer.py", line 116, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/home/nacef/tools/anaconda3/envs/rl/lib/python3.7/site-packages/yaml/representer.py", line 47, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/home/nacef/tools/anaconda3/envs/rl/lib/python3.7/site-packages/yaml/representer.py", line 205, in represent_dict
    return self.represent_mapping('tag:yaml.org,2002:map', data)
  File "/home/nacef/tools/anaconda3/envs/rl/lib/python3.7/site-packages/yaml/representer.py", line 116, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/home/nacef/tools/anaconda3/envs/rl/lib/python3.7/site-packages/yaml/representer.py", line 57, in represent_data
    node = self.yaml_representers[None](self, data)
  File "/home/nacef/tools/anaconda3/envs/rl/lib/python3.7/site-packages/yaml/representer.py", line 229, in represent_undefined
    raise RepresenterError("cannot represent an object: %s" % data)
yaml.representer.RepresenterError: cannot represent an object: <function main.<locals>.<lambda> at 0x7fd0fc4bfbf8>

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
issue-label-bot[bot]commented, Sep 30, 2019

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.93. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

0reactions
AGKhalilcommented, Jun 21, 2020

Found related commit. It is 4 behind master though. So for anyone looking, until this is fully merged, my solution and the commit’s solution should work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ray integration yaml serialization error · Issue #586 - GitHub
Tried to use the wandb Ray tune integration. Training fails when serializing config with following error: yaml.representer.
Read more >
Serialization — Ray 2.2.0 - the Ray documentation
Since Ray processes do not share memory space, data transferred between workers and nodes will need to serialized and deserialized. Ray uses the...
Read more >
Error - Sitecore is configured for item serialization but it's ...
I'm using Sitecore 9.3 and when I try to serialize an item by Developer > Serialize ... the item generated always has the...
Read more >
Format of Text Serialized files - Unity - Manual
Format of Text Serialized files ; Unity's Scene ; The file writes each Object in a Scene as a separate YAML document. The...
Read more >
10x Faster Parallel Python Without Python Multiprocessing
On a machine with 48 physical cores, Ray is 9x faster than Python multiprocessing and 28x faster than single-threaded Python. Error bars are ......
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