Skip to content

Commit dfa58f2

Browse files
Merge pull request #279 from DashAISoftware/develop
Removed llama-cpp from requirements
2 parents 4475244 + 98ef843 commit dfa58f2

12 files changed

Lines changed: 145 additions & 232 deletions

File tree

DashAI/back/api/api_v1/endpoints/pipelines.py

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from DashAI.back.dependencies.database.models import Dataset, Pipeline
2323
from DashAI.back.dependencies.registry.component_registry import ComponentRegistry
2424
from DashAI.back.exploration.base_explorer import BaseExplorer
25+
from DashAI.back.pipeline.validator.nodes_definitions import NODES
2526
from DashAI.back.pipeline.validator.pipeline_validator import PipelineValidator
2627
from DashAI.back.pipeline.validator.validator import VALIDATOR_MAP
2728

@@ -61,37 +62,22 @@ async def get_pipelines(
6162

6263
@router.get("/nodes")
6364
async def get_nodes() -> List[Dict[str, Any]]:
64-
"""Retrieve pipeline node definitions.
65-
66-
Returns
67-
-------
68-
List[Dict[str, Any]]
69-
A list of node definitions from the nodes.json file.
70-
71-
Raises
72-
------
73-
HTTPException
74-
500: Failed to load node definitions.
75-
"""
65+
"""Retrieve pipeline node definitions."""
7666
try:
77-
json_path = Path(__file__).resolve().parents[3] / "pipeline" / "nodes.json"
78-
with open(json_path, "r") as f:
79-
nodes = json.load(f)
80-
81-
type_to_name = {node["type"]: node["name"] for node in nodes}
82-
for node in nodes:
83-
successors = node.get("successors", [])
84-
node["next"] = [type_to_name.get(s, s) for s in successors]
67+
type_to_name = {node.type: node.name for node in NODES}
68+
nodes_with_next = []
69+
for node in NODES:
70+
node_dict = node.model_dump()
71+
node_dict["next"] = [type_to_name.get(s, s) for s in node.successors]
72+
nodes_with_next.append(node_dict)
73+
return nodes_with_next
8574

8675
except Exception as e:
87-
logger.exception(e)
8876
raise HTTPException(
8977
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
9078
detail="Failed to load node definitions",
9179
) from e
9280

93-
return nodes
94-
9581

9682
@router.get("/predict_summary")
9783
@inject

DashAI/back/dataloaders/classes/dashai_dataset.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,16 @@ def save_dataset(dataset: DashAIDataset, path: Union[str, os.PathLike]) -> None:
297297
writer.close()
298298

299299
metadata_filepath = os.path.join(path, "splits.json")
300-
with open(metadata_filepath, "w") as f:
301-
json.dump(dataset.splits, f, indent=2, sort_keys=True, ensure_ascii=False)
300+
# Update splits with dataset shape and column names
301+
metadata = dataset.splits
302+
metadata.update(
303+
{
304+
"total_rows": dataset.shape[0],
305+
"column_names": dataset.column_names,
306+
}
307+
)
308+
with open(metadata_filepath, "w", encoding="utf-8") as f:
309+
json.dump(metadata, f, indent=2, sort_keys=True, ensure_ascii=False)
302310

303311

304312
@beartype
@@ -767,24 +775,16 @@ def get_dataset_info(dataset_path: str) -> object:
767775
else:
768776
splits_data = {"split_indices": {}}
769777

770-
data_filepath = os.path.join(dataset_path, "data.arrow")
771-
with pa.OSFile(data_filepath, "rb") as source:
772-
reader = ipc.open_file(source)
773-
schema = reader.schema
774-
column_names = schema.names
775-
776-
total_rows = 0
777-
for i in range(reader.num_record_batches):
778-
total_rows += reader.get_batch(i).num_rows
779-
780778
splits = splits_data.get("split_indices", {})
781779
train_indices = splits.get("train", [])
782780
test_indices = splits.get("test", [])
783781
val_indices = splits.get("validation", [])
782+
total_rows = splits_data.get("total_rows", 0)
783+
column_names = splits_data.get("column_names", [])
784784

785785
return {
786786
"total_rows": total_rows,
787-
"total_columns": len(schema),
787+
"total_columns": len(column_names),
788788
"column_names": column_names,
789789
"train_size": len(train_indices),
790790
"test_size": len(test_indices),

DashAI/back/initial_components.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
DecisionTreeClassifier,
7777
DistilBertTransformer,
7878
DummyClassifier,
79-
GemmaModel,
8079
GradientBoostingR,
8180
HistGradientBoostingClassifier,
8281
KNeighborsClassifier,
@@ -145,7 +144,6 @@ def get_initial_components():
145144
GradientBoostingR,
146145
HistGradientBoostingClassifier,
147146
KNeighborsClassifier,
148-
GemmaModel,
149147
QwenModel,
150148
StableDiffusionV2Model,
151149
StableDiffusionV3Model,

DashAI/back/models/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from DashAI.back.models.base_generative_model import BaseGenerativeModel
33
from DashAI.back.models.base_model import BaseModel
44
from DashAI.back.models.hugging_face.distilbert_transformer import DistilBertTransformer
5-
from DashAI.back.models.hugging_face.gemma_model import GemmaModel
65
from DashAI.back.models.hugging_face.opus_mt_en_es_transformer import (
76
OpusMtEnESTransformer,
87
)

DashAI/back/models/hugging_face/gemma_model.py

Lines changed: 0 additions & 104 deletions
This file was deleted.

DashAI/back/models/hugging_face/llama_utils.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22
import os
33
from pathlib import Path
44

5-
import llama_cpp
65
from packaging.version import Version
76

87
logger = logging.getLogger(__name__)
98

9+
try:
10+
import llama_cpp
11+
except ImportError:
12+
llama_cpp = None
13+
1014

1115
def is_gpu_available_for_llama_cpp() -> bool:
12-
"""
13-
Utility method to check if GPU offloading is supported for Llama models.
16+
if llama_cpp is None:
17+
return False
1418

15-
Returns:
16-
bool: True if GPU offloading is supported, False otherwise or if fails.
17-
"""
1819
try:
1920
if Version(llama_cpp.__version__) > Version("0.3.0"):
2021
return __is_gpu_available_for_llama_cpp_v03()
@@ -23,7 +24,7 @@ def is_gpu_available_for_llama_cpp() -> bool:
2324

2425
except Exception as e:
2526
logger.warning(
26-
"Error checking GPU availability for llama_cpp. Will use CPU only. \n"
27+
"Error checking GPU availability for llama_cpp. Will use CPU only.\n"
2728
f"Details: {e}"
2829
)
2930
return False

DashAI/back/models/hugging_face/qwen_model.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from typing import List
22

3-
from llama_cpp import Llama
3+
try:
4+
from llama_cpp import Llama
5+
except ImportError:
6+
Llama = None
47

58
from DashAI.back.core.schema_fields import (
69
BaseSchema,
@@ -14,7 +17,7 @@
1417
TextToTextGenerationTaskModel,
1518
)
1619

17-
if is_gpu_available_for_llama_cpp():
20+
if Llama is not None and is_gpu_available_for_llama_cpp():
1821
DEVICE_ENUM = ["gpu", "cpu"]
1922
DEVICE_PLACEHOLDER = "gpu"
2023
else:
@@ -83,6 +86,11 @@ class QwenModel(TextToTextGenerationTaskModel):
8386
SCHEMA = QwenSchema
8487

8588
def __init__(self, **kwargs):
89+
if Llama is None:
90+
raise RuntimeError(
91+
"llama-cpp-python is not installed. Please install it to use QwenModel."
92+
)
93+
8694
kwargs = self.validate_and_transform(kwargs)
8795
self.model_name = kwargs.get("model_name", "Qwen/Qwen2.5-1.5B-Instruct-GGUF")
8896
self.max_tokens = kwargs.pop("max_tokens", 100)
@@ -107,6 +115,4 @@ def generate(self, prompt: list[dict[str, str]]) -> List[str]:
107115
temperature=self.temperature,
108116
frequency_penalty=self.frequency_penalty,
109117
)
110-
111-
generated_text = output["choices"][0]["message"]["content"]
112-
return [generated_text]
118+
return [output["choices"][0]["message"]["content"]]

DashAI/back/pipeline/nodes.json

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)