MCPcopy Create free account
hub / github.com/agentscope-ai/Trinity-RFT / Experience

Class Experience

trinity/common/experience.py:105–496  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103
104@dataclass
105class Experience:
106 _SER_MAGIC = b"TRXP"
107 _SER_VERSION = 1
108 _TENSOR_FIELDS = (
109 "tokens",
110 "logprobs",
111 "token_level_reward",
112 "advantages",
113 "returns",
114 "action_mask",
115 "chosen",
116 "rejected",
117 "teacher_logprobs",
118 "routed_experts",
119 )
120 _META_FIELDS = (
121 "eid",
122 "reward",
123 "truncate_status",
124 "info",
125 "metrics",
126 "prompt_length",
127 "response_text",
128 "prompt_text",
129 "messages",
130 "tools",
131 "chosen_messages",
132 "rejected_messages",
133 )
134
135 eid: EID = field(default_factory=EID) # Unique identifier for the experience
136 tokens: Optional[Tensor] = None # [seq_length]
137 prompt_length: int = 1 # Length of the prompt in tokens, used for generating attention masks
138 logprobs: Optional[Tensor] = None # [resp_length]
139 reward: Optional[float] = None
140 token_level_reward: Optional[Tensor] = None # [resp_length]
141 advantages: Optional[Tensor] = None # [resp_length]
142 returns: Optional[Tensor] = None # [resp_length]
143 truncate_status: Optional[
144 str
145 ] = None # The status of truncation, e.g., "prompt_truncated", "response_truncated"; Not working for openai api
146 info: dict = field(
147 default_factory=dict
148 ) # Additional information about the experience, can also be used to store custom fields
149 metrics: dict[str, float] = field(
150 default_factory=dict
151 ) # Metrics associated with the experience, directly used by the monitor
152
153 # for single-turn experiences
154 response_text: Optional[str] = None # Text of the response
155 prompt_text: Optional[str] = None # Text of the prompt
156
157 # for multi-turn experiences
158 # Action mask indicates which tokens are generated by the model
159 action_mask: Optional[Tensor] = None # [resp_length]
160 messages: Optional[List[dict]] = None # List of messages
161 tools: Optional[List[dict]] = None
162

Callers 15

record_experienceMethod · 0.90
formatMethod · 0.90
runMethod · 0.90
generateMethod · 0.90
generateMethod · 0.90
generateMethod · 0.90

Calls

no outgoing calls

Tested by 15

get_dummy_experienceFunction · 0.72
runMethod · 0.72
runMethod · 0.72
runMethod · 0.72
run_asyncMethod · 0.72
run_asyncMethod · 0.72
run_asyncMethod · 0.72
run_asyncMethod · 0.72
chatMethod · 0.72
generateMethod · 0.72
runMethod · 0.72