feat(agentic): configurable trainable-turn selection and tool-call arg masking - #437
Open
yourshana wants to merge 4 commits into
Open
feat(agentic): configurable trainable-turn selection and tool-call arg masking#437yourshana wants to merge 4 commits into
yourshana wants to merge 4 commits into
Conversation
- 添加 LossSpan 和 LossMaskExplanation 数据结构 - 实现损失掩码解释器及相关工具函数 - 在 agentic 模块中集成损失掩码分析功能
Patch target changed from areno.cli.explain_mask.load_tokenizer to areno.api.tokenizer.load_tokenizer (the actual import location). Also use _load_dataset_for_training instead of _load_dataset_from_path to match the CLI's dataset loading flow.
- Remove unused imports (typing.Any, LossMaskExplanation, LossMaskPolicy) - Sort import blocks in explain_mask.py and test file - Apply ruff format to all modified files
…g masking Add trainable_turns option with three modes (all_assistant, last_assistant, final_answer) and mask_tool_call_args flag for agentic trajectories. - LossMaskPolicy: replace dead final_assistant_text flag with trainable_turns and mask_tool_call_args - ResponseSpan: capture per-turn span metadata for trajectory-level selection - _apply_trainable_turn_mode: compose mode mask on top of existing per-span mask - _validate_call_result_pairing: reject mid-trajectory tool calls without results - _AgentTrainRows: emit trainable_tokens and masked_response_tokens counts - CLI: --trainable-turns (click.Choice) and --mask-tool-call-args options - 63 CPU tests passed, GPU smoke run on Colab T4 confirmed config propagation Closes inclusionAI#199
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.
What
Make trainable turns configurable for agentic trajectories. Three modes + a tool-call arg masking option, applied at token granularity, plus turn-level validation and trainable-token observability.
--trainable-turnsall_assistantall_assistant|last_assistant|final_answer--mask-tool-call-argsassistant_textspan after the last tool result; degenerates to last span when no tools; bare trailing tool call → zero signal (no error).--mask-tool-call-args— masks JSON-argument tokens within tool-call spans, keeps tool-name trainable. Research ablation; arg localization is approximate.Why
LossMaskPolicy.final_assistant_textwas a dead flag (defined atagentic.py:54, never read). No "last turn / final answer only" mode, no trainable-token count, no call/result pairing validation existed. The issue (#199) asks for exactly these capabilities using existing AReno contracts.How
last_assistant/final_answerneed trajectory-level span info the per-span_response_loss_mask_for_spancan't provide. AResponseSpanlist is captured during trajectory assembly (_set_sample_training_row,_append_sample_response) and consumed by_apply_trainable_turn_modeat the single chokepoint_train_rows_from_samples. The mode mask is composed on top of the existing per-span mask (including_tool_call_loss_mask's result-region suppression), never rebuilt from zero._validate_call_result_pairingrejects mid-trajectory tool calls without matching tool results viaValueErrorbefore worker init. Trailing bare tool calls are exempt sofinal_answercan yield zero trainable signal without error. Orphan tool results are tolerated.mask_tool_call_argslocalizes JSON arguments via_tool_call_arg_token_range(decode + brace-match). Does NOT reuse_tool_call_loss_masksentinel logic (different region). Localization is approximate; behavior pinned by per-token CPU tests.Verification
pytest tests/test_agentic_cpu.py→ 63 passed (20 new + 43 regression)--trainable-turns bogus→click.UsageError(exit 2)TrainerConfig(trainable_turns="invalid")→ValueErrortrainable_turnsconfig propagation across all three modesAcceptance criteria
trainable_tokens/masked_response_tokensin metrics; malformed call/result pairs rejected with turn-level errorexamples/agentic/trainable_turns_demo.py) and explains observable outputFiles
areno/api/agentic.py·areno/api/trainer_config.py·areno/api/trainers/policy_only.py·areno/cli/train.py·tests/test_agentic_cpu.py·docs/cli/training.rst·docs/sdk/trainer.rst·docs/troubleshooting/agentic-rollout.rst·examples/agentic/trainable_turns_demo.pyNotes for reviewers
_tool_call_loss_masksentinel logic left unchanged;mask_tool_call_argsdoes not reuse it (different region).final_assistant_texthad no readers.Closes #199