Skip to content
Merged
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
10 changes: 9 additions & 1 deletion iron/applications/llama_3.2_1b/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import subprocess
import pytest
import os
import sys
from pathlib import Path

test_dir = Path(__file__).parent
Expand All @@ -27,14 +28,21 @@ def generate_test_params():
params, names = generate_test_params()


@pytest.mark.skipif(
not (
(weights_dir / "llama3.2-1b" / "model.safetensors").exists()
and (weights_dir / "llama3.2-1b" / "tokenizer.model").exists()
),
reason="llama3.2-1b weights not found",
)
@pytest.mark.supported_devices("npu2")
@pytest.mark.metrics(
TTFT=r"\[Prefill\]\s*Time to first token:\s*(?P<value>[\d\.e\+-]+) s",
TPS=r"\[Decode\]\s*Tokens per second:\s*(?P<value>[\d\.e\+-]+)",
)
@pytest.mark.parametrize("prompt_len,num_tokens", params, ids=names)
def test_llama_3_2_1b(prompt_len, num_tokens):
command = f"python3 {test_dir}/llama_npu.py {weights_dir}/llama3.2-1b/model.safetensors {weights_dir}/llama3.2-1b/tokenizer.model --num-tokens {num_tokens} --prompt-len {prompt_len}"
command = f"{sys.executable} {test_dir}/llama_npu.py {weights_dir}/llama3.2-1b/model.safetensors {weights_dir}/llama3.2-1b/tokenizer.model --num-tokens {num_tokens} --prompt-len {prompt_len}"

result = subprocess.run(
command,
Expand Down
45 changes: 31 additions & 14 deletions iron/common/compilation/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,20 +795,37 @@ def _prefix_symbols(self, artifact, prefix):
nm_path = self._find_working_tool("llvm-nm")
symbol_map_file = artifact.filename + ".symbol_map"

# Extract defined symbols and build the redefine-syms map. Run nm to a
# file, THEN awk (joined by `&&`) rather than `nm | awk`: a pipe reports
# only awk's exit status, so a failing nm silently produces an EMPTY map
# and the prefix rename is skipped, surfacing much later as
# `undefined symbol: {prefix}<sym>` at the per-core link. With `&&` a
# failed nm aborts here loudly instead.
nm_cmd = [
"sh",
"-c",
f"{nm_path} --defined-only --extern-only {artifact.filename} "
f"> {symbol_map_file}.syms && "
f"awk '{{print $3 \" {prefix}\" $3}}' {symbol_map_file}.syms "
f"> {symbol_map_file}",
]
if os.name == "nt":
# Pure python code execution block wrapped cleanly for Windows
python_script = f"""
import subprocess
nm_cmd = [{repr(nm_path)}, '--defined-only', '--extern-only', {repr(artifact.filename)}]
res = subprocess.run(nm_cmd, capture_output=True, text=True, check=True)
lines = []
for line in res.stdout.splitlines():
parts = line.strip().split()
if len(parts) >= 3:
sym = parts[-1]
lines.append(f"{{sym}} {prefix}{{sym}}\\n")
with open({repr(symbol_map_file)}, 'w') as f:
f.writelines(lines)
"""
nm_cmd = [sys.executable, "-c", python_script.strip()]
else:
# Extract defined symbols and build the redefine-syms map. Run nm to a
# file, THEN awk (joined by `&&`) rather than `nm | awk`: a pipe reports
# only awk's exit status, so a failing nm silently produces an EMPTY map
# and the prefix rename is skipped, surfacing much later as
# `undefined symbol: {prefix}<sym>` at the per-core link. With `&&` a
# failed nm aborts here loudly instead.
nm_cmd = [
"sh",
"-c",
f"{nm_path} --defined-only --extern-only {artifact.filename} "
f"> {symbol_map_file}.syms && "
f"awk '{{print $3 \" {prefix}\" $3}}' {symbol_map_file}.syms "
f"> {symbol_map_file}",
]

# Apply the renaming using the symbol map
objcopy_cmd = [
Expand Down
Loading