Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Logic._forward() method a public method #772

Open
linshokaku opened this issue Oct 27, 2023 · 0 comments · May be fixed by #775
Open

Make Logic._forward() method a public method #772

linshokaku opened this issue Oct 27, 2023 · 0 comments · May be fixed by #775
Assignees
Labels
cat:enhancement New feature or request

Comments

@linshokaku
Copy link
Member

When implementing the ML pipeline using the engine function of PPE, the next part is essentially where the model calculates the loss.

def _forward(self, model: torch.nn.Module, batch: Any) -> Any:
if isinstance(batch, tuple) and hasattr(batch, "_fields"):
# namedtuple
return model(batch)
if isinstance(batch, dict):
return model(**batch)
if isinstance(batch, (list, tuple)):
return model(*batch)
return model(batch)

Currently, it is abstracted to work for batches of various formats, but improving customization in this area would make it easier for users to understand the behavior with minimal code changes.

Inheriting and modifying the _forward() method also makes it possible to manage nn.Module, which implements only inference functions that do not require labels, without wrapping it in nn.Module for training. Specifically, this can be achieved by executing the loss function inside the _forward() method.

@kmaehashi kmaehashi added the cat:enhancement New feature or request label Oct 27, 2023
@linshokaku linshokaku linked a pull request Oct 30, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cat:enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants