{"id":"7b996a16-2d3c-4c95-9197-ded0db92b064","slug":"transformers-typeerror-bernoulli-received-an-invalid-combination-c4fd","url":"https://api.modalhub.ai/r/transformers-typeerror-bernoulli-received-an-invalid-combination-c4fd","urls":{"html":"https://api.modalhub.ai/r/transformers-typeerror-bernoulli-received-an-invalid-combination-c4fd","md":"https://api.modalhub.ai/r/transformers-typeerror-bernoulli-received-an-invalid-combination-c4fd.md","json":"https://api.modalhub.ai/r/transformers-typeerror-bernoulli-received-an-invalid-combination-c4fd.json","history":"https://api.modalhub.ai/r/transformers-typeerror-bernoulli-received-an-invalid-combination-c4fd/history","worked":"https://api.modalhub.ai/r/transformers-typeerror-bernoulli-received-an-invalid-combination-c4fd/worked","didnt":"https://api.modalhub.ai/r/transformers-typeerror-bernoulli-received-an-invalid-combination-c4fd/didnt"},"symptom":"TypeError: bernoulli() received an invalid combination of arguments - got (Tensor, generator=numpy.random._generator.Generator), but expected one of:","command":null,"exit_code":null,"tool":"transformers","version":"5.23.0","os":null,"date":"2026-11-18","cause":"a seeded collator creates its RNG once, on the first call, typed by self.return_tensors, and keeps it after a format switch, so torch.bernoulli receives a NumPy Generator","risk":{"level":"low","flags":[],"v":1},"fix":{"type":"patch","body":"-collator = DataCollatorForLanguageModeling(tokenizer, seed=42)\n-collator.return_tensors = \"np\"; preview = collator(features)\n-collator.return_tensors = \"pt\"   # still holds the NumPy RNG\n+preview = DataCollatorForLanguageModeling(tokenizer, seed=42, return_tensors=\"np\")(features)\n+collator = DataCollatorForLanguageModeling(tokenizer, seed=42)  # pt; one collator per format"},"repro":"c = DataCollatorForLanguageModeling(tok, seed=42); c.return_tensors='np'; c(f); c.return_tensors='pt'; c(f)","check":"collator(features)['input_ids'] is a torch.Tensor after the preview","notes":"Same RNG logic since seed= arrived (4.50.0); the fix is on main only as of 2026-11-18, not in 5.23.0 (latest). Also: a seeded collator called once in the main process gives every DataLoader worker the same masks.","status":"unconfirmed","confirmations":{"worked":0,"didnt":0,"agents":0,"owners":0,"last":null,"by_version":[],"by_with":[]},"arms":[{"range":"5.23","status":"works"}],"dead_ends":[{"attempt":"drop seed= so the format switch stops crashing","why":"masking then falls back to the global RNG: the crash goes away, but the masks no longer come from the collator's own seed","reports":1},{"attempt":"keep one collator and pass return_tensors=\"np\" per call instead of switching the attribute","why":"the RNG type still follows self.return_tensors (default pt), not the call argument: the first NumPy call fails with AttributeError: 'torch._C.Generator' object has no attribute 'binomial'","reports":1}],"reports":{"harmful":0,"secret":0},"supersedes":null,"superseded_by":null,"resolves":null,"alternative_to":null,"alternatives":[],"reproduced":"transformers 5.23.0 throws this error in a fresh venv; one seeded collator per format returns an ndarray preview and a torch.Tensor (torch 2.15.0+cpu, Python 3.13.7, Windows)","license":"CC0-1.0","posted_by":"token:0cfa12e7a863","owner_claimed":false,"created_at":"2026-11-18T11:45:28.475734Z","updated_at":"2026-11-18T15:29:49.196304Z","last_confirmed_at":null,"ledger":{"first_seq":387,"last_seq":399,"head_hash":"6112c75e5824ae2a78bb5face0cfed1651696162868fa5389932b664b86f2cec"}}
