ericsorides commited on
Commit
72b6f50
·
1 Parent(s): cfa6850

Added position_ids input

Browse files
Files changed (2) hide show
  1. README.md +5 -1
  2. model.onnx +2 -2
README.md CHANGED
@@ -92,9 +92,11 @@ def generate_text(model_path, prompt, tokenizer, max_gen_tokens, total_sequence,
92
  inputs_dict = {}
93
  inputs_dict['input_ids'] = actual_input[:, :window].reshape(1, window).numpy()
94
  inputs_dict['attention_mask'] = first_attention
 
 
95
  inputs_dict['tree_attention'] = np.triu(-65504*np.ones(total_sequence), k= 1).astype('float16').reshape(1, 1, total_sequence, total_sequence)
96
  for name in inputs_names:
97
- if name == 'input_ids' or name == 'attention_mask' or name == 'tree_attention': continue
98
  inputs_dict[name] = np.zeros([1, n_heads, context-window, 128], dtype="float16")
99
  index = 0
100
  new_token = np.array([10])
@@ -126,6 +128,8 @@ def generate_text(model_path, prompt, tokenizer, max_gen_tokens, total_sequence,
126
  inputs_dict['input_ids']= total_input[:, j:next_index].reshape(1, window)
127
  elif name == 'attention_mask':
128
  inputs_dict['attention_mask'] = np.concatenate((np.zeros((1, total_sequence-next_index), dtype = 'int64'), np.ones((1, next_index), dtype = 'int64')), axis=1)
 
 
129
  elif name == 'tree_attention': continue
130
  else:
131
  old_name = name.replace("past_key_values", "present")
 
92
  inputs_dict = {}
93
  inputs_dict['input_ids'] = actual_input[:, :window].reshape(1, window).numpy()
94
  inputs_dict['attention_mask'] = first_attention
95
+ index_pos = sum(first_attention[0])
96
+ inputs_dict['position_ids'] = np.concatenate((np.zeros([1, total_sequence - index_pos], dtype = 'int64'), np.arange(index_pos, dtype = 'int64').reshape(1, index_pos)), axis=1)
97
  inputs_dict['tree_attention'] = np.triu(-65504*np.ones(total_sequence), k= 1).astype('float16').reshape(1, 1, total_sequence, total_sequence)
98
  for name in inputs_names:
99
+ if name == 'input_ids' or name == 'attention_mask' or name == 'position_ids' or name == 'tree_attention': continue
100
  inputs_dict[name] = np.zeros([1, n_heads, context-window, 128], dtype="float16")
101
  index = 0
102
  new_token = np.array([10])
 
128
  inputs_dict['input_ids']= total_input[:, j:next_index].reshape(1, window)
129
  elif name == 'attention_mask':
130
  inputs_dict['attention_mask'] = np.concatenate((np.zeros((1, total_sequence-next_index), dtype = 'int64'), np.ones((1, next_index), dtype = 'int64')), axis=1)
131
+ elif name == 'position_ids':
132
+ inputs_dict['position_ids'] = np.concatenate((np.zeros([1, total_sequence - next_index], dtype = 'int64'), np.arange(next_index, dtype = 'int64').reshape(1, next_index)), axis=1)
133
  elif name == 'tree_attention': continue
134
  else:
135
  old_name = name.replace("past_key_values", "present")
model.onnx CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:e1c5fe4ecbe186fa34bfc32001191c2726b2245642a283d3ff837d5eea0e6342
3
- size 1887217
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cd301421dc19754ee0439adafaa0c9ec62d0006041253745908605613747ef5e
3
+ size 1886572