psaiops 0.0.17__tar.gz → 0.1.1__tar.gz
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.
- {psaiops-0.0.17 → psaiops-0.1.1}/PKG-INFO +1 -1
- {psaiops-0.0.17 → psaiops-0.1.1}/psaiops/score/attention/app.py +46 -24
- {psaiops-0.0.17 → psaiops-0.1.1}/psaiops/score/attention/lib.py +2 -2
- {psaiops-0.0.17 → psaiops-0.1.1}/pyproject.toml +1 -1
- {psaiops-0.0.17 → psaiops-0.1.1}/.github/README.md +0 -0
- {psaiops-0.0.17 → psaiops-0.1.1}/psaiops/__init__.py +0 -0
- {psaiops-0.0.17 → psaiops-0.1.1}/psaiops/combine/__init__.py +0 -0
- {psaiops-0.0.17 → psaiops-0.1.1}/psaiops/compose/__init__.py +0 -0
- {psaiops-0.0.17 → psaiops-0.1.1}/psaiops/compose/contrast/__init__.py +0 -0
- {psaiops-0.0.17 → psaiops-0.1.1}/psaiops/edit/__init__.py +0 -0
- {psaiops-0.0.17 → psaiops-0.1.1}/psaiops/elements/__init__.py +0 -0
- {psaiops-0.0.17 → psaiops-0.1.1}/psaiops/elements/data.py +0 -0
- {psaiops-0.0.17 → psaiops-0.1.1}/psaiops/score/__init__.py +0 -0
- {psaiops-0.0.17 → psaiops-0.1.1}/psaiops/score/attention/__init__.py +0 -0
- {psaiops-0.0.17 → psaiops-0.1.1}/psaiops/steer/__init__.py +0 -0
|
@@ -18,7 +18,7 @@ MODEL = 'openai/gpt-oss-20b'
|
|
|
18
18
|
|
|
19
19
|
def create_color_map() -> dict:
|
|
20
20
|
return {
|
|
21
|
-
'-1': '#
|
|
21
|
+
'-1': '#004444',
|
|
22
22
|
**{str(__i): '#{:02x}0000'.format(int(2.55 * __i)) for __i in range(101)}}
|
|
23
23
|
|
|
24
24
|
# INTRO ########################################################################
|
|
@@ -30,14 +30,8 @@ def create_intro_block(intro: str) -> dict:
|
|
|
30
30
|
# MODEL ########################################################################
|
|
31
31
|
|
|
32
32
|
def create_model_block() -> dict:
|
|
33
|
-
|
|
34
|
-
|
|
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', '
|
|
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
|
-
|
|
63
|
-
|
|
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
|
|
|
@@ -71,17 +65,25 @@ def create_inputs_block() -> dict:
|
|
|
71
65
|
# OUTPUTS ######################################################################
|
|
72
66
|
|
|
73
67
|
def create_outputs_block() -> dict:
|
|
74
|
-
__output = gradio.HighlightedText(label='Scores', value='', scale=1, interactive=False, show_legend=False, show_inline_category=False, combine_adjacent=
|
|
68
|
+
__output = gradio.HighlightedText(label='Scores', value='', scale=1, interactive=False, show_legend=False, show_inline_category=False, combine_adjacent=False, 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='Token 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
|
-
|
|
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['
|
|
260
|
-
fn=
|
|
261
|
-
inputs=[__fields[__k] for __k in ['position_block', '
|
|
262
|
-
outputs=__fields['
|
|
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['
|
|
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
|
|
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].
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|