BUG: HuggingFaceChatTarget runs model.generate() on the event loop

未關閉 適合新手
#4,046 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 2 天內回覆

@Shizoqua 已經在處理了。

開始於 2026年11月7日。

  • #4047 來自 @Shizoqua —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
76/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
huggingface, python
領域
ai, backend

研究方向

找出 HuggingFaceChatTarget._send_prompt_to_target_async,並檢查它呼叫 self.model.generate(...) 的位置;issue #2211 可能提供將模型工作移出事件迴圈的背景資訊。透過修補 generate 使其等待一個 threading.Event,同時讓另一個工作嘗試在 asyncio.sleep(0.05) 後釋放該事件,來重現停滯。生成期間其他 asyncio 工作能夠執行時,即為完成。

由索引模型根據 Issue 內容生成。

描述

Describe the bug

HuggingFaceChatTarget._send_prompt_to_target_async calls self.model.generate(...) directly inside the async method. Local generation can take seconds to minutes, and it blocks the event loop the whole time, so every other attack, scorer and target call in the same run stalls. #2211 moved model loading off the event loop, but generation still runs on it.

Steps/Code to Reproduce

In a unit test, patch the loaded model's generate to wait on a threading.Event, then send a prompt while another task tries to set that event after asyncio.sleep(0.05). The other task never runs until generate returns.

Expected Results

Other tasks keep running while the model generates.

Actual Results

The event loop is blocked for the full generation time.

Versions

PyRIT main.

主要語言
Python
星號
4.7k
分支
1k
平均合併
2 天 7 小時
30 天內合併 PR
512

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 有 Pull Request 範本
  • 沒有貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

microsoft/PyRIT 的其他 Issue

查看 microsoft/PyRIT 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。