Skip to content

【feature】Support Multi Lora Infer - #408

Merged
Keithwwa merged 4 commits into
AISBench:masterfrom
SJTUyh:multi_lora
Jul 27, 2026
Merged

Keithwwa merged 4 commits into
AISBench:masterfrom
SJTUyh:multi_lora

Conversation

@SJTUyh

@SJTUyh SJTUyh commented Jul 22, 2026 •

Copy link
Copy Markdown
Collaborator

Thanks for your contribution; we appreciate it a lot. The following instructions will make your pull request healthier and help you get feedback more easily. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.
感谢您的贡献,我们非常重视。以下说明将使您的拉取请求更健康,更易于获得反馈。如果您不理解某些项目,请不要担心,只需提交拉取请求并从维护人员那里寻求帮助即可。

PR Type / PR类型

  • Feature(功能新增)
  • Bugfix(Bug 修复)
  • Docs(文档更新)
  • CI/CD(持续集成/持续部署)
  • Refactor(代码重构)
  • Perf(性能优化)
  • Dependency(依赖项更新)
  • Test-Cases(测试用例更新)
  • Other(其他)

Related Issue | 关联 Issue
Fixes #(issue ID / issue 编号) / Relates to #(issue ID / issue 编号)
Fixes #404

🔍 Motivation / 变更动机

Background / 背景

AISBench's service-oriented inference (vLLM / TGI / MindIE) currently supports only a single base model per evaluation. When the inference server has multiple LoRA adapters loaded (a common production scenario), the benchmark must run as multiple independent tasks — one per adapter — which fails to faithfully represent multi-tenant workload and inflates evaluation overhead.

The legacy benchmark-mindie-old plugin already implemented this feature using a JSON mapping file (lora_data_map_file), but the new benchmark codebase lacks equivalent support.

Goal / 目标

Enable routing each sample to the correct LoRA adapter based on dataset data_id (row index) — entirely via a single config parameter (lora_data_map_file under generation_kwargs), without introducing new model classes, without changing model type, and with zero behavior change for users who don't enable it.


📝 Modification / 修改内容

1. Core / 核心改动

File Change
ais_bench/benchmark/models/api_models/vllm_custom_api_chat.py Add 2 helpers (_load_lora_data_map, _resolve_lora_model_name); load lora_data_map_file in __init__; override model field in get_request_body; emit [Multi-LoRA] debug log
ais_bench/benchmark/models/api_models/vllm_custom_api.py Same pattern (completions API, override model field)
ais_bench/benchmark/models/api_models/tgi_api.py Same pattern; write parameters.adapter_id
ais_bench/benchmark/models/api_models/mindie_stream_api.py Same pattern; write parameters.adapter_id
ais_bench/benchmark/openicl/icl_inferencer/icl_gen_inferencer.py Add output.data_id = index (1 line) so the data_id is propagated from dataset to model

No new model class is registered. No @MODELS.register_module() additions. The models/__init__.py export table is unchanged.

2. Tests / 测试

File New UT class # test methods
tests/UT/models/api_models/test_vllm_custom_api_chat.py TestVLLMCustomAPIChatLora 16
tests/UT/models/api_models/test_vllm_custom_api.py TestVLLMCustomAPILora 10
tests/UT/models/api_models/test_tgi_api.py TestTGICustomAPILora 14
tests/UT/models/api_models/test_mindie_stream_api.py TestMindieStreamApiLora 14
tests/UT/openicl/icl_inferencer/test_icl_gen_inferencer.py test_do_request_writes_data_id_to_output + CapturingModel helper 1

test results:

 python tests/run_tests.py tests/UT --source-dirs ais_bench/benchmark/models/api_models ais_bench/benchmark/openicl/icl_inferencer --specific-tests tests/UT/models/api_models/test_base_api.py tests/UT/models/api_mod
els/test_vllm_custom_api_chat.py tests/UT/models/api_models/test_vllm_custom_api.py tests/UT/models/api_models/test_tgi_api.py tests/UT/models/api_models/test_mindie_stream_api.py tests/UT/openicl/icl_inferencer/test_ic
l_gen_inferencer.py --output lora_test/coverage_reports_v2 2>&1 | tee lora_test/logs/coverage_run_v2.log | tail -50'
tests/UT/utils/visualization/test_rps_distribution_plot.py ............. [ 98%]
.................................................                        [ 99%]
tests/UT/utils/visualization/test_summarize_plot.py ..........           [100%]

