Coder Social home page Coder Social logo

Comments (6)

yoshitomo-matsubara avatar yoshitomo-matsubara commented on May 24, 2024

Hi @arbellea

If you are using a module wrapped by DataParallel or DistributedDataParallel, you should provide the right device when instantiating ForwardHookManager

For instance, you can replace

device = torch.device('cpu')
forward_hook_manager = ForwardHookManager(device)

with

device = torch.device('cuda')
forward_hook_manager = ForwardHookManager(device)

in this example notebook.

from torchdistill.

arbellea avatar arbellea commented on May 24, 2024

Thanks, but that is not what I meant
After further digging, I saw that pop_io_dict() gathers the outputs from all devices.
Since I would like to use this as a submodule of a network on parallel gpus, I need to extract only the outputs from the relevant gpu.
I wrote a small fuction that does that:

    def get_io_dict_from_device(self, device):
        device_io_dict = dict()
        for module_path, module_io_dict in self.io_dict.items():
            device_io_dict[module_path] = dict()
            for io_type in list(module_io_dict.keys()):
                sub_dict = module_io_dict[io_type]
                values = sub_dict[device.index]
                device_io_dict[module_path][io_type] = values
        return device_io_dict

and it works fine

from torchdistill.

yoshitomo-matsubara avatar yoshitomo-matsubara commented on May 24, 2024

@arbellea Thank you for the clarification.
Can I ask you for what purpose you'd like extract device-wise input/output?
I didn't expect the forward hook manager to be used in that way, but if that sounds useful for other users, I may want to update it.

from torchdistill.

arbellea avatar arbellea commented on May 24, 2024

I want to take a pretrained network, let's say ResNet, and use that as a backbone for my model.
I would like to take several intermediate layers and continue computations. For example, a U-Net with a ResNet backbone.

from torchdistill.

arbellea avatar arbellea commented on May 24, 2024

What I do now is download the code and modify it so that I can extract the intermediate layers...
But your code is much more convinent!

from torchdistill.

yoshitomo-matsubara avatar yoshitomo-matsubara commented on May 24, 2024

But your code is much more convinent!

Great to hear that :)
It may make sense, and I'll shortly update mine, mentioning this issue.

As you might have known, IntermediateLayerGetter in torchvision might also be something you're looking for, as it's used in R-CNN object detectors using ResNet and FPN as their backbones.

from torchdistill.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.