Skip to content

Commit

Permalink
Change default generate behavior from fixed seed to random seed
Browse files Browse the repository at this point in the history
  • Loading branch information
mondaychen authored and brandonwillard committed Sep 11, 2023
1 parent 3bf5bd0 commit c26ea73
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ from pydantic import BaseModel, constr
import outlines.models as models
import outlines.text.generate as generate

import torch
rng = torch.Generator()
# optional: use this seed to get the same results
rng.manual_seed(67280421310721)


class Weapon(str, Enum):
sword = "sword"
Expand All @@ -220,7 +225,7 @@ class Character(BaseModel):


model = models.transformers("gpt2")
sequence = generate.json(model, Character)("Give me a character description")
sequence = generate.json(model, Character)("Give me a character description", rng=rng) # rng is optional
print(sequence)
# {
# "name": "ranbelt",
Expand Down
1 change: 1 addition & 0 deletions outlines/text/generate/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def __call__(

if rng is None:
rng = torch.Generator(device=self.device)
rng.seed()

num_prompt_tokens = token_ids.shape[-1]

Expand Down

0 comments on commit c26ea73

Please sign in to comment.