Skip to content

Conversation

@Neet-Nestor
Copy link
Contributor

@Neet-Nestor Neet-Nestor commented Aug 4, 2024

Manually aborting reload

This PR updates the engine reload() and unload() methods to allow users to abort an uncompleted reload() by either:

  • call unload() any time before reload() completed
  • call reload() again before the previous reload() completed

Example added in examples/abort-reload.
Console output:

Start to fetch params
get_started.js:16 Fetching param cache[0/108]: 28MB fetched. 0% completed, 1 secs elapsed. It can take a while when we first visit this page to populate the cache. Later refreshes will become faster.
get_started.js:28 calling unload
engine.ts:154 Reload() is aborted. Failed to execute 'add' on 'Cache': Cache.add() was aborted

Related issues:
#484
#499

Note on unload() and unexpected device lost error

Previously, we had an issue where a device lost error is reported when we simply switch a model intentionally (i.e. calling reload()). This is because unload() sets deviceLostIsError back to true immediately after calling this.pipeline.dispose(), which destroys the WebGPU device internally. However, WebGPU is asynchronous and may not finish after dispose() returns. This PR also fixes this issue by making unload() wait until the device is actually destroyed by introducing LLMChatPipeline.sync(). Otherwise, the old device's device-lost callback may still be triggered. See apache/tvm#17250

@CharlieFRuan
Copy link
Member

Currently blocked by unexpected deviceLostError. Will fix that before merging this PR.

@CharlieFRuan
Copy link
Member

Depends on apache/tvm#17250

@CharlieFRuan CharlieFRuan changed the title [Engine] Allow manually aborting reloading [Engine] Allow manually aborting reload, fix unexpected deviceLostError Aug 6, 2024
@CharlieFRuan CharlieFRuan merged commit ddac6d1 into main Aug 8, 2024
Copy link
Member

@CharlieFRuan CharlieFRuan left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

CharlieFRuan added a commit that referenced this pull request Aug 8, 2024
No breaking changes. The only diff is the following PR:

- #525
- This PR updates the engine reload() and unload() methods to allow
users to abort an uncompleted reload() by either:
    - call unload() any time before reload() completed
    - call reload() again before the previous reload() completed
- Besides, it fixes the previous issue where `device lost error` is
raised unexpectedly when user simply switches a model

### TVMjs
- To support the above PR, TVMjs is updated and compiled at
apache/tvm@1fcb620
- Difference:
  - Device error lost fix: apache/tvm#17250
  - Add AbortSignal to fetching APIs:
    - apache/tvm#17208
    - apache/tvm#17227
    - apache/tvm#17233
jingyi-zhao-01 pushed a commit to jingyi-zhao-01/web-llm that referenced this pull request Dec 8, 2024
…or (mlc-ai#525)

### Manually aborting reload
This PR updates the engine `reload()` and `unload()` methods to allow
users to abort an uncompleted `reload()` by either:

- call `unload()` any time before `reload()` completed
- call `reload()` again before the previous `reload()` completed

### Note on unload() and unexpected device lost error

Previously, we had an issue where a device lost error is reported when
we simply switch a model intentionally (i.e. calling `reload()`). This
is because `unload()` sets `deviceLostIsError` back to true immediately
after calling `this.pipeline.dispose()`, which destroys the WebGPU
device internally. However, WebGPU is asynchronous and may not finish
after `dispose()` returns. This PR also fixes this issue by making
`unload()` wait until the device is actually destroyed by introducing
`LLMChatPipeline.sync()`. 

---------

Co-authored-by: Charlie Ruan <[email protected]>
jingyi-zhao-01 pushed a commit to jingyi-zhao-01/web-llm that referenced this pull request Dec 8, 2024
No breaking changes. The only diff is the following PR:

- mlc-ai#525
- This PR updates the engine reload() and unload() methods to allow
users to abort an uncompleted reload() by either:
    - call unload() any time before reload() completed
    - call reload() again before the previous reload() completed
- Besides, it fixes the previous issue where `device lost error` is
raised unexpectedly when user simply switches a model

### TVMjs
- To support the above PR, TVMjs is updated and compiled at
apache/tvm@1fcb620
- Difference:
  - Device error lost fix: apache/tvm#17250
  - Add AbortSignal to fetching APIs:
    - apache/tvm#17208
    - apache/tvm#17227
    - apache/tvm#17233
atebites-hub pushed a commit to atebites-hub/web-llm that referenced this pull request Oct 4, 2025
…or (mlc-ai#525)

### Manually aborting reload
This PR updates the engine `reload()` and `unload()` methods to allow
users to abort an uncompleted `reload()` by either:

- call `unload()` any time before `reload()` completed
- call `reload()` again before the previous `reload()` completed

### Note on unload() and unexpected device lost error

Previously, we had an issue where a device lost error is reported when
we simply switch a model intentionally (i.e. calling `reload()`). This
is because `unload()` sets `deviceLostIsError` back to true immediately
after calling `this.pipeline.dispose()`, which destroys the WebGPU
device internally. However, WebGPU is asynchronous and may not finish
after `dispose()` returns. This PR also fixes this issue by making
`unload()` wait until the device is actually destroyed by introducing
`LLMChatPipeline.sync()`. 

---------

Co-authored-by: Charlie Ruan <[email protected]>
atebites-hub pushed a commit to atebites-hub/web-llm that referenced this pull request Oct 4, 2025
No breaking changes. The only diff is the following PR:

- mlc-ai#525
- This PR updates the engine reload() and unload() methods to allow
users to abort an uncompleted reload() by either:
    - call unload() any time before reload() completed
    - call reload() again before the previous reload() completed
- Besides, it fixes the previous issue where `device lost error` is
raised unexpectedly when user simply switches a model

### TVMjs
- To support the above PR, TVMjs is updated and compiled at
apache/tvm@1fcb620
- Difference:
  - Device error lost fix: apache/tvm#17250
  - Add AbortSignal to fetching APIs:
    - apache/tvm#17208
    - apache/tvm#17227
    - apache/tvm#17233
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.

3 participants