Skip to content

Auto unload on timeout - #506

Open
brycehenson wants to merge 10 commits into
remsky:masterfrom
brycehenson:auto_unload_on_timeout
Open

Auto unload on timeout#506
brycehenson wants to merge 10 commits into
remsky:masterfrom
brycehenson:auto_unload_on_timeout

Conversation

@brycehenson

@brycehenson brycehenson commented Aug 17, 2026

Copy link
Copy Markdown

adds unload after a period of inactivity.

      - MODEL_AUTO_UNLOAD_ENABLED=true
      - MODEL_AUTO_UNLOAD_TIMEOUT_SECONDS=30

request for feeback

Would you prefer a different flag name ?

TODO

  • test on gpu
  • test on cpu
  • test on rocm

@brycehenson
brycehenson marked this pull request as ready for review August 17, 2026 08:05
@remsky

remsky commented Aug 18, 2026

Copy link
Copy Markdown
Owner

Nice work, careful timer handling. Two things:

  1. generate_from_phonemes in tts_service.py uses the backend directly, so the idle timer could unload the model mid-use. Can we move the begin/end pair into one context manager e.g

    # model_manager.py
    @asynccontextmanager
    async def hold(self):
        await self._begin_request()
        try:
            yield
        finally:
            await self._end_request()

    then both generate() and generate_from_phonemes wrap their work in async with manager.hold():. One path for the accounting, less code overall.

  2. On the flag: I think we can drop MODEL_AUTO_UNLOAD_ENABLED and let MODEL_AUTO_UNLOAD_TIMEOUT_SECONDS=0 (default) mean off. _auto_unload_enabled() already treats timeout <= 0 that way if I follow.

brycehenson and others added 2 commits August 20, 2026 05:34
Centralize request timeout accounting  into ModelManager.hold(). Use it for generate_from_phonemes().

Remove MODEL_AUTO_UNLOAD_ENABLED. Replace it with MODEL_AUTO_UNLOAD_TIMEOUT_SECONDS=0 is the default/off state.
@brycehenson

brycehenson commented Aug 20, 2026

Copy link
Copy Markdown
Author

Thanks, good points. Implemented 1 and 2.

validation with unit tests:

  • 276 passed, 17 deselected, 7 warnings in 3.51s

Validation with integrations tests:

  • docker compose -f docker/docker-compose.test.yml up --build --abort-on-container-exit --exit-code-from test-client
  • Result: 17 passed in 44.78s

ps: Thank you for building and maintaining such a great tool !

brycehenson added 2 commits August 20, 2026 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants