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.

NameError: name 'wandb' is not defined

See original GitHub issue

Describe the bug When try to train a classification model with wandb I get this error in google colab.

_Traceback (most recent call last): File “/usr/lib/python3.6/multiprocessing/process.py”, line 258, in _bootstrap self.run() File “/usr/lib/python3.6/multiprocessing/process.py”, line 93, in run self._target(*self._args, **self._kwargs) File “/usr/local/lib/python3.6/dist-packages/wandb/wandb_agent.py”, line 64, in start function() File “<ipython-input-8-9419ea4c148f>”, line 19, in trainMultiClass f1=f1_multiclass, acc=accuracy_score) File “/usr/local/lib/python3.6/dist-packages/simpletransformers/classification/classification_model.py”, line 269, in train_model **kwargs, File “/usr/local/lib/python3.6/dist-packages/simpletransformers/classification/classification_model.py”, line 373, in train wandb.init(project=args[“wandb_project”], config={**args}, **args[“wandb_kwargs”]) NameError: name ‘wandb’ is not defined

To Reproduce

import wandb
sweep_config = {
    'method': 'bayes', #grid, random, bayes
    'metric': {
      'name': 'eval_loss',
      'goal': 'minimize'   
    },
    'parameters': {  
        'learning_rate': {
            'values': [ 5e-5, 3e-5, 4e-5, 2e-5] #4e-5
        },
        'epochs': {
            'values': [1, 2] #2
        },
        'max_seq_length': { #174
            'min': 128,
            'max': 200
        },
        'train_batch_size': {
            'values': [8, 16, 32] #16
        },
        'warmup_ratio': { #0.07478
            'min': 0.04,
            'max': 0.08
        },
        'warmup_steps': {
            'min': 0,
            'max': 100,
        }
    }
}

sweep_id = wandb.sweep(sweep_config,project="sectors")

def f1_multiclass(labels, preds):
    return f1_score(labels, preds, average='micro')

def trainMultiClass():
  wandb.init()
  print("HyperParams=>>", wandb.config)
  num_labels = len(sector_to_id.keys())
  model = ClassificationModel('bert', 'bert-base-uncased', num_labels=11)
  model.train_model(train, output_dir='bert-uncased-sector', eval_df=test, args={'overwrite_output_dir': True, 
                                                                   'num_train_epochs': wandb.config.epochs,
                                                                   'learning_rate': wandb.config.learning_rate,
                                                                   'wandb_project': "sectors",
                                                                   'evaluate_during_training': True,
                                                                   'evaluate_during_training_steps': 100,
                                                                   'max_seq_length': wandb.config.max_seq_length,
                                                                   'train_batch_size': wandb.config.train_batch_size,
                                                                   'warmup_ratio': wandb.config.warmup_ratio,
                                                                   'warmup_steps': wandb.config.warmup_steps},
                    f1=f1_multiclass, acc=accuracy_score)

wandb.agent(sweep_id,function=trainMultiClass)

Expected behavior Four days ago it worked perfectly I didn’t get any error.

Desktop (please complete the following information):

  • Google colab

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
ximo1984commented, May 26, 2020

Now it’s working again. I don’t know if wandb changed something or I made a mistake because I had had two times “from simpletransformers.classification import ClassificationModel”.

Thanks for your excellent library.

0reactions
ximo1984commented, May 27, 2020

Maybe its a temporally error with colab or wandb. Thanks for your help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

wandb - how to get it really silent (weights and biases)
1 Answer 1 · From your code, I assume you are trying to silent the logs like this wandb os.environ["WANDB_SILENT"] = "true". however,...
Read more >
wandb - PyPI
A CLI and library for interacting with the Weights and Biases API.
Read more >
Launch Experiments with wandb.init - Documentation
1. You aren't logged in on this machine. Run wandb login on the command line. · 2. You've set an entity that doesn't...
Read more >
Quickstart - Documentation - Weights & Biases - Wandb
Initialize a new run in W&B in your Python script or notebook. wandb.init() will start tracking system metrics and console logs, right out...
Read more >
wandb.Run - Documentation - Weights & Biases
name. Returns the display name of the run. Display names are not guaranteed to be ... Define metric properties which will later be...
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