psaiops 0.0.17__py3-none-any.whl → 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of psaiops might be problematic. Click here for more details.

@@ -30,14 +30,8 @@ def create_intro_block(intro: str) -> dict:
30
30
  # MODEL ########################################################################
31
31
 
32
32
  def create_model_block() -> dict:
33
- __model_dd = gradio.Dropdown(label='Model', value='openai/gpt-oss-20b', choices=['openai/gpt-oss-20b'], scale=1, allow_custom_value=False, multiselect=False, interactive=True) # 'openai/gpt-oss-120b'
34
- __layer_sl = gradio.Slider(label='Layer Depth', value=12, minimum=-1, maximum=23, step=1, scale=1, interactive=True) # info='-1 to average on all layers'
35
- __head_sl = gradio.Slider(label='Attention Head', value=-1, minimum=-1, maximum=63, step=1, scale=1, interactive=True) # info='-1 to average on all heads'
36
- __model_dd.change(fn=update_layer_range, inputs=[__layer_sl, __model_dd], outputs=__layer_sl, queue=False, show_progress='hidden')
37
- return {
38
- 'model_block': __model_dd,
39
- 'layer_block': __layer_sl,
40
- 'head_block': __head_sl}
33
+ __model = gradio.Dropdown(label='Model', value='openai/gpt-oss-20b', choices=['openai/gpt-oss-20b'], scale=1, allow_custom_value=False, multiselect=False, interactive=True) # 'openai/gpt-oss-120b'
34
+ return {'model_block': __model,}
41
35
 
42
36
  # SAMPLING #####################################################################
43
37
 
@@ -53,14 +47,14 @@ def create_sampling_block() -> dict:
53
47
  # TARGET #######################################################################
54
48
 
55
49
  def create_target_block() -> dict:
56
- __target = gradio.Radio(label='Score', value='Inputs', choices=['Inputs', 'Outputs', 'Both'], scale=1, interactive=True)
50
+ __target = gradio.Radio(label='Score', value='Inputs', choices=['Inputs', 'Everything'], scale=1, interactive=True)
57
51
  return {'target_block': __target}
58
52
 
59
53
  # DISPLAY ######################################################################
60
54
 
61
- def create_display_block() -> dict:
62
- __display = gradio.Radio(label='Display', value='Tokens', choices=['Tokens', 'Indexes'], scale=1, interactive=True)
63
- return {'display_block': __display}
55
+ # def create_display_block() -> dict:
56
+ # __display = gradio.Radio(label='Display', value='Tokens', choices=['Tokens', 'Indexes'], scale=1, interactive=True)
57
+ # return {'display_block': __display}
64
58
 
65
59
  # INPUTS #######################################################################
66
60
 
@@ -74,14 +68,22 @@ def create_outputs_block() -> dict:
74
68
  __output = gradio.HighlightedText(label='Scores', value='', scale=1, interactive=False, show_legend=False, show_inline_category=False, combine_adjacent=True, color_map=create_color_map(), elem_classes='white-text')
75
69
  return {'output_block': __output}
76
70
 
71
+ # SELECT #######################################################################
72
+
73
+ def create_selection_block() -> dict:
74
+ __position = gradio.Slider(label='Position', value=-1, minimum=-1, maximum=15, step=1, scale=1, interactive=True) # info='-1 to average on all tokens'
75
+ __layer = gradio.Slider(label='Layer Depth', value=12, minimum=-1, maximum=23, step=1, scale=1, interactive=True) # info='-1 to average on all layers'
76
+ __head = gradio.Slider(label='Attention Head', value=-1, minimum=-1, maximum=63, step=1, scale=1, interactive=True) # info='-1 to average on all heads'
77
+ return {
78
+ 'position_block': __position,
79
+ 'layer_block': __layer,
80
+ 'head_block': __head,}
81
+
77
82
  # ACTIONS ######################################################################
78
83
 
79
84
  def create_actions_block() -> dict:
80
85
  __process = gradio.Button('Process', variant='primary', size='lg', scale=1, interactive=True)
81
- __position = gradio.Slider(label='Position', value=-1, minimum=-1, maximum=15, step=1, scale=1, interactive=True) # info='-1 to average on all tokens'
82
- return {
83
- 'process_block': __process,
84
- 'position_block': __position}
86
+ return {'process_block': __process,}
85
87
 
86
88
  # STATE ########################################################################
87
89
 
@@ -102,6 +104,8 @@ def create_layout(intro: str=INTRO) -> dict:
102
104
  with gradio.Row(equal_height=True):
103
105
  __fields.update(create_inputs_block())
104
106
  __fields.update(create_outputs_block())
107
+ with gradio.Row(equal_height=True):
108
+ __fields.update(create_selection_block())
105
109
  with gradio.Row(equal_height=True):
106
110
  __fields.update(create_actions_block())
107
111
  with gradio.Tab('Settings') as __settings_tab:
@@ -113,7 +117,7 @@ def create_layout(intro: str=INTRO) -> dict:
113
117
  __fields.update(create_sampling_block())
114
118
  with gradio.Row(equal_height=True):
115
119
  __fields.update(create_target_block())
116
- __fields.update(create_display_block())
120
+ # __fields.update(create_display_block())
117
121
  return __fields
118
122
 
119
123
  # EVENTS #######################################################################
