Skip to content

Commit 9a29a96

Browse files
authored
Add a switch for Qwen3 think mode (#37)
1 parent 1b9ec28 commit 9a29a96

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

trinity/common/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class ModelConfig:
9191
max_response_tokens: int = 2048
9292
# The checkpoint directory, contains a latest dir link and multiple checkpoint dirs.
9393
checkpoint_path: str = ""
94+
# for models support both thinking and non-thinking mode, e.g., Qwen3
95+
enable_thinking: bool = False
9496

9597

9698
@dataclass

trinity/common/models/vllm_async_model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def __init__(
6565
output_kind=RequestOutputKind.FINAL_ONLY,
6666
logprobs=config.explorer.logprobs,
6767
)
68+
self.enable_thinking = config.model.enable_thinking
6869
self.request_id = 0
6970
engine_args = vllm.AsyncEngineArgs(
7071
model=config.model.model_path,
@@ -137,6 +138,7 @@ async def chat_async(self, messages: List[Dict], **kwargs) -> List[Experience]:
137138
tokenize=False,
138139
add_generation_prompt=True,
139140
chat_template=self.chat_template,
141+
enable_thinking=self.enable_thinking,
140142
)
141143
return await self.generate_async(prompt=prompt, **kwargs)
142144

trinity/common/models/vllm_model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def __init__(self, config: Config, **kwargs):
7171
)
7272
self.tokenizer = self.llm.get_tokenizer()
7373
self.chat_template = self.tokenizer.get_chat_template()
74+
self.enable_thinking = config.model.enable_thinking
7475
if self.config.explorer.chat_template:
7576
self.chat_template = self.config.explorer.chat_template
7677
if not re.search(r"\{\%-?\s*generation\s*-?\%\}", self.chat_template):
@@ -233,6 +234,7 @@ def chat(self, messages: List[dict], **kwargs) -> List[Experience]:
233234
tokenize=False,
234235
add_generation_prompt=True,
235236
chat_template=self.chat_template,
237+
enable_thinking=self.enable_thinking,
236238
)
237239
return self.generate([prompt], **kwargs)
238240

trinity/explorer/runner_pool.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@ def __init__(self, config: Config, models: List):
4949
self._create_actors(config.explorer.runner_num)
5050

5151
def _create_actors(self, num: int = 1):
52+
new_actors = []
5253
for _ in range(num):
5354
engine_index = self.engine_status.index(min(self.engine_status))
5455
new_actor = WorkflowRunner.remote(self.config, self.models[engine_index])
55-
ray.get(new_actor.__ray_ready__.remote())
56+
new_actors.append(new_actor)
5657
self.engine_status[engine_index] += 1
5758
self.actor_to_engine_index[new_actor] = engine_index
58-
self._return_actor(new_actor)
59+
for actor in new_actors:
60+
self._return_actor(actor)
5961

6062
def _kill_actors(self, actors):
6163
if not isinstance(actors, list):
@@ -234,7 +236,7 @@ def get_next(self) -> Status:
234236

235237
def _return_actor(self, actor):
236238
try:
237-
actor.is_alive.remote()
239+
ray.get(actor.is_alive.remote())
238240
self._idle_actors.append(actor)
239241
except Exception:
240242
self.logger.info("The actor is not alive, restart a new actor")

0 commit comments

Comments
 (0)