Views
No views yet
KeyError: 'qwen3_moe'1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_name = "Text2MotionPrompter/Text2MotionPrompter"
4
5# load the tokenizer and the model
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForCausalLM.from_pretrained(
8 model_name,
9 torch_dtype="auto",
10 device_map="auto"
11)
12
13# prepare the model input
14template = """
15# Role
16You are an expert in 3D motion analysis, animation timing, and choreography. Your task is to analyze textual action descriptions to estimate execution time and standardize the language for motion generation systems.
17
18# Task
19Analyze the user-provided [Input Action] and generate a structured JSON response containing a duration estimate and a refined caption.
20
21# Instructions
22
23### 1. Duration Estimation (frame_count)
24- Analyze the complexity, speed, and physical constraints of the described action.
25- Estimate the time required to perform the action in a **smooth, natural, and realistic manner**.
26- Calculate the total duration in frames based on a **30 fps** (frames per second) standard.
27- Output strictly as an Integer.
28
29### 2. Caption Refinement (short_caption)
30- Generate a refined, grammatically correct version of the input description in **English**.
31- **Strict Constraints**:
32 - You must **PRESERVE** the original sequence of events (chronological order).
33 - You must **RETAIN** all original spatial modifiers (e.g., "left," "upward," "quickly").
34 - **DO NOT** add new sub-actions or hallucinate details not present in the input.
35 - **DO NOT** delete any specific movements.
36- The goal is to improve clarity and flow while maintaining 100% semantic fidelity to the original request.
37
38### 3. Output Format
39- Return **ONLY** a raw JSON object.
40- Do not use Markdown formatting (i.e., do not use ```json ... ```).
41- Ensure the JSON is valid and parsable.
42
43# JSON Structure
44{{
45 "duration": <Integer, frames at 30fps>,
46 "short_caption": "<String, the refined English description>"
47}}
48
49# Input
50{}
51"""
52
53
54messages = [
55 {"role": "user", "content": template.format("走路")}
56]
57text = tokenizer.apply_chat_template(
58 messages,
59 tokenize=False,
60 add_generation_prompt=True,
61)
62model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
63
64# conduct text completion
65generated_ids = model.generate(
66 **model_inputs,
67 max_new_tokens=8192
68)
69output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
70
71content = tokenizer.decode(output_ids, skip_special_tokens=True)
72
73print("content:", content)
74vllm serve Text2MotionPrompter/Text2MotionPrompter --max-model-len 8192