Skip to content

Wensun/apo #96

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

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

Wensun/apo #96

wants to merge 19 commits into from

Conversation

wensun
Copy link
Collaborator

@wensun wensun commented Jun 23, 2025

Implementation of the new algorithm A*PO.

An example of successful run on GSM8K on mlflow: link

Comment on lines 958 to 1004
mean_ift = masked_mean(
env_outs['ift_kl'],
env_outs['action_mask'],
)
env_outs['advantages'] = advantages
self.kl_ift.append(mean_ift.cpu())

iter_batch.update(env_outs)

iter_batch.update({
'max_gen_len':
torch.ones(self.iter_batch_size).to(torch.int32) *
self.max_gen_len,
'adv_masked_mean':
torch.ones(self.iter_batch_size) * batch_adv_mean.cpu(),
'adv_masked_var':
torch.ones(self.iter_batch_size) * batch_adv_var.cpu(),
'ift_kl_scalar':
torch.ones(self.iter_batch_size) * self.kl_ctl.value,
'reward_std':
torch.ones(self.iter_batch_size) *
env_outs['rewards'].std().to('cpu'),
})
else:
raise ValueError(
f'Invalid loss type: {self.actor_critic.loss_type}. ' +
'Valid options are: ppo, grpo.',
)
# APO and REBEL

batch_adv_mean, batch_adv_var = dist_compute_masked_mean_and_var(
env_outs['advantages'],
env_outs['action_mask'],
)
mean_ift = masked_mean(
env_outs['ift_kl'],
env_outs['action_mask'],
)
self.kl_ift.append(mean_ift.cpu())

iter_batch.update(env_outs)

iter_batch.update({
'max_gen_len':
torch.ones(self.iter_batch_size).to(torch.int32) *
self.max_gen_len,
'adv_masked_mean':
torch.ones(self.iter_batch_size),
'adv_masked_var':
torch.ones(self.iter_batch_size),
'ift_kl_scalar':
torch.ones(self.iter_batch_size) * self.kl_ctl.value,
'reward_std':
torch.ones(self.iter_batch_size) *
env_outs['rewards'].std().to('cpu'),
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this block of code for both algorithms very similar to each other, except for the adv_masked_mean bit? If so can we condense it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Collaborator

@jdchang1 jdchang1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, but will wait for others to stamp it!

@jdchang1 jdchang1 requested a review from bcui-db June 23, 2025 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants