lm-sys / lm-sys/FastChat

Compatibility Issue with Prefix-Tuned Models using PEFT in FastChat

Open
#3,095 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
39.5k
Forks
4.8k
PR merge metrics
No merged PRs in 30d

Description

I am encountering a compatibility issue when trying to use a prefix-tuned model with FastChat. The model was fine-tuned using the PEFT library, which utilizes `past_key_values` for injecting prefixes. This conflicts with FastChat's streaming functionality in `fastchat.serve.inference.generate_stream`, which also relies on `past_key_values`.

To illustrate the problem, I have created a fork with a GPT2 model integrated with a random prefix adapter, which can be found here:
https://github.com/fzalkow/FastChat/blob/test_prefix/fastchat/model/model_adapter.py#L2271-L2298

I launched the FastChat server and API with these commands:

```
python3 -m fastchat.serve.controller --host 127.0.0.1
python3 -m fastchat.serve.model_worker --host 127.0.0.1 --controller-address http://127.0.0.1:21001 --model-path openai-community/gpt2
python3 -m fastchat.serve.openai_api_server --host 127.0.0.1 --controller-address http://127.0.0.1:21001 --port 8000
```

When I make an API call:

```
curl http://127.0.0.1:8000/v1/completions -H "Content-Type: application/json" -d '{"model": "gpt2", "prompt": "Does fastchat work with prefix-tuned models?", "max_tokens": 1014, "temperature": 0.0}'
```

I receive an `Internal Server Error` due to the `got multiple values for keyword argument 'past_key_values'` error.

The prefix-tuned model's forward call from the PEFT library uses the `past_key_values` keyword, which is here:
https://github.com/huggingface/peft/blob/main/src/peft/peft_model.py#L1126-L1127

And FastChat's use of the same keyword in its streaming functionality is here:
https://github.com/lm-sys/FastChat/blob/main/fastchat/serve/inference.py#L160-L167

Does anyone know how to resolve this conflict? I currently use a dirty workaround to get it working, where I reimplemented `generate_stream` to use `model.generate` in a single step, but this bypasses the entire streaming functionality, which is not ideal. Any suggestions or guidance would be greatly appreciated.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with the provided FastChat controller, model worker, API server, and curl commands. Read fastchat/serve/inference.py around lines 160-167 and the linked model_adapter.py and PEFT forward-call references to trace the duplicate past_key_values arguments. Done means prefix-tuned models work through the normal streaming API without the duplicate-keyword error while preserving streaming behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
ai, backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.