Skip to content

Commit 014c50c

Browse files
committed
bpe fixes
1 parent 47153aa commit 014c50c

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

python_autocomplete/bpe.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import string
2+
from functools import lru_cache
23
from heapq import heappush, heappop
34
from typing import List, Tuple
45

@@ -125,6 +126,7 @@ def calc_bpe_itos(self):
125126
itos.append(itos[p1] + itos[p2])
126127
return itos
127128

129+
@lru_cache(1024)
128130
def encode(self, word: str):
129131
if word in self.popular_words:
130132
return self.popular_words[word]

python_autocomplete/train.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ class Configs(TrainValidConfigs):
8383
itos: List[str]
8484
stoi: Dict[str, int]
8585

86+
cache_name: str = ''
87+
8688
def init(self):
8789
tracker.set_queue("loss.*", 20, True)
8890
tracker.set_scalar("accuracy.*", True)
@@ -176,19 +178,19 @@ def _loss_func(c: Configs):
176178
@option(Configs.n_tokens)
177179
def _n_tokens(c: Configs):
178180
from labml.utils.cache import cache
179-
return cache('n_tokens', lambda: c.text.n_tokens)
181+
return cache(f'n_tokens{c.cache_name}', lambda: c.text.n_tokens)
180182

181183

182184
@option(Configs.itos)
183185
def _itos(c: Configs):
184186
from labml.utils.cache import cache
185-
return cache('itos', lambda: c.text.itos)
187+
return cache(f'itos{c.cache_name}', lambda: c.text.itos)
186188

187189

188190
@option(Configs.stoi)
189191
def _stoi(c: Configs):
190192
from labml.utils.cache import cache
191-
return cache('stoi', lambda: c.text.stoi)
193+
return cache(f'stoi{c.cache_name}', lambda: c.text.stoi)
192194

193195

194196
@option(Configs.model)
@@ -352,6 +354,7 @@ def main():
352354
experiment.create(name="source_code",
353355
comment='bpe')
354356
experiment.configs(conf, {
357+
'cache_name': 'bpe',
355358
# 'text': 'source_code',
356359
'text': 'source_code_bpe',
357360
'model': 'transformer_model',

0 commit comments

Comments
 (0)