flm serve: /v1/completions and other routes run outside the NPU queue and race with model swaps
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 48/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- cpp
- 领域
- api, backend, performance
调研方向
Start in src/server/server.cpp at requires_npu_access(), then trace the route dispatch in src/src/main.cpp and the handlers in src/server/rest_handler.cpp, especially completion, embeddings, model loading, and /api/ps. Confirm which engine accesses and model-tag reads can overlap, then define done as serialized NPU work and a synchronized /api/ps view without changing unrelated routes.
由索引模型根据 Issue 内容生成。
描述
Everything below comes from reading the source on main at 39ff855. None of it has been measured.
What looks wrong
requires_npu_access() decides which requests go through the single NPU queue (server.cpp:160-170). It lists /api/generate, /api/chat, /v1/chat/completions, /v1/audio/transcriptions and /v1/embeddings. Every other route runs directly on whichever of the 10 I/O threads accepted it (main.cpp:624), concurrently with whatever holds the NPU. Three of those routes touch state that the queued routes change:
-
POST /v1/completionsis missing from the list, but it does inference.handle_openai_completioncallsensure_model_loaded(),insert()andgenerate()on the sharedauto_chat_engine(rest_handler.cpp:1423-1490). A/v1/completionsrequest that arrives while a/v1/chat/completionsrequest is decoding would therefore run on the same engine and the same NPU at the same time. If it names a different model, it would reset the engine that the other request is using (:385-388). -
POST /api/embeddingsis also missing, while its twin/v1/embeddingsis listed. Both call the samehandle_embeddings, which runs the embedding model on the NPU. -
GET /api/psreadscurrent_model_tag(:1017-1022). Meanwhile,ensure_model_loadedassigns thatstd::stringon a queued request's thread (:411,:418). A concurrent read of astd::stringduring assignment is a data race, and undefined behaviour in C++.We have measured one consequence on our patched build. The tag stays at the
model-fakersentinel until a first load finishes. Polling/api/pswhile that load ran hit the sentinel lookup (a separate bug: undefined behaviour inrectify_model_tag) on 19 of 23 polls.
Expected
Anything that uses or swaps auto_chat_engine or the embedding engine goes through the NPU queue. For a read-only route like /api/ps, a snapshot of (engine loaded, tag) published under a mutex, or atomically, would be enough.
Suggested fix
- Add
/v1/completionsand/api/embeddingstorequires_npu_access(). - Give
/api/psa synchronised view of the loaded tag.
We have not written a patch for this yet. We found it while fixing /api/ps downstream. That fix (https://github.com/noamsto/nix-amd-ai/blob/46d7a73c1044435cec0ff08410e1a3bc87cbc544/pkgs/fastflowlm/patches/ps-loaded-models.patch) avoids the sentinel lookup, but it does not add synchronisation.
The heap-corruption reports in #608 involve concurrent requests. We haven't connected them to this, so this is only a pointer.
Environment
Found by reading the source; checked against main at 39ff855 and v1.0.6.
- 主要语言
- C++
- 星标
- 2.1k
- 派生
- 184
- 平均合并
- 12 小时 22 分钟
- 30 天内合并 PR
- 239
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ROCm/FastFlowLM 的其他 Issue
-
Update Gemma tokenizer.json after Google's recent fix可能已有人在做 @four1er 于 6 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
ROCm/FastFlowLM#1057 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
ROCm/FastFlowLM#757 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
ROCm/FastFlowLM#744 · 2 条评论 ·
维护者通常 1 天内回复
-
Truncated tool call is emitted as a complete one (unterminated heredoc reaches the client)可能已有人在做 @Javinator9889 于 72 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
ROCm/FastFlowLM#741 · 1 条评论 ·
维护者通常 1 天内回复
-
Download timeout可能已有人在做 @stdevPavelmc 于 200 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 74/100
ROCm/FastFlowLM#520 · 7 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
bug good first issue help wanted
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
difficulty:easy func:gui prio:normal type:bug
难度 2/5 1-3 小时 新手友好度 78/100
NatronGitHub/Natron#2118 ·
维护者通常 1 天内回复
-
Bug
难度 1/5 1 小时以内 新手友好度 82/100
-
bug difficulty:easy prio:low
难度 2/5 1-3 小时 新手友好度 72/100
NatronGitHub/openfx-io#523 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
ArduPilot/ardupilot_gazebo#195 ·