Skip to content

Commit

Permalink
fix llamacpp and windows libuv (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyasMoutawwakil authored Nov 26, 2024
1 parent 7f5d486 commit 9104793
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 20 deletions.
7 changes: 2 additions & 5 deletions optimum_benchmark/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,11 @@ def __init__(self, config: BackendConfigT):

elif self.config.library == "llama_cpp":
self.logger.info("\t+ Benchmarking a LlamaCpp model")
# TOD: need a custom method to extract shapes from gguf
self.model_shapes = extract_transformers_shapes_from_artifacts(
self.pretrained_config, self.pretrained_processor
)
self.pretrained_processor = None
self.generation_config = None
self.pretrained_config = None
self.generation_config = None
self.automodel_loader = None
self.model_shapes = {}

else:
self.logger.info("\t+ Benchmarking a Transformers model")
Expand Down
9 changes: 2 additions & 7 deletions optimum_benchmark/backends/llama_cpp/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,10 @@ def llama_cpp_kwargs(self) -> Dict[str, Any]:
"echo": False,
}

def prepare_input_shapes(self, input_shapes: Dict[str, Any]) -> Dict[str, Any]:
if self.config.task == "text-generation":
if input_shapes["batch_size"] != 1:
raise ValueError("Batch size must be 1 for LlamaCpp text generation")

return input_shapes

def prepare_inputs(self, inputs: Dict[str, Any]) -> Dict[str, Any]:
if self.config.task == "text-generation":
if inputs["input_ids"].shape[0] != 1:
raise ValueError("Batch size must be 1 for LlamaCpp text generation")
return {"tokens": inputs["input_ids"].squeeze(0).tolist()}

elif self.config.task == "feature-extraction":
Expand Down
2 changes: 1 addition & 1 deletion optimum_benchmark/backends/pytorch/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from .config import PyTorchConfig

if is_deepspeed_available():
import deepspeed
import deepspeed # type: ignore

if is_torch_distributed_available():
import torch.distributed
Expand Down
5 changes: 0 additions & 5 deletions optimum_benchmark/launchers/torchrun/launcher.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import sys
import traceback
from contextlib import ExitStack
from logging import Logger
Expand Down Expand Up @@ -155,10 +154,6 @@ def entrypoint(worker: Callable[..., BenchmarkReport], worker_args: List[Any], l
else:
setup_logging(level="ERROR", to_file=log_to_file, prefix=f"RANK-PROCESS-{rank}")

if sys.platform == "win32":
logger.info("\t+ Disabline libuv on Windows")
os.environ["USE_LIBUV"] = "0"

if torch.cuda.is_available():
logger.info(f"\t+ Setting torch.distributed cuda device to {rank}")
device = torch.device("cuda", rank)
Expand Down
4 changes: 2 additions & 2 deletions tests/configs/_gguf_.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ hydra:
mode: MULTIRUN
sweeper:
params:
backend.model: ggml-org/models
backend.task: text-generation,feature-extraction
backend.model: QuantFactory/gpt2-GGUF
backend.filename: gpt2.Q4_0.gguf
backend.filename: tinyllamas/stories15M-q8_0.gguf
6 changes: 6 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def test_cli_configs(config_name):

@pytest.mark.parametrize("launcher", ["inline", "process", "torchrun"])
def test_cli_exit_code_0(launcher):
if launcher == "torchrun" and sys.platform == "win32":
pytest.skip("torchrun is not supported on Windows")

args_0 = [
"optimum-benchmark",
"--config-dir",
Expand All @@ -73,6 +76,9 @@ def test_cli_exit_code_0(launcher):

@pytest.mark.parametrize("launcher", ["inline", "process", "torchrun"])
def test_cli_exit_code_1(launcher):
if launcher == "torchrun" and sys.platform == "win32":
pytest.skip("torchrun is not supported on Windows")

args_1 = [
"optimum-benchmark",
"--config-dir",
Expand Down

0 comments on commit 9104793

Please sign in to comment.