Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/en/llm/pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,30 @@ response = pipe(['Hi, pls intro yourself', 'Shanghai is'],
hidden_states = [x.last_hidden_state for x in response]
```

### Get last layer's hidden states for prompt and generated tokens

Set `output_last_hidden_state='all'` to return the last layer's hidden
states for both the prefill prompt tokens and generated tokens.

```python
from lmdeploy import pipeline, GenerationConfig

pipe = pipeline('internlm/internlm2_5-7b-chat')

gen_config=GenerationConfig(output_last_hidden_state='all',
max_new_tokens=10)
response = pipe(['Hi, pls intro yourself', 'Shanghai is'],
gen_config=gen_config)
hidden_states = [x.last_hidden_state for x in response]
```

```{note}
`output_last_hidden_state` is supported by the TurboMind engine. Use
`'generation'` when you only need generated-token hidden states, and use
`'all'` when you also need the prompt/prefill hidden states. Prefix caching
cannot be enabled together with `output_last_hidden_state='all'`.
```

### Calculate ppl

```python
Expand Down
24 changes: 24 additions & 0 deletions docs/zh_cn/llm/pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,30 @@ response = pipe(['Hi, pls intro yourself', 'Shanghai is'],
hidden_states = [x.last_hidden_state for x in response]
```

### 获取 prompt 和生成 token 最后一层的 hidden_states

设置 `output_last_hidden_state='all'` 可以同时返回 prefill 阶段的 prompt
token 和生成 token 的最后一层 hidden states。

```python
from lmdeploy import pipeline, GenerationConfig

pipe = pipeline('internlm/internlm2_5-7b-chat')

gen_config=GenerationConfig(output_last_hidden_state='all',
max_new_tokens=10)
response = pipe(['Hi, pls intro yourself', 'Shanghai is'],
gen_config=gen_config)
hidden_states = [x.last_hidden_state for x in response]
```

```{note}
`output_last_hidden_state` 由 TurboMind 引擎支持。如果只需要生成 token
的 hidden states,使用 `'generation'`;如果还需要 prompt/prefill 的 hidden
states,使用 `'all'`。`output_last_hidden_state='all'` 不能和 prefix caching
同时开启。
```

### 计算 ppl

```python
Expand Down