Skip to content

grpo liger loss #3781

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 80 commits into from
May 22, 2025
Merged
Changes from 1 commit
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
c3f859d
liger grpo loss
hjh0119 Apr 7, 2025
5224a4a
merge main
hjh0119 Apr 14, 2025
bbce4b2
update
hjh0119 Apr 14, 2025
63fdcea
fix
hjh0119 Apr 14, 2025
5915901
move args
hjh0119 Apr 14, 2025
d0c290c
fix
hjh0119 Apr 14, 2025
0a3794f
fix
hjh0119 Apr 14, 2025
3b9ee6d
fix
hjh0119 Apr 14, 2025
d643ab9
fix
hjh0119 Apr 14, 2025
93fdb71
require
hjh0119 Apr 15, 2025
f87b042
compatible with zero3
hjh0119 Apr 15, 2025
b82cbf4
fix
hjh0119 Apr 15, 2025
9c20051
merge main
hjh0119 May 1, 2025
fc7fabe
wip
hjh0119 May 1, 2025
8f67b13
update liger loss
hjh0119 May 1, 2025
8b4e346
liger&peft
hjh0119 May 1, 2025
edc1fd1
init
hjh0119 May 6, 2025
07a1040
fix default
hjh0119 May 6, 2025
0303461
fix
hjh0119 May 7, 2025
854f357
fix seed
hjh0119 May 7, 2025
7df2b5d
fix
hjh0119 May 7, 2025
fda82ee
wip
hjh0119 May 7, 2025
5d8d4a2
wip multi turn
hjh0119 May 7, 2025
ac52340
multi turn
hjh0119 May 7, 2025
578a365
fix comment
hjh0119 May 7, 2025
9a49fb5
fix peft model inspect and labels
hjh0119 May 7, 2025
5579c3e
fix multi turn
hjh0119 May 7, 2025
7de8aab
update multi turn
hjh0119 May 7, 2025
438f1f7
multi turn not remove response
hjh0119 May 8, 2025
d69a9ae
fix
hjh0119 May 8, 2025
451fd02
fix multi turn concate response
hjh0119 May 8, 2025
c3a1aa9
fix multi turn message check
hjh0119 May 8, 2025
300610e
fix infer
hjh0119 May 8, 2025
fd08ccd
external async generate
hjh0119 May 8, 2025
9da6242
clean argument check
hjh0119 May 8, 2025
8a22c9b
fix async generate
hjh0119 May 8, 2025
8ba0330
fix server infer to list
hjh0119 May 8, 2025
0926a3c
fix server infer
hjh0119 May 8, 2025
0c3827a
catch async generate error
hjh0119 May 8, 2025
fbc2b54
fix infer inputs
hjh0119 May 8, 2025
57445b4
fix async generate
hjh0119 May 8, 2025
e2330f9
fix size
hjh0119 May 8, 2025
37a06f9
remove vllm context
hjh0119 May 9, 2025
66ad138
reward model prepare ds
hjh0119 May 9, 2025
a1f1636
merge main
hjh0119 May 12, 2025
f4a05d3
lint
hjh0119 May 12, 2025
2b5198e
fix multi turn + TP
hjh0119 May 12, 2025
a479465
external path image
hjh0119 May 12, 2025
1fb25db
fix async generate and doc
hjh0119 May 12, 2025
7394dc9
update doc
hjh0119 May 12, 2025
4160ad3
remove async mode script
hjh0119 May 12, 2025
47bb902
doc wip and deprecate patch
hjh0119 May 12, 2025
37c68d2
lint
hjh0119 May 12, 2025
f7700fa
doc and scipt wip
hjh0119 May 13, 2025
6a572fa
doc update
hjh0119 May 13, 2025
4afbdc3
doc
hjh0119 May 13, 2025
df2ce3d
doc update
hjh0119 May 13, 2025
b101e4b
doc update
hjh0119 May 13, 2025
1939873
update doc and readme
hjh0119 May 13, 2025
dae81c1
update grpo doc
hjh0119 May 13, 2025
05054d0
update scripts
hjh0119 May 13, 2025
11307be
rm script
hjh0119 May 13, 2025
7bbed3f
update completion_length_limit_scope argument
hjh0119 May 13, 2025
53a08d0
merge refactor
hjh0119 May 13, 2025
829a7ea
fix epsilon
hjh0119 May 13, 2025
f2b4aac
update stable doc reference
hjh0119 May 13, 2025
cb7ff52
remove lmdeploy
hjh0119 May 13, 2025
5e9e3b5
set different seed bewteen processes
hjh0119 May 13, 2025
25ac346
fix seed
hjh0119 May 13, 2025
427a32f
merge refactor
hjh0119 May 13, 2025
c4dc72e
merge main
hjh0119 May 13, 2025
346396f
remove liger check
hjh0119 May 13, 2025
3045802
fix epsilon
hjh0119 May 13, 2025
4bf7996
remvoe unused import
hjh0119 May 14, 2025
f7080f5
Merge remote-tracking branch 'origin' into liger
hjh0119 May 22, 2025
83b3845
use_liger_kernel
hjh0119 May 22, 2025
8a10681
update
hjh0119 May 22, 2025
79834e6
Merge remote-tracking branch 'origin' into liger
hjh0119 May 22, 2025
169882f
remove require
hjh0119 May 22, 2025
3c7e763
lint
hjh0119 May 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
catch async generate error
  • Loading branch information
