Skip to content

Commit

Permalink
fix absurdly fast benchmarks: cleanup lm-format-enforcer cache in tea…
Browse files Browse the repository at this point in the history
…rdown step, cleanup json generator
  • Loading branch information
lapp0 committed Oct 16, 2024
1 parent 5bc6379 commit 0d73c1c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/benchmark_lfe.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def time_lfe(self, _, regex_name):
for i in range(len(regex_sample_tokens)):
_ = token_enforcer.get_allowed_tokens(regex_sample_tokens[: i + 1])

def teardown(self, *args):
del self.tokenizer_data


class LMFormatEnforcerJsonSchema:
params = [models, json_cases.keys()]
Expand Down Expand Up @@ -66,3 +69,6 @@ def time_lfe(self, _, json_schema_name):
json_sample_tokens = self.tokenizer.encode(json_sample)
for i in range(len(json_sample_tokens)):
_ = token_enforcer.get_allowed_tokens(json_sample_tokens[: i + 1])

def teardown(self, *args):
del self.tokenizer_data
8 changes: 4 additions & 4 deletions src/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
"title": "Character",
"type": "object",
},
"samples": map(
json.dumps, json.load(open(SAMPLES_PATH / "rpg_characters.json"))
"samples": list(
map(json.dumps, json.load(open(SAMPLES_PATH / "rpg_characters.json")))
),
},
"Simple nested schema": {
Expand Down Expand Up @@ -94,8 +94,8 @@
},
"required": ["id", "work", "recording_artists"],
},
"samples": map(
json.dumps, json.load(open(SAMPLES_PATH / "recording_schema.json"))
"samples": list(
map(json.dumps, json.load(open(SAMPLES_PATH / "recording_schema.json")))
),
},
}

0 comments on commit 0d73c1c

Please sign in to comment.