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

remove format_for_markdown_visualization #723

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
logger = logging.getLogger(__name__)


def on_startup():
def on_startup() -> None:
initialize_logging()
logger.info("STARTING APP")


@app("/", on_startup=on_startup)
async def serve(q: Q):
async def serve(q: Q) -> None:
"""Serving function."""

# Chat is still being streamed but user clicks on another button.
Expand Down
1 change: 0 additions & 1 deletion llm_studio/app_utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def get_size(x):
"validation_dataframe",
],
"user_settings": {
"theme_dark": True,
"credential_saver": ".env File",
"default_aws_bucket_name": f"{os.getenv('AWS_BUCKET', 'bucket_name')}",
"default_aws_access_key": os.getenv("AWS_ACCESS_KEY_ID", ""),
Expand Down
2 changes: 1 addition & 1 deletion llm_studio/app_utils/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ async def handle(q: Q) -> None:
)


async def experiment_delete_all_artifacts(q: Q, experiment_ids: List[int]):
async def experiment_delete_all_artifacts(q: Q, experiment_ids: List[int]) -> None:
await experiment_stop(q, experiment_ids)
await experiment_delete(q, experiment_ids)
await list_current_experiments(q)
1 change: 1 addition & 0 deletions llm_studio/app_utils/sections/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def gpu_is_blocked(q, gpu_id):
def load_cfg_model_tokenizer(
experiment_path: str, merge: bool = False, device: str = "cuda:0"
):
"""Loads the model, tokenizer and configuration from the experiment path."""
cfg = load_config_yaml(os.path.join(experiment_path, "cfg.yaml"))
cfg.architecture.pretrained = False
cfg.architecture.gradient_checkpointing = False
Expand Down
2 changes: 1 addition & 1 deletion llm_studio/app_utils/sections/chat_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ async def show_stream_is_aborted_dialog(q):
await q.page.save()


async def is_app_blocked_while_streaming(q: Q):
async def is_app_blocked_while_streaming(q: Q) -> bool:
"""
Check whether the app is blocked with current answer generation.
"""
Expand Down
122 changes: 80 additions & 42 deletions llm_studio/app_utils/sections/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,84 @@
logger = logging.getLogger(__name__)


# https://github.com/highlightjs/highlight.js/blob/main/src/styles/atom-one-dark.css.
css = """
.hljs {
color: #abb2bf;
}

.hljs-comment,
.hljs-quote {
color: #5c6370;
font-style: italic;
}

.hljs-doctag,
.hljs-keyword,
.hljs-formula {
color: #c678dd;
}

.hljs-section,
.hljs-name,
.hljs-selector-tag,
.hljs-deletion,
.hljs-subst {
color: #e06c75;
}

.hljs-literal {
color: #56b6c2;
}

.hljs-string,
.hljs-regexp,
.hljs-addition,
.hljs-attribute,
.hljs-meta .hljs-string {
color: #98c379;
}

.hljs-attr,
.hljs-variable,
.hljs-template-variable,
.hljs-type,
.hljs-selector-class,
.hljs-selector-attr,
.hljs-selector-pseudo,
.hljs-number {
color: #d19a66;
}

.hljs-symbol,
.hljs-bullet,
.hljs-link,
.hljs-meta,
.hljs-selector-id,
.hljs-title {
color: #61aeee;
}

.hljs-built_in,
.hljs-title.class_,
.hljs-class .hljs-title {
color: #e6c07b;
}

.hljs-emphasis {
font-style: italic;
}

.hljs-strong {
font-weight: bold;
}

.hljs-link {
text-decoration: underline;
}
"""


async def meta(q: Q) -> None:
if q.client["keep_meta"]: # Do not reset meta, keep current dialog opened
q.client["keep_meta"] = False
Expand Down Expand Up @@ -37,52 +115,12 @@ async def meta(q: Q) -> None:
scripts=[
ui.script(source, asynchronous=True) for source in q.app["script_sources"]
],
stylesheet=ui.inline_stylesheet(
"""
.ms-MessageBar {
padding-top: 3px;
padding-bottom: 3px;
min-height: 18px;
}
div[data-test="nav_bar"] .ms-Nav-groupContent {
margin-bottom: 0;
}

div[data-test="experiment/display/deployment/top_right"],
div[data-test="experiment/display/deployment/top_right"]
div[data-visible="true"]:last-child > div > div {
display: flex;
}

div[data-test="experiment/display/deployment/top_right"]
div[data-visible="true"]:last-child,
div[data-test="experiment/display/deployment/top_right"]
div[data-visible="true"]:last-child > div {
display: flex;
flex-grow: 1;
}

div[data-test="experiment/display/deployment/top_right"]
div[data-visible="true"]:last-child > div > div > div {
display: flex;
flex-grow: 1;
flex-direction: column;
}

div[data-test="experiment/display/deployment/top_right"]
div[data-visible="true"]:last-child > div > div > div > div {
flex-grow: 1;
}
"""
),
stylesheet=ui.inline_stylesheet(css),
script=None,
notification_bar=notification_bar,
)

if q.client.theme_dark:
q.page["meta"].theme = "h2o-dark"
else:
q.page["meta"].theme = "light"
q.page["meta"].theme = "h2o-dark"


