Compare isolated layer sharing against the native lookup model
This commit is contained in:
@@ -20,6 +20,12 @@ from functional.model import PREFIX, StreamingLM
|
||||
from functional.run import write_json
|
||||
|
||||
|
||||
# Vary only layers 15 and 19 with native attention at layer 23 in all four arms.
|
||||
ISOLATION_SCHEDULES = {
|
||||
'native': (), 'only-15': (15,), 'only-19': (19,), 'both-15-19': (15, 19)
|
||||
}
|
||||
|
||||
|
||||
class PathDecoder(GenerationDecoder):
|
||||
def score_paths(self, h, layer, positions, scores):
|
||||
if layer != self.site or self.mode == 'baseline':
|
||||
@@ -66,8 +72,13 @@ def batch(model, tok, adapters, qs, site, mode):
|
||||
ids = [tok.encode(prompt(q['question']),add_special_tokens=False).ids for q in qs]
|
||||
width = max(map(len,ids))
|
||||
padding = [width-len(x) for x in ids]
|
||||
dec = PathDecoder(model,[SITES]*len(qs),padding,adapters)
|
||||
dec.site, dec.mode = site, mode
|
||||
if mode in ISOLATION_SCHEDULES:
|
||||
schedule = ISOLATION_SCHEDULES[mode]
|
||||
dec = GenerationDecoder(model, [schedule]*len(qs), padding,
|
||||
{layer: adapters[layer] for layer in schedule})
|
||||
else:
|
||||
dec = PathDecoder(model,[SITES]*len(qs),padding,adapters)
|
||||
dec.site, dec.mode = site, mode
|
||||
h = dec.advance(torch.tensor([[0]*p+x for p,x in zip(padding,ids)]))[:,-1]
|
||||
head = model.tensors[PREFIX+'embed_tokens.weight']
|
||||
gold = torch.tensor([tok.encode(str(q['answer']),add_special_tokens=False).ids[0] for q in qs])
|
||||
@@ -147,6 +158,8 @@ def main():
|
||||
if not a.follow_through:
|
||||
return
|
||||
|
||||
evaluate('diagnostic', 'isolation', ISOLATION_SCHEDULES)
|
||||
|
||||
def diagnostic_score(mode):
|
||||
joint = total = 0
|
||||
for kind, items in plan['diagnostic'].items():
|
||||
|
||||
Reference in New Issue
Block a user