pytorch / pytorch/ignite

Possible speed improvement

Open
#2,010 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Python
Stars
4.8k
Forks
726
Avg merge
5d 21h
Merged PRs (30d)
5

Description

Description

I recently noticed possible speed improvement when porting segmentation example to code-generator.

According to the docs, examples, helper functions, and tests, we are calling model.train() or model.eval() inside the process function given to the Engine.

And as per this line, I think model.train() or model.eval() gets called every iteration which I think not necessary.

https://github.com/pytorch/ignite/blob/0d21a0bfe0bb03980055f9748b827cf09a6faee3/ignite/engine/engine.py#L853

To my knowledge, .train() or .eval() is only needed when changing the context (e.g. training or evaluation).
And in pytorch example, model.train() or model.eval() gets called only once when changing context (training -> evaluation, or vice versa)

Possible solution

I think we can address in the ongoing High level API development or address in the refactor of Engine design.

Workaround

For now, we can workaround by calling model.train() before every training epoch and model.eval() before every evaluation epoch.

Thanks!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at ignite/engine/engine.py#L853 and trace how the Engine process function invokes model.train() or model.eval() each iteration. Compare the segmentation example, code-generator work, documented examples, helper functions, tests, and linked PyTorch VAE example; done means avoiding unnecessary per-iteration mode changes without breaking training or evaluation behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.