Skip to content

The input of branch_net is set to requires_grad #2011

@luoyh15

Description

@luoyh15

I notice that the input of branch_net is set to requires_grad in the deepxde. Is it nesseary?
As I understand, the input of branch_net's grad is not used.
The result should not be affected, while maybe slow down the training step.

The piece of code is from deepxde/model.py 305-317, and shows the setting step.

        def outputs(training, inputs):
            self.net.train(mode=training)
            with torch.no_grad():
                if isinstance(inputs, tuple):
                    inputs = tuple(
                        map(lambda x: torch.as_tensor(x).requires_grad_(), inputs)
                    )
                else:
                    inputs = torch.as_tensor(inputs)
                    inputs.requires_grad_()
            # Clear cached Jacobians and Hessians.
            grad.clear()
            return self.net(inputs)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions