How to weight a message
| 19 | |
| 20 | @dataclasses.dataclass |
| 21 | class MessageWeight(BaseConfig): |
| 22 | """How to weight a message""" |
| 23 | |
| 24 | weight: Optional[float] = None |
| 25 | """Scale by weights by this much""" |
| 26 | |
| 27 | root_subsegments: Optional[bool] = None |
| 28 | """Divide by 1/sqrt(n_subsegments)""" |
| 29 | |
| 30 | root_length: Optional[bool] = None |
| 31 | """Divide by 2/sqrt(n_loss_tokens)""" |
| 32 | |
| 33 | def with_overrides(self, other: Union[None, float, 'MessageWeight']) -> 'MessageWeight': |
| 34 | if other is None: |
| 35 | return self |
| 36 | if isinstance(other, (int, float)): |
| 37 | return MessageWeight( |
| 38 | weight=other, root_subsegments=self.root_subsegments, root_length=self.root_length) |
| 39 | return MessageWeight( |
| 40 | weight=self.weight if other.weight is None else other.weight, |
| 41 | root_subsegments=self.root_subsegments if other.root_subsegments is None else other.root_subsegments, |
| 42 | root_length=self.root_length if other.root_length is None else other.root_length, |
| 43 | ) |
| 44 | |
| 45 | |
| 46 | @dataclasses.dataclass |
no outgoing calls
no test coverage detected