# Key Error in wandb.config when using wandb.sweep in pytorch

**URL:** <https://community.wandb.ai/t/key-error-in-wandb-config-when-using-wandb-sweep-in-pytorch/2898>\
**Category:** W&B Help\
**Tags:** sweeps, wandb\
**Created:** [August 11, 2022, 5:43am UTC](https://community.wandb.ai/t/key-error-in-wandb-config-when-using-wandb-sweep-in-pytorch/2898 "2022-08-11T05:43:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hmishfaq](https://sea2.discourse-cdn.com/flex020/user_avatar/community.wandb.ai/hmishfaq/32/930_2.png) [@hmishfaq](https://community.wandb.ai/u/hmishfaq)\
**Post date:** [August 11, 2022, 5:43am UTC](https://community.wandb.ai/t/key-error-in-wandb-config-when-using-wandb-sweep-in-pytorch/2898/1 "2022-08-11T05:43:04Z")

</div>

I am trying to run this codebase [GitHub - devzhk/LMCTS](https://github.com/devzhk/LMCTS). To run hyperparameter sweep, I ran the following:

```auto
wandb sweep sweep/simulation/linear-lmcts.yaml
wandb agent [agent id]

```

[The config file](https://github.com/devzhk/LMCTS/blob/master/sweep/simulation/linear-lmcts.yaml) seems to have the same style as the sweep tutorial in W&B website has. However, when I run sweep command as above, I get the following error

```auto
2022-08-10 02:12:55,113 - wandb.wandb_agent - INFO - Running runs: []
2022-08-10 02:12:55,352 - wandb.wandb_agent - INFO - Agent received command: run
2022-08-10 02:12:55,362 - wandb.wandb_agent - INFO - Agent starting run with config:
	T: 10000
	algo: LMCTS
	beta_inv: 0.0001
	datapath: data/gaussian50-20-1-1.pt
	dim_context: 20
	func: linear
	lr: 0.1
	model: linear
	num_arm: 50
	num_iter: 70
	sigma: 0.5
2022-08-10 02:12:55,372 - wandb.wandb_agent - INFO - About to run command: /usr/bin/env python3 run_simulation.py
2022-08-10 02:13:00,385 - wandb.wandb_agent - INFO - Running runs: ['ngxmksza']
/home/mila/i/ishfaqha/code/LMCTS/LCMTS/lib/python3.7/site-packages/sklearn/feature_extraction/image.py:167: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  dtype=np.int):
Random seed: 720
Traceback (most recent call last):
  File "run_simulation.py", line 107, in <module>
    run(config, args)
  File "run_simulation.py", line 41, in run
    data = torch.load(config['datapath'])
KeyError: 'datapath'

```

Shouldn’t it automatically parse the config?

---

<div class="post-metadata">

**Author:** ![mohammadbakir](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@mohammadbakir](https://community.wandb.ai/u/mohammadbakir)\
**Post date:** [August 11, 2022, 4:36pm UTC](https://community.wandb.ai/t/key-error-in-wandb-config-when-using-wandb-sweep-in-pytorch/2898/2 "2022-08-11T16:36:38Z")

</div>

Hi @hmishfaq , followed up on this in the git thread as well. You are correct that wandb will automatically parse the config. In line [27](https://github.com/devzhk/LMCTS/blob/97114fc7a2160ba5d45c9ef483d2284497f81be6/run_simulation.py#L27) of `run_simulation.py` ,the condition `if args.log and wandb` isn’t satisfied as the default `fixed-linear-lmcts.yaml` [file](https://github.com/devzhk/LMCTS/blob/master/sweep/simulation/linear-lmcts.yaml) doesn’t include the command `- log` , thus wandb init is never called. See the [LMCTS README.md](https://github.com/devzhk/LMCTS/blob/master/README.md) for more info

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/wandb/original/1X/366b649231631dbab896843020da0056074ac79d.png) [@system](https://community.wandb.ai/u/system)\
**Post date:** [October 10, 2022, 4:37pm UTC](https://community.wandb.ai/t/key-error-in-wandb-config-when-using-wandb-sweep-in-pytorch/2898/3 "2022-10-10T16:37:09Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