hjh0119 committed May 8, 2025
commit 0c3827a33035d25b87377f51af99ed33f88b90e9
27 changes: 21 additions & 6 deletions swift/trainers/rlhf_trainer/grpo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def __init__(self,
self.vllm_gpu_memory_utilization = args.vllm_gpu_memory_utilization # only applies to colocation mode
self.vllm_tensor_parallel_size = args.vllm_tensor_parallel_size # only applies to colocation mode
self.loss_type = args.loss_type
self.max_completion_length = args.max_completion_length
model.warnings_issued['estimate_tokens'] = True
kwargs['data_collator'] = lambda features: features
self.shuffle_dataset = args.dataset_shuffle
Expand Down Expand Up @@ -526,9 +527,14 @@ def _infer(self, inputs: InputsType, request_config: RequestConfig) -> OutputsTy
# inputs: local inputs
from swift.llm.infer.protocol import ChatCompletionResponse
request_config = copy(request_config)
# keys from InferRequest
infer_inputs = {
k: v
for k, v in inputs.items() if k in ['messages', 'images', 'audios', 'videos', 'tools', 'objects']
}
if self.vllm_mode == 'server':
# for server mode, we gather all the inputs and send to remote vllm server in main process
all_inputs = gather_object(inputs)
all_inputs = gather_object(infer_inputs)
if self.accelerator.is_main_process:
results: List[ChatCompletionResponse] = self._engine_infer(
infer_requests=all_inputs, request_config=request_config)
Expand Down Expand Up @@ -654,17 +660,26 @@ def _infer_single_or_multi_turn(self, inputs: InputsType, request_config: Reques
return outputs

def async_infer(self, inputs):
current_queue = self._queue

def infer_task():
with self.multi_turn_completion_length_context():
return self._infer_single_or_multi_turn(inputs, self.request_config)
try:
with self.multi_turn_completion_length_context():
return self._infer_single_or_multi_turn(inputs, self.request_config)
except Exception as e:
logger.error('Inference task failed: %s', str(e))
raise

future: Future = self.executor.submit(infer_task)

# pre-fetch the queue to avoid switching back to eval_queue at the end of training sample sampling
current_queue = self._queue

def done(_self):
current_queue.put(DataCache(inputs, _self.result()))
def done(future):
try:
result = future.result()
current_queue.put(DataCache(inputs, result))
except Exception as e:
logger.error('Error in async_infer callback: %s', str(e))

future.add_done_callback(done)

Expand Down
Loading