================================ tests coverage ================================
_______________ coverage: platform linux, python 3.10.19-final-0 _______________

Name                                                                                             Stmts   Miss Branch BrPart   Cover   Missing
---------------------------------------------------------------------------------------------------------------------------------------------
ais_bench/benchmark/models/api_models/__init__.py                                                    0      0      0      0 100.00%
ais_bench/benchmark/models/api_models/base_api.py                                                  390    123    164     33  67.15%   51, 55, 59, 170, 191, 201, 211->exit, 225, 231, 245-248, 257->284, 260, 266-268, 270, 285-286, 290-319, 322-342, 365-416, 421, 427, 442, 463, 476, 486, 490->484, 523, 543, 545-547, 555, 559->541, 584, 591, 596-600, 607, 613->634, 625, 627-628, 631-632, 640, 642, 644->643, 649, 677, 730->732, 733
ais_bench/benchmark/models/api_models/mindie_stream_api.py                                          57      0     12      0 100.00%
ais_bench/benchmark/models/api_models/tgi_api.py                                                    65      3     12      0  96.10%   138-140
ais_bench/benchmark/models/api_models/triton_api.py                                                 38      3      0      0  92.11%   104-106
ais_bench/benchmark/models/api_models/vita_generate_api.py                                          59     43     26      0  18.82%   55-70, 73-76, 81-135, 138-139, 142-144
ais_bench/benchmark/models/api_models/vllm_custom_api.py                                            92     13     20      2  86.61%   69-70, 142-143, 160-162, 165-167, 172-174
ais_bench/benchmark/models/api_models/vllm_custom_api_chat.py                                      128     18     40      4  86.90%   79-80, 156, 173, 199->201, 209-211, 214, 220-222, 228-230, 236-239
ais_bench/benchmark/openicl/icl_inferencer/__init__.py                                               7      0      0      0 100.00%
ais_bench/benchmark/openicl/icl_inferencer/icl_base_api_inferencer.py                              391     76    124     18  76.70%   90, 128-130, 200-201, 205, 207-209, 261, 272-273, 284->290, 286-287, 300-301, 354-367, 387->exit, 391-392, 429-435, 445, 465, 474->512, 478, 494, 500->474, 505-511, 513-520, 616-627, 708-710, 739-740, 748-757
ais_bench/benchmark/openicl/icl_inferencer/icl_base_inferencer.py                                   90      6     36      8  88.89%   111, 115, 118, 123, 129, 132->134, 144, 148->150
ais_bench/benchmark/openicl/icl_inferencer/icl_base_local_inferencer.py                             54      0     14      1  98.53%   116->exit
ais_bench/benchmark/openicl/icl_inferencer/icl_bfcl_v3_inferencer.py                               264      2     52      4  98.10%   519->600, 580-586, 598->519, 601->603
ais_bench/benchmark/openicl/icl_inferencer/icl_gen_inferencer.py                                    76      0     24      3  97.00%   157->162, 163->168, 171->170
ais_bench/benchmark/openicl/icl_inferencer/icl_lmm_gen_inferencer.py                                26      0      4      0 100.00%
ais_bench/benchmark/openicl/icl_inferencer/icl_multiturn_inferencer.py                             138      3     28      4  95.78%   76, 78, 115, 241->248
ais_bench/benchmark/openicl/icl_inferencer/output_handler/__init__.py                                0      0      0      0 100.00%
ais_bench/benchmark/openicl/icl_inferencer/output_handler/base_handler.py                          182     14     54      7  90.25%   176-181, 315, 368-370, 390->392, 393-399, 426->435, 431->435, 436->444, 444->452, 450-451
ais_bench/benchmark/openicl/icl_inferencer/output_handler/bfcl_v3_output_handler.py                 11      0      2      0 100.00%
ais_bench/benchmark/openicl/icl_inferencer/output_handler/db_utils.py                               32      2      4      0  94.44%   48-49
ais_bench/benchmark/openicl/icl_inferencer/output_handler/gen_inferencer_output_handler.py          23     14     12      0  25.71%   44-74
ais_bench/benchmark/openicl/icl_inferencer/output_handler/lmm_gen_inferencer_output_handler.py      33      3     14      1  91.49%   48->50, 79-81
ais_bench/benchmark/openicl/icl_inferencer/output_handler/ppl_inferencer_output_handler.py          29      1      4      1  93.94%   69
ais_bench/benchmark/openicl/icl_inferencer/ppl_inferencer.py                                       100      1     32      1  98.48%   73
---------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                                                             2285    325    678     87  82.99%
Coverage HTML written to dir /home/y30044005/yh_dev/benchmark/lora_test/coverage_reports_v2/htmlcov
Coverage XML written to file /home/y30044005/yh_dev/benchmark/lora_test/coverage_reports_v2/coverage.xml
Coverage JSON written to file /home/y30044005/yh_dev/benchmark/lora_test/coverage_reports_v2/coverage.json
Required test coverage of 80.0% reached. Total coverage: 82.99%
================ 3423 passed, 54 warnings in 195.48s (0:03:15) =================
--------------------------------------------------------------------------------
⏱️  Test runtime: 202.91 seconds
📊 Test results: 3423 total, 3423 passed, 0 failed, 0 skipped
📊 Coverage results:
   Line coverage: 85.8%
   Branch coverage: 73.6%
