Skip to content

Commit

Permalink
[max-examples] GUI: Improvements and fixes
Browse files Browse the repository at this point in the history
- Bert: display top 5 examples by default
- Llamma3: use 3.1 models by default
- Rag: put example data in `ragdata` folder so it doesn't crash
- Stable Diffusion: fix data type being incorrect
- Yolo: move yoloconstants.py CLASS_NAMES into yolo.py

MODULAR_ORIG_COMMIT_REV_ID: 5567ef1680b1f697f5b1cacbcd897f1d08564301
  • Loading branch information
jackos authored and modularbot committed Sep 13, 2024
1 parent 70ec6f4 commit 458cfc0
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/gui/pages/bert.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def softmax(logits):
model_state = st.empty()

mlm = st.sidebar.checkbox("Masked Language Model", True)
show_predictions = st.sidebar.checkbox("Show top 5 predictions", True)
filename = "bert.torchscript"
if mlm:
filename = "bert-mlm.torchscript"
Expand All @@ -102,7 +103,6 @@ def softmax(logits):
batch = st.sidebar.number_input("Batch Size", 1, 64)
seq_len = st.sidebar.slider("Sequence Length", 128, 1024)
input_text = st.text_input("Text Input", "Don't [MASK] about it")
show_predictions = st.sidebar.checkbox("Show top 5 predictions")

compile_torchscript(batch, seq_len, mlm)

Expand Down
6 changes: 3 additions & 3 deletions examples/gui/pages/llama3.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ def start_llama3(
)

if quantization == "q4_0":
model_url = "https://huggingface.co/QuantFactory/Meta-Llama-3-8B-Instruct-GGUF/resolve/main/Meta-Llama-3-8B-Instruct.Q4_0.gguf"
model_url = "https://huggingface.co/QuantFactory/Meta-Llama-3-8B-Instruct-GGUF/resolve/main/Meta-Llama-3.1-8B-Instruct.Q4_0.gguf"
elif quantization == "q4_k":
model_url = "https://huggingface.co/bartowski/Meta-Llama-3-8B-Instruct-GGUF/resolve/main/Meta-Llama-3-8B-Instruct-Q4_K_M.gguf"
model_url = "https://huggingface.co/bartowski/Meta-Llama-3-8B-Instruct-GGUF/resolve/main/Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf"
elif quantization == "q6_k":
model_url = "https://huggingface.co/bartowski/Meta-Llama-3-8B-Instruct-GGUF/resolve/main/Meta-Llama-3-8B-Instruct-Q6_K.gguf"
model_url = "https://huggingface.co/bartowski/Meta-Llama-3-8B-Instruct-GGUF/resolve/main/Meta-Llama-3.1-8B-Instruct-Q6_K.gguf"

model_url = st.sidebar.text_input("Model URL", value=model_url)
os.makedirs(modular_cache_dir(), exist_ok=True)
Expand Down
11 changes: 5 additions & 6 deletions examples/gui/pages/rag.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ===----------------------------------------------------------------------=== #
from pathlib import Path
import os
import subprocess
from pathlib import Path

import chromadb
import openai
import streamlit as st
import chromadb
from fastembed import TextEmbedding
from llama_index.core import SimpleDirectoryReader

from shared import download_file, kill_process, menu, modular_cache_dir

st.set_page_config("RAG with Llama3", page_icon="🗣️ 📄")
Expand Down Expand Up @@ -153,11 +152,11 @@ def start_llama3(
)

