Skip to content

Commit

Permalink
rollback user guide
Browse files Browse the repository at this point in the history
  • Loading branch information
lvhan028 committed Sep 25, 2024
1 parent bd3df2e commit a1a4845
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
8 changes: 6 additions & 2 deletions docs/en/advance/long_context.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ This test takes approximately 364 seconds per round when conducted on A100-80G G
The following codes demonstrate how to use LMDeploy to calculate perplexity.

```python
from transformers import AutoTokenizer
from lmdeploy import TurbomindEngineConfig, pipeline
import numpy as np

# build pipeline
# load model and tokenizer
model_repoid_or_path = 'internlm/internlm2_5-7b-chat-1m'
backend_config = TurbomindEngineConfig(
rope_scaling_factor=2.5,
Expand All @@ -107,9 +109,11 @@ backend_config = TurbomindEngineConfig(
cache_max_entry_count=0.7,
tp=4)
pipe = pipeline(model_repoid_or_path, backend_config=backend_config)
tokenizer = AutoTokenizer.from_pretrained(model_repoid_or_path, trust_remote_code=True)

# get perplexity
text = 'Use a long prompt to replace this sentence'
ppl = pipe.get_ppl(text)
input_ids = tokenizer.encode(text)
ppl = pipe.get_ppl(input_ids)[0]
print(ppl)
```
16 changes: 8 additions & 8 deletions docs/en/llm/pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,21 @@ for item in pipe.stream_infer(prompts, gen_config=gen_config):
- **An example to cauculate logits & ppl:**

```python
from transformers import AutoTokenizer
from lmdeploy import pipeline

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

prompts = [
"Hello, I am an AI assistant named InternLM. I am developed by Shanghai AI Laboratory",
"How to use LMDeploy to deploy a LLM model?"
]
tokenizer = AutoTokenizer.from_pretrained(model_repoid_or_path, trust_remote_code=True)

# logits
logits = pipe.get_logits(prompts)
messages = [
{"role": "user", "content": "Hello, how are you?"},
]
input_ids = tokenizer.apply_chat_template(messages)
logits = pipe.get_logits(input_ids)

# ppl
ppl = pipe.get_ppl(prompts)
ppl = pipe.get_ppl(input_ids)
```

- **Below is an example for pytorch backend. Please install triton first.**
Expand Down
8 changes: 6 additions & 2 deletions docs/zh_cn/advance/long_context.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ passkey_retrieval(session_len, 5)
下面展示使用 LMDeploy 计算困惑度的用法

```python
from transformers import AutoTokenizer
from lmdeploy import TurbomindEngineConfig, pipeline
import numpy as np

# build pipeline
# load model and tokenizer
model_repoid_or_path = 'internlm/internlm2_5-7b-chat-1m'
backend_config = TurbomindEngineConfig(
rope_scaling_factor=2.5,
Expand All @@ -107,9 +109,11 @@ backend_config = TurbomindEngineConfig(
cache_max_entry_count=0.7,
tp=4)
pipe = pipeline(model_repoid_or_path, backend_config=backend_config)
tokenizer = AutoTokenizer.from_pretrained(model_repoid_or_path, trust_remote_code=True)

# get perplexity
text = 'Use a long prompt to replace this sentence'
loss = pipe.get_ppl(text)
input_ids = tokenizer.encode(text)
loss = pipe.get_ppl(input_ids)[0]
print(ppl)
```
16 changes: 8 additions & 8 deletions docs/zh_cn/llm/pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,21 @@ for item in pipe.stream_infer(prompts, gen_config=gen_config):
- **计算 logits & ppl:**

```python
from transformers import AutoTokenizer
from lmdeploy import pipeline

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

prompts = [
"Hello, I am an AI assistant named InternLM. I am developed by Shanghai AI Laboratory",
"How to use LMDeploy to deploy a LLM model?"
]
tokenizer = AutoTokenizer.from_pretrained(model_repoid_or_path, trust_remote_code=True)

# logits
logits = pipe.get_logits(prompts)
messages = [
{"role": "user", "content": "Hello, how are you?"},
]
input_ids = tokenizer.apply_chat_template(messages)
logits = pipe.get_logits(input_ids)

# ppl
ppl = pipe.get_ppl(prompts)
ppl = pipe.get_ppl(input_ids)
```

- **使用 pytorch 后端**
Expand Down

0 comments on commit a1a4845

Please sign in to comment.