Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion graph_net/torch/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

torch._dynamo.config.capture_scalar_outputs = True
torch._dynamo.config.capture_dynamic_output_shape_ops = True
torch._dynamo.config.capture_sparse_compute = True
try:
torch._dynamo.config.capture_sparse_compute = True
except AttributeError:
pass
torch._dynamo.config.raise_on_ctx_manager_usage = False
torch._dynamo.config.allow_rnn = True

Expand Down
6 changes: 5 additions & 1 deletion graph_net/torch/sample_pass/backward_graph_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ def __call__(self):
module, forward_inputs = get_torch_module_and_inputs(
self.model_path, use_dummy_inputs=False, device=self.device
)
module.train()
module.eval()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eval模式下不会生成反向图吧?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model.eval() 不会禁用梯度计算,只有 torch.no_grad() / torch.inference_mode() 才会。eval 仅改变特定层的前向行为(dropout → identity,BatchNorm → 用 running stats 而非 batch stats),反向传播完全正常。而且使用 eval 模式反而更好

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eval模式下不会有反向图吧?


eval_forward_dir = os.path.join(
self.output_dir, "eval_forward", self.rel_model_path
)
if not os.path.exists(eval_forward_dir):
shutil.copytree(self.model_path, eval_forward_dir)

forward_inputs = [
inp.detach().clone() if isinstance(inp, torch.Tensor) else inp
for inp in forward_inputs
]
forward_inputs = self.set_requires_grad_for_forward_inputs(
self.model_path, module, forward_inputs
)
Expand Down
Loading