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