@@ -250,19 +254,37 @@ def create_app(title: str=TITLE, intro: str=INTRO, style: str=STYLE, model: str=
250
254
  # init the state
251
255
  __fields.update(create_state())
252
256
  # wire the input fields
257
+ __fields['tokens_block'].change(
258
+ fn=update_position_range,
259
+ inputs=[__fields[__k] for __k in ['position_block', 'tokens_block']],
260
+ outputs=__fields['position_block'],
261
+ queue=False,
262
+ show_progress='hidden')
263
+ __fields['model_block'].change(
264
+ fn=update_layer_range,
265
+ inputs=[__fields[__k] for __k in ['layer_block', 'model_block']],
266
+ outputs=__fields['layer_block'],
267
+ queue=False,
268
+ show_progress='hidden')
253
269
  __fields['process_block'].click(
254
270
  fn=__compute,
255
271
  inputs=[__fields[__k] for __k in ['tokens_block', 'topk_block', 'topp_block', 'position_block', 'layer_block', 'head_block', 'input_block']],
256
272
  outputs=[__fields[__k] for __k in ['output_block', 'input_state', 'output_state', 'attention_state']],
257
273
  queue=False,
258
274
  show_progress='full')
259
- __fields['tokens_block'].change(
260
- fn=update_position_range,
261
- inputs=[__fields[__k] for __k in ['position_block', 'tokens_block']],
262
- outputs=__fields['position_block'],
275
+ __fields['position_block'].change(
276
+ fn=update_text_highlight,
277
+ inputs=[__fields[__k] for __k in ['position_block', 'layer_block', 'head_block', 'input_state', 'output_state', 'attention_state']],
278
+ outputs=__fields['output_block'],
263
279
  queue=False,
264
280
  show_progress='hidden')
265
- __fields['position_block'].change(
281
+ __fields['layer_block'].change(
282
+ fn=update_text_highlight,
283
+ inputs=[__fields[__k] for __k in ['position_block', 'layer_block', 'head_block', 'input_state', 'output_state', 'attention_state']],
284
+ outputs=__fields['output_block'],
285
+ queue=False,
286
+ show_progress='hidden')
287
+ __fields['head_block'].change(
266
288
  fn=update_text_highlight,
267
289
  inputs=[__fields[__k] for __k in ['position_block', 'layer_block', 'head_block', 'input_state', 'output_state', 'attention_state']],
268
290
  outputs=__fields['output_block'],
@@ -98,7 +98,7 @@ def reduce_attention_weights(
98
98
  __layer_slice = slice(None) if (__layer_idx < 0) else slice(__layer_idx, __layer_idx + 1)
99
99
  __sample_slice = slice(None)
100
100
  __head_slice = slice(None) if (__head_idx < 0) else slice(__head_idx, __head_idx + 1)
101
- __token_slice = slice(input_dim, __output_dim) if (__token_idx < 0) else slice(input_dim + __token_idx, input_dim + __token_idx + 1)
101
+ __token_slice = slice(input_dim - 1, __output_dim) if (__token_idx < 0) else slice(input_dim + __token_idx - 1, input_dim + __token_idx)
102
102
  # filter the data
103
103
  __data = attention_data[__layer_slice, __sample_slice, __head_slice, __token_slice, slice(None)]
104
104
  # reduce all the axes but the last
@@ -119,7 +119,7 @@ def postprocess_attention_scores(
119
119
  __output_range = list(range(__output_dim - input_dim)) if (__token_idx < 0) else [__token_idx]
120
120
  __output_mask = torch.BoolTensor([__i in __output_range for __i in range(__output_dim - input_dim)])
121
121
  # normalize the scores
122
- __input_scores = attention_data[__input_slice] / (attention_data[__input_slice].mean() + 1e-5)
122
+ __input_scores = attention_data[__input_slice] / (attention_data[__input_slice].max() + 1e-5)
123
123
  # round to obtain integer labels from 0 to 100
124
124
  __input_scores = torch.round(100.0 * __input_scores, decimals=0).type(torch.int32)
125
125
  # the generated tokens are not scored
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: psaiops
3
- Version: 0.0.17
3
+ Version: 0.1.0
4
4
  Summary: Web apps to inspect & engineer NN activations.
5
5
  License: .github/LICENSE.md
6
6
  Author: apehex
@@ -7,9 +7,9 @@ psaiops/elements/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,
7
7
  psaiops/elements/data.py,sha256=vGYeMN11uP9gs8rV6aSDffE_TeIX5PmdzWGwUpdGE2Y,906
8
8
  psaiops/score/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  psaiops/score/attention/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- psaiops/score/attention/app.py,sha256=G1MQP7FkWfeCCdSm4OwOy3W1ikbcDysIIAJhVC3IwvA,12444
11
- psaiops/score/attention/lib.py,sha256=vyJrp6BK2LvKfmq4JkkmvlsqE4_OcIeBmlq_YMq9jN4,6929
10
+ psaiops/score/attention/app.py,sha256=PlpbhEIJ4zcaqOWJM0V6rFi7HsIhQyDdqhNBltB4dRY,13437
11
+ psaiops/score/attention/lib.py,sha256=j9p7ZXhkh5Y9VDeIe6TPUUrHRkwp1Y6P22iciaaKdL4,6932
12
12
  psaiops/steer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- psaiops-0.0.17.dist-info/METADATA,sha256=kdMbG-IrggF2tS_ndov1kYpeeCE53UUVd3XHsj7tTXw,1222
14
- psaiops-0.0.17.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
15
- psaiops-0.0.17.dist-info/RECORD,,
13
+ psaiops-0.1.0.dist-info/METADATA,sha256=GtW5Nj6cjS2KX4oIEXiZQ98pkYMVpPb1bP7ky0f9U4M,1221
14
+ psaiops-0.1.0.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
15
+ psaiops-0.1.0.dist-info/RECORD,,