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
Show file tree
Hide file tree
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
wip
  • Loading branch information
hjh0119 committed May 1, 2025
commit fc7fabe414d13b990dc67a0b034b0cf2807dfa2a
16 changes: 8 additions & 8 deletions swift/llm/argument/rlhf_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,15 @@ def _check_rlhf(self):
def _check_grpo(self):
if self.rlhf_type != 'grpo':
return

from packaging import version

if self.use_liger_loss:
import liger_kernel
liger_kernel_version = version.parse(liger_kernel.__version__)
assert liger_kernel_version >= version.parse('0.5.8'), (
'Your current version of `liger-kernel` is outdated. '
'Please update it by running: pip install -U liger-kernel')

import trl
trl_version = version.parse(trl.__version__)
assert trl_version >= version.parse('0.17'), ('Your current version of `trl` is outdated. '
Expand Down Expand Up @@ -278,10 +285,3 @@ def _external_vllm_warning(self):
"Configuration conflict: 'vllm_max_model_len=%s' is ignored for external vLLM. "
'Please specify it when launching the inference service: '
'`swift deploy --max_model_len <value>`', self.vllm_max_model_len)

if self.use_liger_loss:
assert self.mini_batch_size is None, 'liger loss is not compatible with mini batch currently'
try:
from liger_kernel.chunked_loss import LigerFusedLinearGRPOLoss
except ImportError:
raise ImportError('liger_kernel is not available. Run `pip install -U liger-kernel`.')
7 changes: 6 additions & 1 deletion swift/trainers/rlhf_trainer/grpo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ def __init__(self,
else:
self.reward_weights = torch.ones(len(reward_funcs), dtype=torch.float32)

self.num_generations = args.num_generations
self.num_generations = args.num_generations # = G in the GRPO paper
self.max_completion_length = args.max_completion_length # = |o_i| in the GRPO paper
self.temperature = args.temperature
self.loss_type = args.loss_type
model.warnings_issued['estimate_tokens'] = True
Expand All @@ -175,6 +176,8 @@ def __init__(self,

use_vllm = args.use_vllm
use_lmdeploy = args.use_lmdeploy

# we initialize vllm_client in RLHFArguments._init_external_vllm (swift/llm/rlhf_args)
vllm_client = kwargs.pop('vllm_client') # for external vllm
self.use_vllm = args.use_vllm
self.use_lmdeploy = args.use_lmdeploy
Expand Down Expand Up @@ -209,6 +212,8 @@ def __init__(self,
epsilon_high=self.epsilon_high,
temperature=self.temperature,
use_ref_model=self.ref_model is not None,
loss_type=self.loss_type,
max_completion_length=self.max_completion_length,
)
self._forward_redirection = _ForwardRedirection()

Expand Down