File size: 3,653 Bytes
e786a40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Weight policy (the drafter; draft/prep_weights.py): the listed tensors of the published checkpoint are staged and
// converted at load by llm_prep_<src>_<dst> (llm.loom); every other tensor keeps its file bytes. No converted
// checkpoint is written or published.

func.decl import("weights") @input(%source: i32, %key: buffer, %key_offset: i64, %key_length: i64, %offset: i64, %length: i64, %alignment: i64) -> (i64)

func.decl import("prepare") @stage(%root: buffer, %tag: i64) -> (i32)

func.decl import("prepare") @config_i64(%stage: i32, %key: buffer, %value: i64)

global.rodata.def @root0 = bytes("6c6c6d5f707265705f626631365f71385f30")

global.rodata.def @blocks_key = bytes("6c6c6d2e707265705f626c6f636b73")

global.rodata.def @input_key = bytes("6c6c6d2e707265705f696e707574")

// "dspark_hidden_out.weight"
global.rodata.def @k0 = bytes("64737061726b5f68696464656e5f6f75742e776569676874")

// "joint_proj.weight"
global.rodata.def @k1 = bytes("6a6f696e745f70726f6a2e776569676874")

func.def @same(%key: buffer, %name: buffer) -> (i1) {
  %a = buffer.length %key
  %b = buffer.length %name
  %sized = index.cmp eq, %a, %b : offset
  %result = scf.if %sized -> (i1) {
    %o = index.constant 0 : offset
    %order = buffer.compare %key[%o], %name[%o], %b
    %z = scalar.constant 0 : i32
    %same = scalar.cmpi eq, %order, %z : i32
    scf.yield %same : i1
  } else {
    %no = scalar.constant false : i1
    scf.yield %no : i1
  }
  func.return %result : i1
}

func.def public @prepare_weight(%key: buffer) -> (i64) {
  %zero = scalar.constant 0 : i64
  %blocks_0 = scalar.constant 0 : i64
  %kind_0 = scalar.constant 0 : i64
  %inb_0 = scalar.constant 0 : i64
  %outb_0 = scalar.constant 0 : i64
  %name0 = global.load @k0 : buffer
  %is0 = func.call @same(%key, %name0) : (buffer, buffer) -> (i1)
  %nb0 = scalar.constant 18432 : i64
  %nk0 = scalar.constant 0 : i64
  %ni0 = scalar.constant 64 : i64
  %no0 = scalar.constant 34 : i64
  %blocks_1 = scf.select %is0, %nb0, %blocks_0 : i64
  %kind_1 = scf.select %is0, %nk0, %kind_0 : i64
  %inb_1 = scf.select %is0, %ni0, %inb_0 : i64
  %outb_1 = scf.select %is0, %no0, %outb_0 : i64
  %name1 = global.load @k1 : buffer
  %is1 = func.call @same(%key, %name1) : (buffer, buffer) -> (i1)
  %nb1 = scalar.constant 122880 : i64
  %nk1 = scalar.constant 0 : i64
  %ni1 = scalar.constant 64 : i64
  %no1 = scalar.constant 34 : i64
  %blocks_2 = scf.select %is1, %nb1, %blocks_1 : i64
  %kind_2 = scf.select %is1, %nk1, %kind_1 : i64
  %inb_2 = scf.select %is1, %ni1, %inb_1 : i64
  %outb_2 = scf.select %is1, %no1, %outb_1 : i64
  %found = scalar.cmpi ne, %blocks_2, %zero : i64
  %bytes = scf.if %found -> (i64) {
    %source = scalar.constant 0 : i32
    %align = scalar.constant 256 : i64
    %length = scalar.muli %blocks_2, %inb_2 : i64
    %key_bytes = buffer.length %key
    %key_length = index.cast %key_bytes : offset to i64
    %first = func.call @input(%source, %key, %zero, %key_length, %zero, %length, %align) : (i32, buffer, i64, i64, i64, i64, i64) -> (i64)
    %want0 = scalar.constant 0 : i64
    %this0 = scalar.cmpi eq, %kind_2, %want0 : i64
    scf.if %this0 {
      %root0 = global.load @root0 : buffer
      %stage0 = func.call @stage(%root0, %zero) : (buffer, i64) -> (i32)
      %bk0 = global.load @blocks_key : buffer
      %ik0 = global.load @input_key : buffer
      func.call @config_i64(%stage0, %bk0, %blocks_2) : (i32, buffer, i64)
      func.call @config_i64(%stage0, %ik0, %first) : (i32, buffer, i64)
    }
    %prepared = scalar.muli %blocks_2, %outb_2 : i64
    scf.yield %prepared : i64
  } else {
    scf.yield %zero : i64
  }
  func.return %bytes : i64
}