Skip to content

wandb does not work with verifiers integration #63

@tmabraham

Description

@tmabraham

Running python -m tinker_cookbook.recipes.verifiers_rl.train errors out if wandb logging is enabled:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/tanishq/tinker-cookbook/tinker_cookbook/recipes/verifiers_rl/train.py", line 184, in <module>
    asyncio.run(cli_main(cli_config, None))
  File "/home/tanishq/.local/share/uv/python/cpython-3.12.11-linux-x86_64-gnu/lib/python3.12/asyncio/runners.py", line 195, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/home/tanishq/.local/share/uv/python/cpython-3.12.11-linux-x86_64-gnu/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tanishq/.local/share/uv/python/cpython-3.12.11-linux-x86_64-gnu/lib/python3.12/asyncio/base_events.py", line 691, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/tanishq/tinker-cookbook/tinker_cookbook/recipes/verifiers_rl/train.py", line 179, in cli_main
    await train.main(cfg)
  File "/home/tanishq/tinker-cookbook/tinker_cookbook/utils/trace.py", line 332, in async_wrapper
    return await func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tanishq/tinker-cookbook/tinker_cookbook/rl/train.py", line 990, in main
    ml_logger = ml_log.setup_logging(
                ^^^^^^^^^^^^^^^^^^^^^
  File "/home/tanishq/tinker-cookbook/tinker_cookbook/utils/ml_log.py", line 470, in setup_logging
    ml_logger.log_hparams(config)
  File "/home/tanishq/tinker-cookbook/tinker_cookbook/utils/ml_log.py", line 349, in log_hparams
    logger.log_hparams(config)
  File "/home/tanishq/tinker-cookbook/tinker_cookbook/utils/ml_log.py", line 230, in log_hparams
    wandb.config.update(dump_config(config))
  File "/home/tanishq/tinker-cookbook/.venv/lib/python3.12/site-packages/wandb/sdk/wandb_config.py", line 187, in update
    sanitized = self._update(d, allow_val_change)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tanishq/tinker-cookbook/.venv/lib/python3.12/site-packages/wandb/sdk/wandb_config.py", line 180, in _update
    sanitized = self._sanitize_dict(
                ^^^^^^^^^^^^^^^^^^^^
  File "/home/tanishq/tinker-cookbook/.venv/lib/python3.12/site-packages/wandb/sdk/wandb_config.py", line 267, in _sanitize_dict
    k, v = self._sanitize(k, v, allow_val_change)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tanishq/tinker-cookbook/.venv/lib/python3.12/site-packages/wandb/sdk/wandb_config.py", line 288, in _sanitize
    raise config_util.ConfigError(
wandb.sdk.lib.config_util.ConfigError: Attempted to change value of key "dataset_builder" from {'vf_env': '<verifiers.envs.singleturn_env.SingleTurnEnv object at 0x7fd46752da30>',
'groups_per_batch': 128, 'dataset_n': -1, 'dataset_seed': None} to {'vf_env': '<verifiers.envs.singleturn_env.SingleTurnEnv object at 0x7fd4677eb800>', 'groups_per_batch': 128, 'dataset_n': -1,
 'dataset_seed': None}
If you really want to do this, pass allow_val_change=True to config.update()

It seems the reason seems to be VerifiersRLDatasetBuilder is a chz.chz class and all the fields get saved to wandb but this includes vf_env the full verifiers env... i couldn't find any good solution to avoid this and came up with some hacky solution with Claude Code's help:

-@chz.chz
 class VerifiersRLDatasetBuilder(RLDatasetBuilder):
-    vf_env: vf.Environment
-    groups_per_batch: int
-    dataset_n: int
-    dataset_seed: int | None
+    def __init__(
+        self,
+        vf_env: vf.Environment,
+        groups_per_batch: int,
+        dataset_n: int,
+        dataset_seed: int | None,
+    ):
+        # Use object.__setattr__ to bypass frozen instance restrictions from parent chz class
+        object.__setattr__(self, 'vf_env', vf_env)
+        object.__setattr__(self, 'groups_per_batch', groups_per_batch)
+        object.__setattr__(self, 'dataset_n', dataset_n)
+        object.__setattr__(self, 'dataset_seed', dataset_seed)
+
+    def to_dict(self):
+        """Return a dictionary representation excluding the vf_env object."""
+        return {
+            "groups_per_batch": self.groups_per_batch,
+            "dataset_n": self.dataset_n,
+            "dataset_seed": self.dataset_seed,
+        }

Let me know if there may be better approaches for addressing this issue otherwise I'm happy to PR this change directly as well.

cc: @willccbb

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions