psaiops 0.0.6__py3-none-any.whl → 0.0.8__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.
psaiops/score/attention/app.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import functools
|
|
2
|
+
|
|
1
3
|
import gradio
|
|
2
4
|
import torch
|
|
3
5
|
import torch.cuda
|
|
@@ -124,10 +126,12 @@ def update_output_value(
|
|
|
124
126
|
def create_app(title: str=TITLE, intro: str=INTRO, style: str=STYLE, model: str=MODEL) -> gradio.Blocks:
|
|
125
127
|
__fields = {}
|
|
126
128
|
with gradio.Blocks(theme=gradio.themes.Soft(), title=title, css=style) as __app:
|
|
127
|
-
#
|
|
129
|
+
# load the model
|
|
128
130
|
__device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
|
129
131
|
__model = psaiops.score.attention.lib.get_model(name=model, device=__device)
|
|
130
132
|
__tokenizer = psaiops.score.attention.lib.get_tokenizer(name=model, device=__device)
|
|
133
|
+
# adapt the scoring function
|
|
134
|
+
__score = functools.partial(psaiops.score.attention.lib.score_tokens, model_obj=__model, tokenizer_obj=__tokenizer, device_str=__device)
|
|
131
135
|
# create the UI
|
|
132
136
|
__fields.update(create_layout(intro=intro))
|
|
133
137
|
# init the state
|
|
@@ -136,8 +140,8 @@ def create_app(title: str=TITLE, intro: str=INTRO, style: str=STYLE, model: str=
|
|
|
136
140
|
__button = __fields['process_block']
|
|
137
141
|
# wire the input fields
|
|
138
142
|
__button.click(
|
|
139
|
-
fn=
|
|
140
|
-
inputs=[
|
|
143
|
+
fn=__score,
|
|
144
|
+
inputs=[__fields[__k] for __k in ['input_block', 'tokens_block', 'topk_block', 'topp_block', 'position_block', 'layer_block', 'head_block']],
|
|
141
145
|
outputs=__fields['output_block'],
|
|
142
146
|
queue=False,
|
|
143
147
|
show_progress='full')
|
psaiops/score/attention/lib.py
CHANGED
|
@@ -142,16 +142,17 @@ def postprocess_token_ids(
|
|
|
142
142
|
# COMPUTE ########################################################################
|
|
143
143
|
|
|
144
144
|
def score_tokens(
|
|
145
|
+
prompt_str: str,
|
|
146
|
+
token_num: int,
|
|
147
|
+
topk_num: int,
|
|
148
|
+
topp_num: float,
|
|
149
|
+
token_idx: int,
|
|
150
|
+
layer_idx: int,
|
|
151
|
+
head_idx: int,
|
|
152
|
+
*,
|
|
153
|
+
device_str: str,
|
|
145
154
|
model_obj: object,
|
|
146
155
|
tokenizer_obj: object,
|
|
147
|
-
prompt_str: str,
|
|
148
|
-
token_num: int=32,
|
|
149
|
-
topk_num: int = 4,
|
|
150
|
-
topp_num: float = 0.9,
|
|
151
|
-
token_idx: int=-1, # -1 => avg over all tokens
|
|
152
|
-
layer_idx: int=-1, # -1 => avg over layers
|
|
153
|
-
head_idx: int=-1, # -1 => avg over heads
|
|
154
|
-
device_str: str='cuda',
|
|
155
156
|
) -> list:
|
|
156
157
|
# dictionary {'input_ids': _, 'attention_mask': _}
|
|
157
158
|
__inputs = preprocess_token_ids(
|
|
@@ -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=
|
|
11
|
-
psaiops/score/attention/lib.py,sha256=
|
|
10
|
+
psaiops/score/attention/app.py,sha256=E4XKNXEGwcL5ceOVy6twd88IeFoR6RHxZ5C4Arn9jhM,6973
|
|
11
|
+
psaiops/score/attention/lib.py,sha256=VOzixtc1DjEPd7bKmzJfVn_7ZHobblzou_VEhNjtVsk,6865
|
|
12
12
|
psaiops/steer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
|
-
psaiops-0.0.
|
|
14
|
-
psaiops-0.0.
|
|
15
|
-
psaiops-0.0.
|
|
13
|
+
psaiops-0.0.8.dist-info/METADATA,sha256=j5iKrQj8DILJb0CEMK5IJ7kinump2COk7cPgtNd8KjU,1221
|
|
14
|
+
psaiops-0.0.8.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
|
15
|
+
psaiops-0.0.8.dist-info/RECORD,,
|
|
File without changes
|