Optimize the implementation of Sampler and ProduceStrategy#1493
Merged
YanhuiDua merged 3 commits intoInternLM:rl_designfrom Feb 27, 2026
Merged
Optimize the implementation of Sampler and ProduceStrategy#1493YanhuiDua merged 3 commits intoInternLM:rl_designfrom
YanhuiDua merged 3 commits intoInternLM:rl_designfrom
Conversation
…er to Sampler and use Sampler defaultly; 2. add is_valid_sample_fn and should_continue_fn arguments to produce_batch
jayhenry
reviewed
Feb 26, 2026
| model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True) | ||
| dataloader_cfg: DataloaderConfig | ||
| tokenizer: Union[str, PreTrainedTokenizer, PreTrainedTokenizerFast] | ||
| prompt_repeat_k: int = 1 |
Collaborator
There was a problem hiding this comment.
应该遵循 SamplerCfg.build() 得到对应 Sampler的惯用模式。即DatasetSamplerCfg.build得到DatasetSampler, SamplerCfg.build得到Sampler。
其中静态参数在SamplerCfg中指定,动态参数(比如外部生成的tokenizer, mesh)作为 build()的入参。
YanhuiDua
commented
Feb 27, 2026
|
|
||
| class AgentLoopConfig(BaseModel): | ||
| model_config = ConfigDict(extra="allow", arbitrary_types_allowed=True) | ||
| type: Type[AgentLoop] = SingleTurnAgentLoop |
Collaborator
Author
There was a problem hiding this comment.
@jayhenry @hhaAndroid 这里帮忙看下,传AgentLoop的原因是:想要支持用户定义新的AgentLoop后,仅需要修改Config就可以切换AgentLoop。但是没想到更好的传参数方式,ProduceStrategyConfig也是类似的问题
YanhuiDua
commented
Feb 27, 2026
| class ProducerConfig(BaseModel): | ||
| model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True) | ||
| # TODO: 要考虑怎么方便用户使用自定义的 ProduceStrategy, 并且怎么使用用户需要的参数 | ||
| type: Type[ProduceStrategy] | Literal["sync", "over"] = "sync" |
Collaborator
Author
There was a problem hiding this comment.
ProducerConfig中也有类似于AgentLoopConfig类似的问题 @jayhenry
YanhuiDua
commented
Feb 27, 2026
| # TODO: 要考虑怎么方便用户使用自定义的 ProduceStrategy, 并且怎么使用用户需要的参数 | ||
| type: Type[ProduceStrategy] | Literal["sync", "over"] = "sync" | ||
| staleness_threshold: float = 0.0 # only used for over_produce strategy | ||
| is_valid_sample_fn: Optional[Callable[[list[RolloutState]], bool]] = None |
Collaborator
Author
There was a problem hiding this comment.
这两个function放在config里也是为了方便用户仅需修改config就可以完成自定义的功能的组合
YanhuiDua
added a commit
that referenced
this pull request
Apr 27, 2026
* Optimizer Sampler && ProduceStrategy: 1. rename SamplerWithReplayBuffer to Sampler and use Sampler defaultly; 2. add is_valid_sample_fn and should_continue_fn arguments to produce_batch * Add config for agentloop, agentloopmanager, produceStrategy * fix ProduceStrategyConfig and AgentLoopConfig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sampler->_DatasetSampler,SamplerWithReplayBuffer->Sampler,并且ProduceStrategy默认使用SamplerAsyncProduceStrategy 重命名:
AsyncProduceStrategy->OverProduceStrategyProduceStrategy 增加两个入参:
is_valid_sample_fn,should_continue_fnis_valid_sample_fn用于定义判断样本是否有效,过滤的规则写在这里进行传入,默认为all(sample.status == Status.COMPLETED for sample in samples)should_continue_fn传入是否继续生产的条件,默认为completed_samples_count < batch_size通过增加这两个入参,并且去掉了tqdm进度条,去除
ProduceStrategy中hardcode的部分,仅作为一个轻量的控制流,仅通过调用算法/业务相关函数/Module实现对应功能,进度条显示应该有更加优雅的实现方式