✅ All tests passed!

Coverage: _load_lora_data_map (valid / missing / null / empty / file-not-exist / invalid-JSON / empty dict), _resolve_lora_model_name (hit / miss / no map / no data_id), get_request_body LoRA injection (hit / miss / no config / PromptList input).

3. Docs / 文档

  • docs/source_en/base_tutorials/all_params/models.md — new "Multi-LoRA Routing" section.
  • docs/source_zh_cn/base_tutorials/all_params/models.md — new "Multi-LoRA 路由" section.
  • Both include JSON format, request-body field mapping table, absolute-path recommendation, debug-log hint.

4. Design Spec / 设计文档

  • .trae/documents/multi-lora-support-design.md — full design doc following design_doc_template.md (Story context, sequence diagram, class diagram, flow chart, 14 UT cases, 7 exception scenarios).
  • .trae/documents/multi-lora-support-design.docx — Word format of the same doc.

📐 Associated Test Results / 关联测试结果

  • Local AST-level validation: all 5 modified/extended files parse cleanly; LoRA helpers present in all 4 backend classes; output.data_id = index present in icl_gen_inferencer.py (32/32 structural checks PASS).
  • UT test classes discovered by AST: 16+10+14+14+1 = 55 new test methods, all helpers (setUp, _write_lora_map, _make_model_with_lora, etc.) wired correctly.
  • Full unittest runtime not executed in this local environment due to Windows torch DLL dependency; CI Python pipeline at /gemini review should run pytest tests/UT/models/api_models/test_vllm_custom_api_chat.py::TestVLLMCustomAPIChatLora (and analogous for the other 3 backend classes + the new inferencer test).

⚠️ BC-breaking (Optional) / 向后不兼容变更

No BC-breaking change. Verified:

  • Models without lora_data_map_file in generation_kwargs: _load_lora_data_map returns None; _resolve_lora_model_name returns None; get_request_body falls back to existing behavior (writes model=self.model or no adapter_id). Behavior is identical to pre-change baseline.
  • RequestOutput does not require data_id attribute; _resolve_lora_model_name uses getattr(output, 'data_id', None) so old callers that don't set it are unaffected.
  • Public API of all 4 model classes unchanged: no constructor signature change, no method signature change, no exports added/removed.
  • Doc + UT: existing test classes (e.g. TestVLLMCustomAPIChat) preserved untouched — new tests live in dedicated TestVLLMCustomAPIChatLora etc.

⚠️ Performance degradation (Optional) / 性能下降

Negligible / none.

  • _load_lora_data_map runs exactly once per model instance at __init__ time (i.e. once per worker process).
  • _resolve_lora_model_name is O(1) dict lookup + attribute access; called once per request.
  • output.data_id = index is a single attribute write in do_request.
  • The [Multi-LoRA] debug log is at logger.debug level — no runtime cost unless --debug / verbose=True is enabled.

🌟 Use cases (Optional) / 使用案例

Use case 1: Single dataset per LoRA adapter

// lora_data_map.json
{"0": "LoraA", "1": "LoraB", "2": "LoraA"}
models = [
    dict(type=VLLMCustomAPIChat, abbr='vllm-chat-lora',
         generation_kwargs=dict(lora_data_map_file='/abs/path/lora_data_map.json')),
]