def heap_analytics(
Expand Down
16 changes: 9 additions & 7 deletions llm_studio/app_utils/sections/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ async def dataset_delete_single(q: Q, dataset_id: int):
async def dataset_display(q: Q) -> None:
"""Display a selected dataset."""

dataset_id = q.client["dataset/list/df_datasets"]["id"].iloc[
dataset_id: int = q.client["dataset/list/df_datasets"]["id"].iloc[
q.client["dataset/display/id"]
]
dataset: Dataset = q.client.app_db.get_dataset(dataset_id)
Expand Down Expand Up @@ -1159,7 +1159,7 @@ async def show_data_tab(q, cfg, filename: str):
q.client.delete_cards.add("dataset/display/data")


async def show_visualization_tab(q, cfg):
async def show_visualization_tab(q: Q, cfg):
try:
plot = cfg.logging.plots_class.plot_data(cfg)
except Exception as error:
Expand Down Expand Up @@ -1199,7 +1199,7 @@ async def show_visualization_tab(q, cfg):
q.client.delete_cards.add("dataset/display/visualization")


async def show_summary_tab(q, dataset_id):
async def show_summary_tab(q: Q, dataset_id: int) -> None:
dataset_df = get_datasets(q)
dataset_df = dataset_df[dataset_df.id == dataset_id]
stat_list_items: List[StatListItem] = []
Expand All @@ -1216,7 +1216,9 @@ async def show_summary_tab(q, dataset_id):
q.client.delete_cards.add("dataset/display/summary")


async def show_statistics_tab(q, dataset_filename, config_filename):
async def show_statistics_tab(
q: Q, dataset_filename: str, config_filename: str
) -> None:
cfg_hash = hashlib.md5(open(config_filename, "rb").read()).hexdigest()
stats_dict = compute_dataset_statistics(dataset_filename, config_filename, cfg_hash)

Expand Down Expand Up @@ -1283,7 +1285,7 @@ async def show_statistics_tab(q, dataset_filename, config_filename):


@functools.lru_cache()
def compute_dataset_statistics(dataset_path: str, cfg_path: str, cfg_hash: str):
def compute_dataset_statistics(dataset_path: str, cfg_path: str, cfg_hash: str) -> dict:
"""
Compute various statistics for a dataset.
- text length distribution for prompts and answers
Expand Down Expand Up @@ -1325,7 +1327,7 @@ def compute_dataset_statistics(dataset_path: str, cfg_path: str, cfg_hash: str):
return stats_dict


async def dataset_import_uploaded_file(q: Q):
async def dataset_import_uploaded_file(q: Q) -> None:
local_path = await q.site.download(
q.args["dataset/import/local_upload"][0],
f"{get_data_dir(q)}/"
Expand All @@ -1341,7 +1343,7 @@ async def dataset_import_uploaded_file(q: Q):
await dataset_import(q, step=1, error=error)


async def dataset_delete_current_datasets(q: Q):
async def dataset_delete_current_datasets(q: Q) -> None:
dataset_ids = list(
q.client["dataset/list/df_datasets"]["id"].iloc[
list(map(int, q.client["dataset/list/table"]))
Expand Down
3 changes: 2 additions & 1 deletion llm_studio/app_utils/sections/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,7 @@ async def summary_tab(experiment_id, q):
box=ui.box(zone="third"),
title="",
content=content,
compact=False,
)
q.client.delete_cards.add(card_name)

Expand Down Expand Up @@ -1363,7 +1364,7 @@ def unite_validation_metric_charts(charts_list):
return charts_list


async def charts_tab(q, charts_list, legend_labels):
async def charts_tab(q, charts_list, legend_labels) -> None:
charts_list = unite_validation_metric_charts(charts_list)

box = ["first", "first", "second", "second"]
Expand Down
11 changes: 0 additions & 11 deletions llm_studio/app_utils/sections/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,6 @@ async def settings(q: Q) -> None:
""",
),
ui.separator("Appearance"),
ui.inline(
items=[
ui.label("Dark Mode", width=label_width),
ui.toggle(
name="theme_dark",
value=q.client["theme_dark"],
tooltip="Enables Dark Mode as theme.",
trigger=True,
),
]
),
ui.inline(
items=[
ui.label("Delete Dialogs", width=label_width),
Expand Down
2 changes: 1 addition & 1 deletion llm_studio/app_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ async def poll(self):
await self.update_ui()


def s3_download_coroutine(q, filename):
def s3_download_coroutine(q: Q, filename: str):
download_folder = f"{get_data_dir(q)}/tmp"
download_folder = get_valid_temp_data_folder(q, download_folder)

Expand Down
26 changes: 6 additions & 20 deletions llm_studio/app_utils/wave_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,14 @@


class ThemeColors(TypedDict):
light: dict
dark: dict
primary: str
background_color: str


class WaveTheme:
_theme_colors: ThemeColors = {
"light": {
"primary": "#000000",
"background_color": "#ffffff",
},
"dark": {
"primary": "#FEC925",
"background_color": "#121212",
},
"primary": "#FEC925",
"background_color": "#121212",
}

states = {
Expand All @@ -43,20 +37,12 @@ class WaveTheme:
def __repr__(self) -> str:
return "WaveTheme"

def get_value_by_key(self, q: Q, key: str):
value = (
self._theme_colors["dark"][key]
if q.client.theme_dark
else self._theme_colors["light"][key]
)
return value

def get_primary_color(self, q: Q):
primary_color = self.get_value_by_key(q, "primary")
primary_color = self._theme_colors["primary"]
return primary_color

def get_background_color(self, q: Q):
background_color = self.get_value_by_key(q, "background_color")
background_color = self._theme_colors["background_color"]
return background_color


Expand Down
5 changes: 3 additions & 2 deletions llm_studio/python_configs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DefaultConfig:
Template for any configuration file
"""

def __post_init__(self):
def __post_init__(self) -> None:
self._possible_values: Dict[str, Any] = {k: None for k in self.__dict__}
self._visibility = {k: 0 for k in self.__dict__}

Expand Down Expand Up @@ -156,7 +156,7 @@ def _get_order(self, warn_if_unset=True) -> List[str]:
return ordered_keys + unordered_keys

@classmethod
def get_annotations(cls):
def get_annotations(cls) -> Dict[str, Any]:
"""Returns type annotations through all the Parent config classes"""

d: Dict[str, Any] = {}
Expand Down Expand Up @@ -189,6 +189,7 @@ class DefaultConfigProblemBase(DefaultConfig):
experiment_name: str
output_directory: str
llm_backbone: str
_parent_experiment: str

dataset: Any
tokenizer: Any
Expand Down
4 changes: 2 additions & 2 deletions llm_studio/src/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def __init__(self, keys: Optional[List[str]] = None):
else:
self._list = list()

def _unique_guard(self, *keys: str):
def _unique_guard(self, *keys: str) -> None:
for key in keys:
if key in self._list:
raise ValueError(f"`{key}` is already in the list!")

def append(self, key: str):
def append(self, key: str) -> None:
"""
Append a key at the end of the list:

Expand Down
Loading