SynthID-Text: CPU and MPS produce different sampling tables with the same seed
System Info
- transformers 4.46.3, torch 2.8.0, Python 3.9.6, macOS 15.7.9, Apple M3 Pro (MPS)
Reproduction
import torch
from transformers import SynthIDTextWatermarkingConfig
cfg = SynthIDTextWatermarkingConfig(
keys=[654, 400, 836, 123, 340, 443, 597, 160, 57, 29], ngram_len=5, sampling_table_seed=0
)
p_cpu = cfg.construct_processor(vocab_size=32000, device="cpu")
p_mps = cfg.construct_processor(vocab_size=32000, device="mps")
print("tables agree:", (p_cpu.sampling_table == p_mps.sampling_table.cpu()).float().mean().item())
ids = torch.randint(0, 32000, (1, 64), generator=torch.Generator().manual_seed(0))
g_cpu = p_cpu.compute_g_values(ids)
g_mps = p_mps.compute_g_values(ids.to("mps")).cpu()
print("g-values agree:", (g_cpu == g_mps).float().mean().item())
Output: tables agree: 0.5019, g-values agree: 0.4900.
SynthIDTextWatermarkLogitsProcessor.__init__ draws the sampling table with torch.Generator(device=device).manual_seed(sampling_table_seed). PyTorch does not guarantee identical random streams across devices for the same seed, so the same keys and sampling_table_seed give different tables, and therefore different g-values, on CPU and MPS.
Reproduced on 4.46.3. The same device-specific initialization is present in v5.19.0 (src/transformers/generation/logits_process.py, SynthIDTextWatermarkLogitsProcessor.__init__); we have not run v5.19.0.
Effect in practice
In our evaluation (Qwen2.5-1.5B-Instruct, 10 watermarked outputs of 400 tokens, 30 keys, ngram_len=5), the mean g-score, i.e. the mean g-value over positions not masked by context repetition, was 0.59 to 0.66 when scored with an MPS-built processor and 0.49 to 0.50 when scored with a CPU-built processor. Ten unwatermarked outputs scored 0.49 to 0.51. So scoring MPS-watermarked text with a CPU-built processor reduced the mean g-score to the unwatermarked baseline. We did not test the Bayesian detector or CUDA.
Expected behavior
The same keys and sampling_table_seed give the same sampling table, and the same g-values, on every device.
Possible fix
Draw the table on CPU and move it to the device:
generator = torch.Generator(device="cpu").manual_seed(sampling_table_seed)
self.sampling_table = torch.randint(
low=0, high=2, size=(sampling_table_size,), generator=generator, device="cpu"
).to(device)
This would change the default table on non-CPU devices, so text already watermarked on MPS or GPU would no longer be detected with the default. Keeping that possible would need an option to select the previous device-generated table; a documentation note alone would explain the behaviour but would not preserve detection of existing text. Happy to open a PR for whichever approach you prefer.
Context, not needed to reproduce: we found this while preparing a pre-registered robustness evaluation of the open-source implementation, https://falsify.dev/receipts/synthid-text-2026-10/
Hi! This is an interesting reproducibility issue, and I'd like to contribute to resolving it. I can help investigate cross-device regression tests and backward-compatibility implications for existing watermarked text.
Since you've offered to open a PR, would you be open to collaborating on those aspects, or is there another part of the investigation that would be useful?
Hey! I believe this has already been fixed in the upstream Deepmind implementation, so they don't use a device-specific seed like that anymore. We'll accept a PR for this, but please ensure it matches the upstream one, so that SynthID generated by either implementation is comparable
Thanks for checking, @Rocketknight1. I won't be opening the PR myself, so @samarth-git27 or anyone else is welcome to pick it up.
Thanks for the clarification! I'll take this up and first inspect DeepMind's upstream implementation to ensure the sampling-table initialization matches it. I'll also investigate backward compatibility and add regression tests for cross-device reproducibility before opening a PR.
Thanks for the guidance @sk8ordie84 . I've inspected the current upstream implementation and confirmed that it uses Threefry-based g-value generation rather than the precomputed sampling table.
One API question before I implement the port: Transformers currently accepts a list of per-depth keys, along with sampling_table_seed and sampling_table_size, whereas upstream uses a single master key and depth.
Would you prefer this PR to migrate toward the upstream key/depth interface with a backward-compatibility path, or is there an intended mapping from the existing Transformers configuration to the upstream algorithm?
I'd like to align on this before making changes so the PR preserves compatibility where possible and produces g-values that match upstream.
Let's migrate towards their interface. If users pass the old args, we can raise a warning, and then go with a fallback like selecting the first key in keys and using that as key, or something (it doesn't have to be exactly that - I haven't inspected the code too closely so there may be a better approach)
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.
Please note that issues that do not follow the contributing guidelines are likely to be ignored.
Thanks for the follow-up! This issue is still relevant, and I'd like to continue working on it.
I've received maintainer guidance to migrate towards the upstream key/depth interface while retaining a compatibility path for the existing arguments, with an appropriate deprecation warning.
I'm currently reviewing the upstream implementation and planning the migration to ensure behavioral parity and backward compatibility.
I'd be happy to continue working on this. Thanks!