torchtune icon indicating copy to clipboard operation
torchtune copied to clipboard

Hown to config generation length on Android device

Open HaomingSong opened this issue 2 years ago • 1 comments

I found that the number of tokens generated in a single run by the model can be controlled by setting the max_tokens parameter in MLCEngine. (As shown below) Now, I want to compile and deploy the model to an Android device. How should I configure a similar parameter to control the number of tokens generated per run on the Android device?

from mlc_llm import MLCEngine

# Create engine
model = "/path/to/converted_model"
engine = MLCEngine(model)

# Run chat completion in OpenAI API.
for response in engine.chat.completions.create(
    messages=[{"role": "user", "content": "What is the meaning of life?"}],
    model=model,
    stream=True,
    max_tokens=512
):
    for choice in response.choices:
        print(choice.delta.content, end="", flush=True)
print("\n")

engine.terminate()

HaomingSong avatar Nov 19 '24 08:11 HaomingSong

Hi @HaomingSong I don't see where you're using torchtune in this code snippet. Maybe this is meant for the mlc-llm repo?

ebsmothers avatar Nov 19 '24 16:11 ebsmothers