Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store the image moderation and text moderation logs #3478

Open
wants to merge 43 commits into
base: operation-202407
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
92a6d1f
Chatbot Arena Category Classification Script (#3433)
CodingWithTim Jul 9, 2024
f67b6e4
Update sglang_worker.py to fix #3372 error launching SGLand worker (#…
vikrantrathore Jul 29, 2024
653f7c1
add a performant worker dash-infer which is specifically optimized fo…
yejunjin Jul 29, 2024
d32e370
Update README.md
infwinston Jul 30, 2024
1c95cc8
Update monitor.py
infwinston Jul 30, 2024
d2016dd
Update README.md
infwinston Jul 31, 2024
925fb82
Update README.md
infwinston Jul 31, 2024
d310369
added leaderboard for arena hard auto (#3437)
connorchenn Jul 31, 2024
76571d2
Arena hard auto leaderboard UI (#3457)
CodingWithTim Jul 31, 2024
a5c29e1
Update monitor.py (#3460)
infwinston Aug 1, 2024
5c0443e
Survey only (#3466)
lisadunlap Aug 6, 2024
cb4da0d
Store text and image moderation logs
BabyChouSr Aug 15, 2024
605add3
Update moderation
BabyChouSr Aug 16, 2024
4492299
Run formatter
BabyChouSr Aug 16, 2024
2723660
Show vote button
BabyChouSr Aug 16, 2024
51f9a0d
Fix pylint
BabyChouSr Aug 16, 2024
38a1360
Fix pylint
BabyChouSr Aug 16, 2024
e10d11b
Save bad images
BabyChouSr Aug 16, 2024
5159d3b
Address comments
BabyChouSr Aug 17, 2024
8708fd7
Add max-model-len argument to vllm worker (#3451)
aliasaria Aug 18, 2024
29fc8a0
Revert "Add max-model-len argument to vllm worker" (#3488)
vikrantrathore Aug 21, 2024
c7f9230
New leaderboard (#3465)
lisadunlap Aug 22, 2024
d8f411a
Update dataset_release.md (#3492)
merrymercy Aug 24, 2024
4c25b00
Update link
infwinston Aug 26, 2024
36f7807
Update monitor_md.py (#3494)
infwinston Aug 26, 2024
0b09cee
Version names for Command R/R+ (#3491)
sanderland Aug 26, 2024
282534b
Update preset images (#3493)
lisadunlap Aug 26, 2024
05b9305
Add Style Control to Chatbot Arena Leaderboard 🔥 (#3495)
CodingWithTim Aug 27, 2024
dba425f
Save moderation info per turn
BabyChouSr Aug 27, 2024
d289be9
Change states
BabyChouSr Aug 27, 2024
7911ecd
Clean up
BabyChouSr Aug 27, 2024
1527aac
Get rid of previous moderation response
BabyChouSr Aug 27, 2024
36c67da
Rename
BabyChouSr Aug 27, 2024
4e62d77
Added NewYorker images back in (#3499)
lisadunlap Aug 27, 2024
3e21ddc
Fix Style control Bootstrapping (#3500)
CodingWithTim Aug 28, 2024
93037a4
Add load test (#3496)
BabyChouSr Aug 30, 2024
8714da2
Fix load test (#3508)
BabyChouSr Aug 31, 2024
b11f710
Merge branch 'main' into moderation-log
BabyChouSr Aug 31, 2024
571f39e
Merge branch 'main' into moderation-log
BabyChouSr Aug 31, 2024
3555d01
Merge remote-tracking branch 'fastchat/operation-202407' into moderat…
BabyChouSr Aug 31, 2024
fe45c6f
Format
BabyChouSr Aug 31, 2024
a2200e4
Merge with unified vision arena
BabyChouSr Aug 31, 2024
c90b8fc
Fix edge case
BabyChouSr Aug 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions fastchat/serve/gradio_block_arena_anony.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
get_ip,
get_model_description_md,
)
from fastchat.serve.moderation.moderator import AzureAndOpenAIContentModerator
from fastchat.serve.remote_logger import get_remote_logger
from fastchat.utils import (
build_logger,
moderation_filter,
)

logger = build_logger("gradio_web_server_multi", "gradio_web_server_multi.log")
Expand Down Expand Up @@ -201,6 +201,9 @@ def get_battle_pair(
if len(models) == 1:
return models[0], models[0]

if len(models) == 0:
raise ValueError("There are no models provided. Cannot get battle pair.")

model_weights = []
for model in models:
weight = get_sample_weight(
Expand Down Expand Up @@ -289,7 +292,11 @@ def add_text(
all_conv_text = (
all_conv_text_left[-1000:] + all_conv_text_right[-1000:] + "\nuser: " + text
)
flagged = moderation_filter(all_conv_text, model_list, do_moderation=True)

content_moderator = AzureAndOpenAIContentModerator()
flagged = content_moderator.text_moderation_filter(
all_conv_text, model_list, do_moderation=True
)
if flagged:
logger.info(f"violate moderation (anony). ip: {ip}. text: {text}")
# overwrite the original text
Expand Down
49 changes: 33 additions & 16 deletions fastchat/serve/gradio_block_arena_named.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
get_ip,
get_model_description_md,
)
from fastchat.serve.moderation.moderator import AzureAndOpenAIContentModerator
from fastchat.serve.remote_logger import get_remote_logger
from fastchat.utils import (
build_logger,
moderation_filter,
)

logger = build_logger("gradio_web_server_multi", "gradio_web_server_multi.log")
Expand Down Expand Up @@ -174,19 +174,29 @@ def add_text(
no_change_btn,
]
* 6
+ [True]
)

model_list = [states[i].model_name for i in range(num_sides)]
all_conv_text_left = states[0].conv.get_prompt()
all_conv_text_right = states[1].conv.get_prompt()
all_conv_text = (
all_conv_text_left[-1000:] + all_conv_text_right[-1000:] + "\nuser: " + text
)
flagged = moderation_filter(all_conv_text, model_list)
if flagged:
logger.info(f"violate moderation (named). ip: {ip}. text: {text}")
# overwrite the original text
text = MODERATION_MSG
content_moderator = AzureAndOpenAIContentModerator()
text_flagged = content_moderator.text_moderation_filter(text, model_list)

if text_flagged:
logger.info(f"violate moderation. ip: {ip}. text: {text}")
content_moderator.write_to_json(get_ip(request))
BabyChouSr marked this conversation as resolved.
Show resolved Hide resolved
for i in range(num_sides):
states[i].skip_next = True
gr.Warning(MODERATION_MSG)
return (
states
+ [x.to_gradio_chatbot() for x in states]
+ [""]
+ [
no_change_btn,
]
* 6
+ [True]
)

conv = states[0].conv
if (len(conv.messages) - conv.offset) // 2 >= CONVERSATION_TURN_LIMIT:
Expand All @@ -201,6 +211,7 @@ def add_text(
no_change_btn,
]
* 6
+ [True]
)

text = text[:INPUT_CHAR_LEN_LIMIT] # Hard cut-off
Expand All @@ -217,6 +228,7 @@ def add_text(
disable_btn,
]
* 6
+ [False]
)


Expand Down Expand Up @@ -295,7 +307,11 @@ def bot_response_multi(
break


def flash_buttons():
def flash_buttons(dont_show_vote_buttons: bool = False):
if dont_show_vote_buttons:
yield [no_change_btn] * 4 + [enable_btn] * 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this actually ends up breaking the ui - need to keep yield + return pattern

return

btn_updates = [
[disable_btn] * 4 + [enable_btn] * 2,
[enable_btn] * 6,
Expand All @@ -321,6 +337,7 @@ def build_side_by_side_ui_named(models):
states = [gr.State() for _ in range(num_sides)]
model_selectors = [None] * num_sides
chatbots = [None] * num_sides
dont_show_vote_buttons = gr.State(False)

notice = gr.Markdown(notice_markdown, elem_id="notice_markdown")

Expand Down Expand Up @@ -476,24 +493,24 @@ def build_side_by_side_ui_named(models):
textbox.submit(
add_text,
states + model_selectors + [textbox],
states + chatbots + [textbox] + btn_list,
states + chatbots + [textbox] + btn_list + [dont_show_vote_buttons],
).then(
bot_response_multi,
states + [temperature, top_p, max_output_tokens],
states + chatbots + btn_list,
).then(
flash_buttons, [], btn_list
flash_buttons, [dont_show_vote_buttons], btn_list
)
send_btn.click(
add_text,
states + model_selectors + [textbox],
states + chatbots + [textbox] + btn_list,
states + chatbots + [textbox] + btn_list + [dont_show_vote_buttons],
).then(
bot_response_multi,
states + [temperature, top_p, max_output_tokens],
states + chatbots + btn_list,
).then(
flash_buttons, [], btn_list
flash_buttons, [dont_show_vote_buttons], btn_list
)

return states + model_selectors
71 changes: 31 additions & 40 deletions fastchat/serve/gradio_block_arena_vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@
get_conv_log_filename,
get_remote_logger,
)
from fastchat.serve.moderation.moderator import AzureAndOpenAIContentModerator
from fastchat.serve.vision.image import ImageFormat, Image
from fastchat.utils import (
build_logger,
moderation_filter,
image_moderation_filter,
)

logger = build_logger("gradio_web_server", "gradio_web_server.log")
Expand All @@ -51,8 +50,16 @@
invisible_btn = gr.Button(interactive=False, visible=False)
visible_image_column = gr.Image(visible=True)
invisible_image_column = gr.Image(visible=False)
enable_multimodal = gr.MultimodalTextbox(
interactive=True, visible=True, placeholder="Enter your prompt or add image here"
enable_multimodal_keep_input = gr.MultimodalTextbox(
interactive=True,
visible=True,
placeholder="Enter your prompt or add image here",
)
enable_multimodal_clear_input = gr.MultimodalTextbox(
interactive=True,
visible=True,
placeholder="Enter your prompt or add image here",
value={"text": "", "files": []},
)
invisible_text = gr.Textbox(visible=False, value="", interactive=False)
visible_text = gr.Textbox(
Expand Down Expand Up @@ -144,22 +151,22 @@ def clear_history(request: gr.Request):
ip = get_ip(request)
logger.info(f"clear_history. ip: {ip}")
state = None
return (state, [], None) + (disable_btn,) * 5
return (state, [], enable_multimodal_clear_input) + (disable_btn,) * 5


def clear_history_example(request: gr.Request):
ip = get_ip(request)
logger.info(f"clear_history_example. ip: {ip}")
state = None
return (state, [], enable_multimodal) + (disable_btn,) * 5
return (state, [], enable_multimodal_keep_input) + (disable_btn,) * 5


# TODO(Chris): At some point, we would like this to be a live-reporting feature.
def report_csam_image(state, image):
pass


def _prepare_text_with_image(state, text, images, csam_flag):
def _prepare_text_with_image(state, text, images):
if len(images) > 0:
if len(state.conv.get_images()) > 0:
# reset convo with new image
Expand All @@ -184,31 +191,6 @@ def convert_images_to_conversation_format(images):
return conv_images


def moderate_input(state, text, all_conv_text, model_list, images, ip):
text_flagged = moderation_filter(all_conv_text, model_list)
# flagged = moderation_filter(text, [state.model_name])
nsfw_flagged, csam_flagged = False, False
if len(images) > 0:
nsfw_flagged, csam_flagged = image_moderation_filter(images[0])

image_flagged = nsfw_flagged or csam_flagged
if text_flagged or image_flagged:
logger.info(f"violate moderation. ip: {ip}. text: {all_conv_text}")
if text_flagged and not image_flagged:
# overwrite the original text
text = TEXT_MODERATION_MSG
elif not text_flagged and image_flagged:
text = IMAGE_MODERATION_MSG
elif text_flagged and image_flagged:
text = MODERATION_MSG

if csam_flagged:
state.has_csam_image = True
report_csam_image(state, images[0])

return text, image_flagged, csam_flagged


def add_text(state, model_selector, chat_input, request: gr.Request):
text, images = chat_input["text"], chat_input["files"]
ip = get_ip(request)
Expand All @@ -226,16 +208,25 @@ def add_text(state, model_selector, chat_input, request: gr.Request):

images = convert_images_to_conversation_format(images)

text, image_flagged, csam_flag = moderate_input(
state, text, all_conv_text, [state.model_name], images, ip
)
content_moderator = AzureAndOpenAIContentModerator()
text_flagged = content_moderator.text_moderation_filter(text, [state.model_name])
if len(images) > 0:
nsfw_flag, csam_flag = content_moderator.image_moderation_filter(images[0])
image_flagged = nsfw_flag or csam_flag
if csam_flag:
state.has_csam_image = True
else:
image_flagged = False

if image_flagged:
if text_flagged or image_flagged:
logger.info(f"violate moderation. ip: {ip}. text: {text}")
content_moderator.write_to_json(get_ip(request))

if image_flagged or text_flagged:
logger.info(f"image flagged. ip: {ip}. text: {text}")
state.skip_next = True
return (state, state.to_gradio_chatbot(), {"text": IMAGE_MODERATION_MSG}) + (
no_change_btn,
) * 5
gr.Warning(MODERATION_MSG)
return (state, state.to_gradio_chatbot(), None) + (no_change_btn,) * 5

if (len(state.conv.messages) - state.conv.offset) // 2 >= CONVERSATION_TURN_LIMIT:
logger.info(f"conversation turn limit. ip: {ip}. text: {text}")
Expand All @@ -245,7 +236,7 @@ def add_text(state, model_selector, chat_input, request: gr.Request):
) * 5

text = text[:INPUT_CHAR_LEN_LIMIT] # Hard cut-off
text = _prepare_text_with_image(state, text, images, csam_flag=csam_flag)
text = _prepare_text_with_image(state, text, images)
state.conv.append_message(state.conv.roles[0], text)
state.conv.append_message(state.conv.roles[1], None)
return (state, state.to_gradio_chatbot(), None) + (disable_btn,) * 5
Expand Down
Loading
Loading