# Wandb sweep showing null for loss

**URL:** <https://community.wandb.ai/t/wandb-sweep-showing-null-for-loss/7188>\
**Category:** W&B Help\
**Tags:** sweeps\
**Created:** [July 11, 2024, 4:35pm UTC](https://community.wandb.ai/t/wandb-sweep-showing-null-for-loss/7188 "2024-07-11T16:35:24Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![thilak-cm212](https://avatars.discourse-cdn.com/v4/letter/t/f19dbf/32.png) [@thilak-cm212](https://community.wandb.ai/u/thilak-cm212)\
**Post date:** [July 11, 2024, 4:35pm UTC](https://community.wandb.ai/t/wandb-sweep-showing-null-for-loss/7188/1 "2024-07-11T16:35:24Z")

</div>

I’m having trouble fixing wandb logging for sweeps. see screenshot for output

 ![image](https://us1.discourse-cdn.com/flex020/uploads/wandb/original/2X/4/4dbfe04f425470e2b736922bdcd99d0dc9f0d43f.jpeg)

I’ve look at topics for the same error but I’m still unable to figure out how to make it work. thanks in advance to whoever takes their time to help me out.

when I want to run sweeps, I set the global var sweep as true, and it runs these functions.  
here’s my code snippet for the sweep train function

def sweep\_train():  
print(‘Setting up sweep…’)  
sweep\_iteration = 1

```
def train(config=None):
    nonlocal sweep_iteration
    with wandb.init(config=config):
        config = wandb.config
        print('this is the config for this sweep')
        print(config)
        print(f"Sweep number: {sweep_iteration}")

        spxdata = pd.read_csv('spxdata.csv', parse_dates=['Date'], index_col='Date')
        print(f'Data shape: {spxdata.shape}')
        x = spxdata[features]
        y = spxdata[metric]

        x_train, y_train = x[:-test_size_days], y[:-test_size_days]
        x_test, y_test = x[-test_size_days:], y[-test_size_days:]

        feature_scaler = StandardScaler()
        x_train_scaled = feature_scaler.fit_transform(x_train)
        x_test_scaled = feature_scaler.transform(x_test)

        target_scaler = StandardScaler()
        y_train_scaled = target_scaler.fit_transform(y_train.values.reshape(-1, 1))
        y_test_scaled = target_scaler.transform(y_test.values.reshape(-1, 1))

        model, history = train_model(x_train_scaled, y_train_scaled, x_test_scaled, y_test_scaled)
        print(f'Loss: {history["loss"][-1]}, Val Loss: {history["val_loss"][-1]}')
        wandb.log({"loss": history['loss'][-1], "val_loss": history['val_loss'][-1]})
        print('im inside the train function now')

        sweep_iteration += 1

with open('sweep.yaml') as file:
    sweep_config = yaml.safe_load(file)
sweep_id = wandb.sweep(sweep_config)
wandb.agent(sweep_id, function=train, count=sweep_count)
print('im done now')

```

if **name** == ‘ **main** ’:  
if sweep:  
sweep\_train()  
else:  
start\_time = time.time()  
main()  
print(f’Time taken: {time.time() - start\_time:.2f} seconds’)

here’s my sweep.yaml file content  
method: bayes  
metric:  
name: val\_loss  
goal: minimize  
parameters:  
batch\_size:  
values: [16, 32, 64]  
epochs:  
values: [10,]  
learning\_rate:  
max: 0.01  
min: 0.0001  
dropout:  
min: 0.2  
max: 0.5

if you need to see any other code lmk I’m willing to share. but for now I hope this is sufficient for debugging

---

<div class="post-metadata">

**Author:** ![artsiom](https://sea2.discourse-cdn.com/flex020/user_avatar/community.wandb.ai/artsiom/32/1001_2.png) [@artsiom](https://community.wandb.ai/u/artsiom)\
**Post date:** [July 15, 2024, 7:41pm UTC](https://community.wandb.ai/t/wandb-sweep-showing-null-for-loss/7188/2 "2024-07-15T19:41:23Z")

</div>

Hey @thilak-cm212, thank you for writing. could you please point me to the workspace you are logging your sweeps to? What is your username, project name and the sweep name you are running the sweeps in?

---

<div class="post-metadata">

**Author:** ![thilak-cm212](https://avatars.discourse-cdn.com/v4/letter/t/f19dbf/32.png) [@thilak-cm212](https://community.wandb.ai/u/thilak-cm212)\
**Post date:** [July 17, 2024, 4:37pm UTC](https://community.wandb.ai/t/wandb-sweep-showing-null-for-loss/7188/3 "2024-07-17T16:37:59Z")

</div>

username: thilak-cm212  
project name: Neural Networks Hyperparameter Tuning

funny thing is, when you replied, the issue seems to have fixed itself. but now I’m gettin null values again. so I think until I understand what the issue is I’m not sure ‘just hoping that the issue fixes itself’ like it did last time is a reliable strategy.  
anyway, sweep 2z5kq8wx shows null values, its my latest run. whereas, look at zaabf7f8. this works just fine.  
here’s a link in case you can’t find the sweeps webpage

> **[thilak](https://wandb.ai/thilak/Neural%20Networks%20Hyperparameter%20Tuning/sweeps/zaabf7f8?nw=nwuserthilakcm212)**
>
> Weights & Biases, developer tools for machine learning

---

<div class="post-metadata">

**Author:** ![artsiom](https://sea2.discourse-cdn.com/flex020/user_avatar/community.wandb.ai/artsiom/32/1001_2.png) [@artsiom](https://community.wandb.ai/u/artsiom)\
**Post date:** [July 18, 2024, 5:18pm UTC](https://community.wandb.ai/t/wandb-sweep-showing-null-for-loss/7188/4 "2024-07-18T17:18:26Z")

</div>

Hey @thilak-cm212! Than you for sending over the link.

Looking at this sweep here:

> **[thilak](https://wandb.ai/thilak/Neural%20Networks%20Hyperparameter%20Tuning/sweeps/2z5kq8wx/table)**
>
> Weights & Biases, developer tools for machine learning

I do see that all of your runs are currently marked as crashed and none of them have any validation loss recorded. Are you expecting to see something different on your side?

---

<div class="post-metadata">

**Author:** ![thilak-cm212](https://avatars.discourse-cdn.com/v4/letter/t/f19dbf/32.png) [@thilak-cm212](https://community.wandb.ai/u/thilak-cm212)\
**Post date:** [July 18, 2024, 9:01pm UTC](https://community.wandb.ai/t/wandb-sweep-showing-null-for-loss/7188/5 "2024-07-18T21:01:50Z")

</div>

yes I see that these runs crashed, explaining the null values in the plot. however, on running my code again, I see that it works.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/wandb/original/2X/c/c0ad1fc4d136ffdfb8341e292dca3bad10f018ea.jpeg)

my doubt is this now: what are potential reasons of run crashes (especially when it previously worked, because I haven’t changed the code from the last run crash and now it works). alternatively, do you have any suggestions on how to sorta reboot the system and check if it works? anything helps, thanks for the prompt replies @artsiom I really appreciate it

---

<div class="post-metadata">

**Author:** ![artsiom](https://sea2.discourse-cdn.com/flex020/user_avatar/community.wandb.ai/artsiom/32/1001_2.png) [@artsiom](https://community.wandb.ai/u/artsiom)\
**Post date:** [July 19, 2024, 10:33pm UTC](https://community.wandb.ai/t/wandb-sweep-showing-null-for-loss/7188/6 "2024-07-19T22:33:44Z")

</div>

Hey @thilak-cm212! Unfortunately, we will not know what exactly crashed your run unless we do some investigation.

Could you please provide the debug.log and debug-internal.log files associated with the run where you are running into this issue? These files should be located in the wandb folder relative to your working directory.

If you are able to see the graphs in the UI for the finished runs, the should not go away and go back to null. If they are going to become null, there is definitely something suspicious going on.

You are able to fully reset your workspace by clicking 3 dots in the top right corner of the screen and pressing `reset to default`, but it will also reset all of your workspace setup if you have edited your workspace before.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/wandb/original/2X/6/6f82f83ab36c6a884c57c6d9e56bba2969c61356.png)

---

<div class="post-metadata">

**Author:** ![thilak-cm212](https://avatars.discourse-cdn.com/v4/letter/t/f19dbf/32.png) [@thilak-cm212](https://community.wandb.ai/u/thilak-cm212)\
**Post date:** [July 22, 2024, 3:45pm UTC](https://community.wandb.ai/t/wandb-sweep-showing-null-for-loss/7188/7 "2024-07-22T15:45:11Z")

</div>

so I just noticed this:  
when I run the cli command ‘wandb disabled’ in terminal, and then run my script the values go to null. but when I have wandb enabled (by running ‘wandb enabled’ in terminal), the sweep works just fine.  
for now it seems that this is what is crashing the runs and not reflecting the loss value in the sweep graphs.  
I’ll test it for a few days and see if I face any errors with ‘wandb enabled’.  
do you know why ‘wandb disabled’ is causing this issue?

---

<div class="post-metadata">

**Author:** ![artsiom](https://sea2.discourse-cdn.com/flex020/user_avatar/community.wandb.ai/artsiom/32/1001_2.png) [@artsiom](https://community.wandb.ai/u/artsiom)\
**Post date:** [July 22, 2024, 7:02pm UTC](https://community.wandb.ai/t/wandb-sweep-showing-null-for-loss/7188/8 "2024-07-22T19:02:45Z")

</div>

Thank you for testing it out. I am assuming this happens because once you disable wandb, none of the info gets sent to the wandb cloud and therefore the runs are marked as crashed. Same situation as we cannot run sweeps in in wandb offline mode, because the sweeps controller is up in the cloud and cannot control sweeps configs in the offline mode.

I will follow up with you on wednesday to make sure that this is the issue, and you are unblocked now.

---

<div class="post-metadata">

**Author:** ![artsiom](https://sea2.discourse-cdn.com/flex020/user_avatar/community.wandb.ai/artsiom/32/1001_2.png) [@artsiom](https://community.wandb.ai/u/artsiom)\
**Post date:** [July 24, 2024, 9:17pm UTC](https://community.wandb.ai/t/wandb-sweep-showing-null-for-loss/7188/9 "2024-07-24T21:17:42Z")

</div>

Hi there, I wanted to follow up on this request. Please let us know if we can be of further assistance or if your issue has been resolved.

---

<div class="post-metadata">

**Author:** ![thilak-cm212](https://avatars.discourse-cdn.com/v4/letter/t/f19dbf/32.png) [@thilak-cm212](https://community.wandb.ai/u/thilak-cm212)\
**Post date:** [July 24, 2024, 9:44pm UTC](https://community.wandb.ai/t/wandb-sweep-showing-null-for-loss/7188/10 "2024-07-24T21:44:03Z")

</div>

hey, thanks a lot for your help. the issue is resolved.

---

<div class="post-metadata">

**Author:** ![artsiom](https://sea2.discourse-cdn.com/flex020/user_avatar/community.wandb.ai/artsiom/32/1001_2.png) [@artsiom](https://community.wandb.ai/u/artsiom)\
**Post date:** [July 26, 2024, 2:25pm UTC](https://community.wandb.ai/t/wandb-sweep-showing-null-for-loss/7188/11 "2024-07-26T14:25:48Z")

</div>

Sounds great! I will go ahead and close this ticket out. If you would like to reopen the conversation, please let us know! Unfortunately, at the moment, we do not receive notifications if a thread reopens on Discourse. So, please feel free to create a new ticket regarding your concern if you’d like to continue the conversation.
