Skip to content

Commit

Permalink
Shark-1.0: Update gradio to 4.19.2 (#2098)
Browse files Browse the repository at this point in the history
* Shark-1.0: Update gradio to 4.19.2

- Move pin for gradio from 4.12 -> 4.19.2 on SHARK-1.0 branch
- Fix png import txt2img/txt2img_sdxl event handling for gradio 4.19.2
- Fix sendto txt2img/txt2img_sdxl event handling for gradio 4.19.2

* Shark-1.0: Reformat with black

- Apply the new (2024) black reformattings
  • Loading branch information
one-lithe-rune authored Mar 1, 2024
1 parent 85ae2ee commit 9fc0b5b
Show file tree
Hide file tree
Showing 31 changed files with 281 additions and 225 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ cython_debug/
*venv/
shark_tmp/
*.vmfb
*.safetensors
.use-iree
tank/dict_configs.py
*.csv
Expand Down
6 changes: 3 additions & 3 deletions apps/language_models/langchain/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ def run_cli( # for local function:
eval_vars[eval_func_param_names.index("iinput")] = eval_vars[
eval_func_param_names.index("iinput_nochat")
] = "" # no input yet
eval_vars[
eval_func_param_names.index("context")
] = "" # no context yet
eval_vars[eval_func_param_names.index("context")] = (
"" # no context yet
)

# grab other parameters, like langchain_mode
for k in eval_func_param_names:
Expand Down
18 changes: 10 additions & 8 deletions apps/language_models/langchain/create_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,16 @@ def test_config_to_json():
"\n", ""
),
},
{
"prompt_type": "plain",
"instruction": f"<human>: How can I do this: {title}.\n<bot>: Set the {k.replace('_', ' ')} config.toml\n<human>:".replace(
"\n", ""
),
}
if title and comment
else None,
(
{
"prompt_type": "plain",
"instruction": f"<human>: How can I do this: {title}.\n<bot>: Set the {k.replace('_', ' ')} config.toml\n<human>:".replace(
"\n", ""
),
}
if title and comment
else None
),
{
"prompt_type": "human_bot",
"instruction": f"Explain the following expert setting for Driverless AI",
Expand Down
66 changes: 36 additions & 30 deletions apps/language_models/langchain/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,19 +582,19 @@ def get_hf_model(
tokenizer,
model=base_model,
device=0 if self.device == "cuda" else -1,
torch_dtype=torch.float16
if self.device == "cuda"
else torch.float32,
torch_dtype=(
torch.float16 if self.device == "cuda" else torch.float32
),
)
else:
assert self.device in ["cuda", "cpu", "mps"], (
"Unsupported device %s" % self.device
)
model_kwargs = dict(
local_files_only=local_files_only,
torch_dtype=torch.float16
if self.device == "cuda"
else torch.float32,
torch_dtype=(
torch.float16 if self.device == "cuda" else torch.float32
),
resume_download=resume_download,
use_auth_token=use_auth_token,
trust_remote_code=trust_remote_code,
Expand Down Expand Up @@ -628,9 +628,9 @@ def get_hf_model(
# MPT doesn't support spreading over GPUs
model_kwargs.update(
dict(
device_map={"": gpu_id}
if self.device == "cuda"
else "cpu"
device_map=(
{"": gpu_id} if self.device == "cuda" else "cpu"
)
)
)

Expand Down Expand Up @@ -689,17 +689,19 @@ def get_hf_model(
model = PeftModel.from_pretrained(
model,
lora_weights,
torch_dtype=torch.float16
if self.device == "cuda"
else torch.float32,
torch_dtype=(
torch.float16
if self.device == "cuda"
else torch.float32
),
local_files_only=local_files_only,
resume_download=resume_download,
use_auth_token=use_auth_token,
trust_remote_code=trust_remote_code,
offload_folder=offload_folder,
device_map={"": 0}
if self.device == "cuda"
else {"": "cpu"}, # seems to be required
device_map=(
{"": 0} if self.device == "cuda" else {"": "cpu"}
), # seems to be required
)
else:
with torch.device(self.device):
Expand All @@ -716,9 +718,11 @@ def get_hf_model(
model = PeftModel.from_pretrained(
model,
lora_weights,
torch_dtype=torch.float16
if self.device == "cuda"
else torch.float32,
torch_dtype=(
torch.float16
if self.device == "cuda"
else torch.float32
),
local_files_only=local_files_only,
resume_download=resume_download,
use_auth_token=use_auth_token,
Expand Down Expand Up @@ -1143,9 +1147,9 @@ def evaluate(
db=db1,
user_path=user_path,
detect_user_path_changes_every_query=detect_user_path_changes_every_query,
cut_distanct=1.1
if langchain_mode in ["wiki_full"]
else 1.64, # FIXME, too arbitrary
cut_distanct=(
1.1 if langchain_mode in ["wiki_full"] else 1.64
), # FIXME, too arbitrary
use_openai_embedding=use_openai_embedding,
use_openai_model=use_openai_model,
hf_embedding_model=hf_embedding_model,
Expand Down Expand Up @@ -1523,9 +1527,11 @@ def mean(a):""",
examples += [
[
summarize_example1,
"Summarize"
if prompt_type not in ["plain", "instruct_simple"]
else "",
(
"Summarize"
if prompt_type not in ["plain", "instruct_simple"]
else ""
),
]
+ params_list
]
Expand All @@ -1548,14 +1554,14 @@ def mean(a):""",
]
# adjust examples if non-chat mode
if not chat:
example[
eval_func_param_names.index("instruction_nochat")
] = example[eval_func_param_names.index("instruction")]
example[eval_func_param_names.index("instruction_nochat")] = (
example[eval_func_param_names.index("instruction")]
)
example[eval_func_param_names.index("instruction")] = ""

example[
eval_func_param_names.index("iinput_nochat")
] = example[eval_func_param_names.index("iinput")]
example[eval_func_param_names.index("iinput_nochat")] = (
example[eval_func_param_names.index("iinput")]
)
example[eval_func_param_names.index("iinput")] = ""
assert len(example) == len(
eval_func_param_names
Expand Down
6 changes: 3 additions & 3 deletions apps/language_models/langchain/gpt_langchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,9 @@ def _call(
chunk = True
chunk_size = 512
client_kwargs = dict(
instruction=prompt
if self.chat_client
else "", # only for chat=True
instruction=(
prompt if self.chat_client else ""
), # only for chat=True
iinput="", # only for chat=True
context="",
# streaming output is supported, loops over and outputs each generation in streaming mode
Expand Down
6 changes: 3 additions & 3 deletions apps/language_models/langchain/h2oai_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,9 @@ def generate_token(h2ogpt_shark_model, model, tokenizer, **generate_kwargs):
)

model_kwargs["output_attentions"] = generation_config.output_attentions
model_kwargs[
"output_hidden_states"
] = generation_config.output_hidden_states
model_kwargs["output_hidden_states"] = (
generation_config.output_hidden_states
)
model_kwargs["use_cache"] = generation_config.use_cache

input_ids = (
Expand Down
1 change: 1 addition & 0 deletions apps/language_models/langchain/image_captions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
https://huggingface.co/Salesforce/blip-image-captioning-base
"""

from typing import List, Union, Any, Tuple

import requests
Expand Down
9 changes: 6 additions & 3 deletions apps/language_models/langchain/read_wiki_full.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Load Data from a MediaWiki dump xml."""

import ast
import glob
import pickle
Expand Down Expand Up @@ -105,9 +106,11 @@ def load(self) -> List[Document]:
source="https://en.wikipedia.org/wiki/" + title_url,
id=page.id,
redirect=page.redirect,
views=self.views[page.title]
if self.views is not None
else -1,
views=(
self.views[page.title]
if self.views is not None
else -1
),
)
metadata = {k: v for k, v in metadata.items() if v is not None}
docs.append(Document(page_content=text, metadata=metadata))
Expand Down
80 changes: 45 additions & 35 deletions apps/language_models/src/pipelines/falcon_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,18 @@ def compile_layer(
path = shark_module.save_module(
self.falcon_vmfb_path.parent.absolute(),
self.falcon_vmfb_path.stem,
extra_args=[
"--iree-vm-target-truncate-unsupported-floats",
"--iree-codegen-check-ir-before-llvm-conversion=false",
"--iree-vm-bytecode-module-output-format=flatbuffer-binary",
]
+ [
"--iree-llvmcpu-use-fast-min-max-ops",
]
if self.precision == "int4"
else [],
extra_args=(
[
"--iree-vm-target-truncate-unsupported-floats",
"--iree-codegen-check-ir-before-llvm-conversion=false",
"--iree-vm-bytecode-module-output-format=flatbuffer-binary",
]
+ [
"--iree-llvmcpu-use-fast-min-max-ops",
]
if self.precision == "int4"
else []
),
debug=self.debug,
)
print("Saved falcon vmfb at ", str(path))
Expand Down Expand Up @@ -326,9 +328,11 @@ def compile(self):
lm_head,
[sample_hidden_states],
"lm_head",
device_idx=(0 % num_devices) % args.num_shards
if self.device == "rocm"
else None,
device_idx=(
(0 % num_devices) % args.num_shards
if self.device == "rocm"
else None
),
)
shark_lm_head = CompiledLMHeadEmbeddingLayer(shark_lm_head)

Expand All @@ -340,9 +344,11 @@ def compile(self):
word_embedding,
[sample_input_ids],
"word_embeddings",
device_idx=(1 % num_devices) % args.num_shards
if self.device == "rocm"
else None,
device_idx=(
(1 % num_devices) % args.num_shards
if self.device == "rocm"
else None
),
)
shark_word_embedding = CompiledWordEmbeddingsLayer(
shark_word_embedding
Expand All @@ -354,9 +360,11 @@ def compile(self):
ln_f,
[sample_hidden_states],
"ln_f",
device_idx=(2 % num_devices) % args.num_shards
if self.device == "rocm"
else None,
device_idx=(
(2 % num_devices) % args.num_shards
if self.device == "rocm"
else None
),
)
shark_ln_f = CompiledLNFEmbeddingLayer(shark_ln_f)

Expand Down Expand Up @@ -458,9 +466,9 @@ def generate(self, prompt):
)

model_kwargs["output_attentions"] = generation_config.output_attentions
model_kwargs[
"output_hidden_states"
] = generation_config.output_hidden_states
model_kwargs["output_hidden_states"] = (
generation_config.output_hidden_states
)
model_kwargs["use_cache"] = generation_config.use_cache

input_ids = (
Expand Down Expand Up @@ -790,16 +798,18 @@ def compile(self):
path = shark_module.save_module(
self.falcon_vmfb_path.parent.absolute(),
self.falcon_vmfb_path.stem,
extra_args=[
"--iree-vm-target-truncate-unsupported-floats",
"--iree-codegen-check-ir-before-llvm-conversion=false",
"--iree-vm-bytecode-module-output-format=flatbuffer-binary",
]
+ [
"--iree-llvmcpu-use-fast-min-max-ops",
]
if self.precision == "int4"
else [],
extra_args=(
[
"--iree-vm-target-truncate-unsupported-floats",
"--iree-codegen-check-ir-before-llvm-conversion=false",
"--iree-vm-bytecode-module-output-format=flatbuffer-binary",
]
+ [
"--iree-llvmcpu-use-fast-min-max-ops",
]
if self.precision == "int4"
else []
),
debug=self.debug,
)
print("Saved falcon vmfb at ", str(path))
Expand Down Expand Up @@ -859,9 +869,9 @@ def generate(self, prompt):
batch_size = inputs_tensor.shape[0]

model_kwargs["output_attentions"] = generation_config.output_attentions
model_kwargs[
"output_hidden_states"
] = generation_config.output_hidden_states
model_kwargs["output_hidden_states"] = (
generation_config.output_hidden_states
)
model_kwargs["use_cache"] = generation_config.use_cache

input_ids = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
SPDX-License-Identifier: BSD-3-Clause
For full license text, see the LICENSE_Lavis file in the repo root or https://opensource.org/licenses/BSD-3-Clause
"""

from omegaconf import OmegaConf
from torchvision import transforms
from torchvision.transforms.functional import InterpolationMode
Expand Down
14 changes: 8 additions & 6 deletions apps/language_models/src/pipelines/minigpt4_utils/eva_vit.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,9 @@ def __init__(
super().__init__()
self.image_size = img_size
self.num_classes = num_classes
self.num_features = (
self.embed_dim
) = embed_dim # num_features for consistency with other models
self.num_features = self.embed_dim = (
embed_dim # num_features for consistency with other models
)

self.patch_embed = PatchEmbed(
img_size=img_size,
Expand Down Expand Up @@ -429,9 +429,11 @@ def __init__(
drop_path=dpr[i],
norm_layer=norm_layer,
init_values=init_values,
window_size=self.patch_embed.patch_shape
if use_rel_pos_bias
else None,
window_size=(
self.patch_embed.patch_shape
if use_rel_pos_bias
else None
),
)
for i in range(depth)
]
Expand Down
Loading

0 comments on commit 9fc0b5b

Please sign in to comment.