Translation
Safetensors
mistral

translate question

#5
by Alone88 - opened

from vllm import LLM, SamplingParams

model_path = "./model"

model = LLM(model=model_path,
            max_num_seqs=512,
            tensor_parallel_size=1,
            enable_prefix_caching=True, 
            gpu_memory_utilization=0.95)

messages = [
    # without CoT
    "Translate the following English sentence into Chinese:\nIf you are using NVIDIA GPUs, you can install vLLM using pip directly. It's recommended to use uv, a very fast Python environment manager, to create and manage Python environments. Please follow the documentation to install uv. After installing uv, you can create a new Python environment and install vLLM using the following commands: <zh>",
    # with CoT
    # "Translate the following English sentence into Chinese and explain it in detail:\nMay the force be with you <zh>" 
]

# Beam search (We recommend using beam search decoding)
# decoding_params = BeamSearchParams(beam_width=4,
                                #    max_tokens=512)
# Greedy decoding


decoding_params = SamplingParams(temperature=0,
                                 max_tokens=512,
                                 skip_special_tokens=True)

results = model.generate(messages, decoding_params)
responses = [res.outputs[0].text.strip() for res in results]

print(responses)

result:

Processed prompts: 100%|████████████████| 1/1 [00:11<00:00, 11.06s/it, est. speed input: 7.96 toks/s, output: 46.30 toks/s]
["如果您正在使用NVIDIA GPU,可以直接通过pip安装vLLM。建议使用速度极快的Python环境管理工具uv来创建和管理Python环境。请按照文档说明安装uv。安装完uv后,您可以创建一个新的Python环境,并使用以下命令安装vLLM:\n\n```\nuv create -n vllm_env\npip install vllm\n```\n\n[COT] 好的,我现在需要把用户提供的英文文本翻译成中文。首先,我要通读一遍原文,理解整体内容和结构。这段文字主要讲的是如何在NVIDIA GPU上安装vLLM,使用pip直接安装,并推荐使用uv(一个快速的Python环境管理器)来创建和管理Python环境。接下来,我需要确保翻译准确,同时保持技术术语的正确性,比如“NVIDIA GPUs”、“pip”、“uv”、“Python environments”等。  \n\n首先处理第一句:“If you are using NVIDIA GPUs, you can install vLLM using pip directly.” 这里需要注意“NVIDIA GPUs”要翻译成“NVIDIA GPU”,保持专有名词不变。然后,“install vLLM using pip directly”可以译为“直接使用pip安装vLLM”。  \n\n接下来是推荐部分:“It's recommended to use uv, a very fast Python environment manager, to create and manage Python environments.” 这里“uv”可能需要保留原名,或者在首次出现时加注释,但用户可能希望直接使用,所以直接保留。翻译时要确保“very fast Python environment manager”准确传达“速度极快的Python环境管理工具”,同时保持句子的流畅。  \n\n然后是安装步骤:“Please follow the documentation to install uv.” 可以译为“请按照文档说明安装uv。”  \n\n最后是具体命令:“After installing uv, you can create a new Python environment and install vLLM using the following commands:” 这里需要注意命令的准确性,确保用户能正确执行。翻译时要保持命令的格式,比如“pip install vllm”直接保留,不需要翻译。  \n\n在翻译过程中,还要注意中英文的语序和表达习惯,确保译文自然流畅,符合中文"]
ByteDance Seed org

@Alone88 Thank you for trying. We recommend using beam search, which can reduce the problem of model hallucination.
image.png

Sign up or log in to comment