if quantization == "q4_0":
model_url = "https://huggingface.co/QuantFactory/Meta-Llama-3-8B-GGUF/resolve/main/Meta-Llama-3-8B.Q4_0.gguf"
model_url = "https://huggingface.co/QuantFactory/Meta-Llama-3-8B-Instruct-GGUF/resolve/main/Meta-Llama-3.1-8B-Instruct.Q4_0.gguf"
elif quantization == "q4_k":
model_url = "https://huggingface.co/bartowski/Meta-Llama-3-8B-Instruct-GGUF/resolve/main/Meta-Llama-3-8B-Instruct-Q4_K_M.gguf"
model_url = "https://huggingface.co/bartowski/Meta-Llama-3-8B-Instruct-GGUF/resolve/main/Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf"
elif quantization == "q6_k":
model_url = "https://huggingface.co/bartowski/Meta-Llama-3-8B-Instruct-GGUF/resolve/main/Meta-Llama-3-8B-Instruct-Q6_K.gguf"
model_url = "https://huggingface.co/bartowski/Meta-Llama-3-8B-Instruct-GGUF/resolve/main/Meta-Llama-3.1-8B-Instruct-Q6_K.gguf"

model_url = st.sidebar.text_input("Model URL", value=model_url)
os.makedirs(modular_cache_dir(), exist_ok=True)
Expand Down
4 changes: 3 additions & 1 deletion examples/gui/pages/stable-diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ def load_tokenizer(path):
padding="max_length",
max_length=tokenizer.model_max_length,
)
input_ids = np.stack((prompt_p.input_ids, prompt_n.input_ids))
input_ids = np.stack((prompt_p.input_ids, prompt_n.input_ids)).astype(
np.int32
)
encoder_hidden_states = txt_encoder.execute(input_ids=input_ids)[
"last_hidden_state"
]
Expand Down
83 changes: 83 additions & 0 deletions examples/gui/pages/yolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,89 @@
ONNX, then compiles it with MAX for faster inference!
"""

CLASS_NAMES = [
"person",
"bicycle",
"car",
"motorcycle",
"airplane",
"bus",
"train",
"truck",
"boat",
"traffic light",
"fire hydrant",
"stop sign",
"parking meter",
"bench",
"bird",
"cat",
"dog",
"horse",
"sheep",
"cow",
"elephant",
"bear",
"zebra",
"giraffe",
"backpack",
"umbrella",
"handbag",
"tie",
"suitcase",
"frisbee",
"skis",
"snowboard",
"sports ball",
"kite",
"baseball bat",
"baseball glove",
"skateboard",
"surfboard",
"tennis racket",
"bottle",
"wine glass",
"cup",
"fork",
"knife",
"spoon",
"bowl",
"banana",
"apple",
"sandwich",
"orange",
"broccoli",
"carrot",
"hot dog",
"pizza",
"donut",
"cake",
"chair",
"couch",
"potted plant",
"bed",
"dining table",
"toilet",
"tv",
"laptop",
"mouse",
"remote",
"keyboard",
"cell phone",
"microwave",
"oven",
"toaster",
"sink",
"refrigerator",
"book",
"clock",
"vase",
"scissors",
"teddy bear",
"hair drier",
"toothbrush",
]


@st.cache_data(show_spinner="Downloading YOLO and exporting to ONNX")
def download_and_export_yolo(model_path, height, width):
Expand Down
28 changes: 28 additions & 0 deletions examples/gui/ragdata/mojo_functions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Mojo Functions

Mojo functions can be declared with either fn or def.

The fn declaration enforces type-checking and memory-safe behaviors (Rust style), while def allows no type declarations and dynamic behaviors (Python style).

For example, this def function doesn't require declaration of argument types or the return type:

```mojo
def greet(name):
return "Hello, " + name + "!"
```

While the same thing as an fn function requires that you specify the argument type and the return type like this:

```mojo
fn greet2(name: String) -> String:
return "Hello, " + name + "!"
```

Both functions have the same result, but the fn function provides compile-time checks to ensure the function receives and returns the correct types. Whereas, the def function might fail at runtime if it receives the wrong type.

Currently, Mojo doesn't support top-level code in a .mojo (or .🔥) file, so every program must include a function named main() as the entry point. You can declare it with either def or fn:

```mojo
def main():
print("Hello, world!")
```

0 comments on commit 458cfc0

Please sign in to comment.