→ Requests for data_id=0 route to LoraA; data_id=1 routes to LoraB.

Use case 2: Mixed base-model + LoRA

// lora_data_map.json — only "0" mapped; others fall back
{"0": "LoraA"}

data_id=0 → LoraA; data_id=1 → base model (silent fallback, no error).

Use case 3: Multi-backend tests

  • TGI service: write parameters.adapter_id (--lora-rank N per adapter).
  • MindIE service: same field, native /infer API.
  • vLLM: just use model field (no client-side change needed; vLLM router picks up adapter by model).

Use case 4: Debugging

--debug (or verbose=True) prints one log line per case:

[Multi-LoRA] data_id=1 lora_model_name=LoraB model_in_request_body=LoraB

Unified [Multi-LoRA] prefix across all 4 backends makes grep / log-aggregation easy.


design: https://github.com/SJTUyh/benchmark/wiki/Multi-Lora-Support-Design
test report:https://github.com/SJTUyh/benchmark/wiki/Multi-Lora-Test-Report

✅ Checklist / 检查列表

Before PR:

  • Pre-commit or other linting tools are used to fix the potential lint issues. / 使用预提交或其他 linting 工具来修复潜在的 lint 问题。
  • Bug fixes are fully covered by unit tests, the case that causes the bug should be added in the unit tests. / 修复的 Bug 已完全由单元测试覆盖,导致 Bug 的情况应在单元测试中添加。
  • The modification is covered by complete unit tests. If not, please add more unit tests to ensure the correctness. / 此拉取请求中的修改已完全由单元测试覆盖。如果不是,请添加更多单元测试以确保正确性。
  • All relevant documentation (API docs, docstrings, example tutorials) has been updated to reflect these changes. / 所有相关文档(API 文档、文档字符串、示例教程)已更新以反映这些更改。

After PR:

  • If the modification has potential influence on downstream or other related projects, this PR should be tested with those projects. / 如果此拉取请求对下游或其他相关项目有潜在影响,应在那些项目中测试此 PR。
  • CLA has been signed and all committers have signed the CLA in this PR. / CLA 已签署,且本 PR 中的所有提交者均已签署 CLA。

👥 Collaboration Info / 协作信息

  • Suggested Reviewers / 建议审核人: @xxx
  • Relevant Module Owners / 相关模块负责人: @xxx
  • Other Collaboration Notes / 其他协作说明:

🌟 Useful CI Command / 实用的CI命令

Command / 命令 Introduction / 介绍
/gemini review Performs a code review for the current pull request in its current state by Gemini. / 对当前拉取请求在当前状态下由 Gemini 执行代码审核。
/gemini summary Provides a summary of the current pull request in its current state by Gemini. / 对当前拉取请求在当前状态下由 Gemini 提供摘要。
/gemini help Displays a list of available commands of Gemini. / 显示 Gemini 可用命令的列表。
/readthedocs build Triggers a build of the documentation for the current pull request in its current state by Read the Docs. / 触发当前拉取请求在当前状态下由 Read the Docs 构建文档。

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@SJTUyh
SJTUyh had a problem deploying to smoke-test-approval July 22, 2026 01:44 — with GitHub Actions Failure
@SJTUyh
SJTUyh temporarily deployed to smoke-test-approval July 22, 2026 02:24 — with GitHub Actions Inactive
@SJTUyh

SJTUyh commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator Author

UT CI is broken, See the UT results of manul execution

@SJTUyh
SJTUyh temporarily deployed to smoke-test-approval July 22, 2026 07:49 — with GitHub Actions Inactive
return url

@staticmethod
def _load_lora_data_map(generation_kwargs):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

这几个api model 下的 方法有啥区别?可以共用一个?都是静态方法

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

[reply] lora map不是所有API后端都支持的,所有没法抽离到基类BaseAPIModel里

@Keithwwa
Keithwwa merged commit 33aa3fa into AISBench:master Jul 27, 2026
5 of 6 checks passed

This branch was previously deployed

1 inactive deployment
smoke-test-approval — 0cd03a48 Deployed Jul 22, 2026 by SJTUyh via run_smoke_test_cases #484
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[需求] AISBench 支持 Multi-LoRA 服务的性能与精度评测

3 participants