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.

wandb.watch does not work with torch/jit/ScriptModules

See original GitHub issue

Hi, first of all, I would like to say huge thank you for a great tool, I really like wandb and it helps me a lot.

Here is a problem, which I get while working with wandb

  • Weights and Biases version: wandb, version 0.8.12
  • Python version: Python 3.6.1
  • Operating System: Darwin

Description

wandb.watch does not work with any models, which contains layer with ScriptModules

What I Did

I am working with detection module from torchvision https://github.com/pytorch/vision/tree/master/references/detection Here is a small example of a problem: If you run this code

import wandb
from torchvision.models.detection import fasterrcnn_resnet50_fpn
wandb.init(project='common')
model = fasterrcnn_resnet50_fpn()
wandb.watch(model)

you will get this error

wandb: Started W&B process version 0.8.12 with PID 38398
wandb: Local directory: wandb/run-20190928_163622-ngu052su
wandb: Syncing run curious-deluge-85: https://app.wandb.ai/truskovskiyk/common/runs/ngu052su
wandb: Run `wandb off` to turn off syncing.

Traceback (most recent call last):
  File "bug_rep.py", line 8, in <module>
    wandb.watch(model)
  File "/Users/kyryl/Projects/Kyryl/common/client/wandb/__init__.py", line 148, in watch
    model, criterion, graph_idx=idx)
  File "/Users/kyryl/Projects/Kyryl/common/client/wandb/wandb_torch.py", line 227, in hook_torch
    graph.hook_torch_modules(model, criterion, graph_idx=graph_idx)
  File "/Users/kyryl/Projects/Kyryl/common/client/wandb/wandb_torch.py", line 291, in hook_torch_modules
    self.hook_torch_modules(sub_module, prefix=name)
  File "/Users/kyryl/Projects/Kyryl/common/client/wandb/wandb_torch.py", line 291, in hook_torch_modules
    self.hook_torch_modules(sub_module, prefix=name)
  File "/Users/kyryl/Projects/Kyryl/common/client/wandb/wandb_torch.py", line 326, in hook_torch_modules
    sub_module.register_forward_hook(self.create_forward_hook(name, modules)))
  File "/Users/kyryl/vn/common/lib/python3.6/site-packages/torch/jit/__init__.py", line 1834, in fail
    raise RuntimeError(name + " is not supported on ScriptModules")
RuntimeError: register_forward_hook is not supported on ScriptM
wandb: Waiting for W&B process to finish, PID 38398
odules
wandb: Program failed with code 1. Press ctrl-c to abort syncing.
wandb: Process crashed early, not syncing files

The problem here is this module https://github.com/pytorch/vision/blob/master/torchvision/ops/misc.py#L135

Here is some toy example of how to reproduce

import wandb
import torch


class MyModule(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.weight = torch.nn.Parameter(torch.rand(2, 2))
        self.linear = torch.nn.Linear(2, 2)

    def forward(self, x):
        output = self.weight.mv(x)
        output = self.linear(output)
        return output


module = MyModule()
scripted_module = torch.jit.script(MyModule())


wandb.init(project='common')
wandb.watch(scripted_module)

ouput

wandb: Started W&B process version 0.8.12 with PID 38764
wandb: Local directory: wandb/run-20190928_164606-sdgo358a
wandb: Syncing run wobbly-crypt-89: https://app.wandb.ai/truskovskiyk/common/runs/sdgo358a
wandb: Run `wandb off` to turn off syncing.

Traceback (most recent call last):
  File "bug_rep.py", line 34, in <module>
    wandb.watch(scripted_module)

wandb: Waiting for W&B process to finish, PID 38764
  File "/Users/kyryl/Projects/Kyryl/common/client/wandb/__init__.py", line 148, in watch
    model, criterion, graph_idx=idx)
  File "/Users/kyryl/Projects/Kyryl/common/client/wandb/wandb_torch.py", line 227, in hook_torch
    graph.hook_torch_modules(model, criterion, graph_idx=graph_idx)
  File "/Users/kyryl/Projects/Kyryl/common/client/wandb/wandb_torch.py", line 326, in hook_torch_modules
    sub_module.register_forward_hook(self.create_forward_hook(name, modules)))
  File "/Users/kyryl/vn/common/lib/python3.6/site-packages/torch/jit/__init__.py", line 1834, in fail
    raise RuntimeError(name + " is not supported on ScriptModules")
RuntimeError: register_forward_hook is not supported on ScriptModules
wandb: Program failed with code 1. Press ctrl-c to abort syncing.
wandb: Process crashed early, not syncing files

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
DennisCraandijkcommented, Oct 29, 2019

@cvphelps do you an update on this? I’m running into the same problem.

0reactions
vanpeltcommented, Sep 15, 2021

@mehraveh2016 you’ll need to set the environment variable WANDB_WATCH=false to disable gradient logging until we’re able to support custom Jit models.

Read more comments on GitHub >

github_iconTop Results From Across the Web

wandb.watch does not work with torch/jit/ScriptModules #580
Hi, I am now using the client wandb-ng on windows. For this client, there is no problem. However I don't know if the...
Read more >
Wandb.watch with pytorch not logging anything - W&B Help
Hi, I am trying to use wandb.watch for a pytorch model, ... Wandb.watch not logging parameters; When is one supposed to run wandb.watch...
Read more >
1.0.0 PDF - PyTorch Lightning Documentation
In this guide we'll show you how to organize your PyTorch code into Lightning in 2 steps. Organizing your code with PyTorch Lightning...
Read more >
Rami/multi-label-class-github-issues-text-classification
Bug My code that uses torch.no_grad stopped working after updating to 1.2 (I'm doing ... "pl+wandb: Hanging during "cleaning up ddp environment" when...
Read more >
CHANGELOG.md · zhiqwang/pytorch-lightning - Gitee.com
... torch.jit scripted submodules (#6511); Fixed when Train loop config was ... Fixed WandbLogger.watch - use of the watch method without importing wandb...
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