Repository navigation
feat(v1): optional sampler logprobs on SamplingMask #2756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
dc361d8
71ad510
ec0bbed
cf6ebfe
5b03e01
2de72ee
13734c6
4733b58
8a90f95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -217,24 +217,32 @@ class SamplingMask: | |
| """Sampling masks stored as flat int32 `ids` and `counts` arrays. | ||
|
|
||
| Each row contains the token ids that survived sampling filters for one completion | ||
| token. Row boundaries are recovered from `counts`. | ||
| token. Row boundaries are recovered from `counts`. The optional float32 `logprobs`, | ||
| parallel to `ids`, are the sampler's renormalized logprobs of those ids. | ||
| """ | ||
|
|
||
| ids: Any | ||
| counts: Any | ||
| logprobs: Any = None | ||
|
cursor[bot] marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High Masks created without sampler logprobs now fail to round-trip across the env-server wire. The serializer iterates every dataclass field, so it encodes 🚀 Reply "fix it for me" or copy this AI Prompt for your agent: |
||
|
|
||
| @classmethod | ||
| def from_sampling_mask( | ||
| cls, sampling_mask: list[list[int]] | dict[str, Any] | ||
| cls, | ||
| sampling_mask: list[list[int]] | dict[str, Any], | ||
| logprobs: dict[str, Any] | None = None, | ||
| ) -> "SamplingMask": | ||
| """Build from vLLM's one-list-per-token masks, or from prime-rl's packed CSR | ||
| form: `{"ids", "counts"}`, each a base64 `{data, shape, dtype}` int32 array.""" | ||
| form: `{"ids", "counts"}`, each a base64 `{data, shape, dtype}` int32 array. | ||
| `logprobs` is packed float32 parallel to the ids (only prime-rl sends it).""" | ||
| import numpy as np | ||
|
|
||
| if logprobs is not None: | ||
| logprobs = _decode_packed(logprobs, np.float32) | ||
| if isinstance(sampling_mask, dict): | ||
| return cls( | ||
| ids=_decode_packed(sampling_mask["ids"], np.int32), | ||
| counts=_decode_packed(sampling_mask["counts"], np.int32), | ||
| logprobs=logprobs, | ||
| ) | ||
| counts = np.fromiter( | ||
| (len(row) for row in sampling_mask), | ||
|
|
@@ -246,7 +254,7 @@ def from_sampling_mask( | |
| if int(counts.sum()) | ||
| else np.empty(0, dtype=np.int32) | ||
| ) | ||
| return cls(ids=ids, counts=counts) | ||
| return cls(ids=ids, counts=counts, logprobs=logprobs) | ||
|
|
||
|
|
||
| def _decode_packed(packed: dict[str, Any], dtype: type) -> "np.ndarray": | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.