model(x) vs model.forward(x)

Posted by yaohong on Monday, May 24, 2021

TOC

model(x) vs model.forward(x)

__call__ magic method in nn.Module will invoke forward() method and take care of hooks and states that python allows, so we should use model(x) rather than call model.forward(x) directly.

REFERENCE:

1.Why there are different output between model.forward(input) and model(input)

2.Calling forward function without .forward()

3.torch.nn.module codes

「点个赞」

Yaohong

点个赞

使用微信扫描二维码完成支付