chore: remove torch in main code (#439)

* use np.ndarray in costeer model evaluators

* remove package

* fix test error

---------

Co-authored-by: Xu Yang <peteryang@vip.qq.com>
This commit is contained in:
Linlang
2024-10-21 15:56:04 +08:00
committed by GitHub
parent 2161956315
commit d3c59b2f33
7 changed files with 14 additions and 71 deletions
-23
View File
@@ -71,7 +71,6 @@ isort==5.13.2
jaraco.classes==3.3.0
jedi==0.19.1
jeepney==0.8.0
Jinja2==3.1.2
joblib==1.4.2
json5==0.9.25
jsonpatch==1.33
@@ -102,7 +101,6 @@ loguru==0.7.2
loguru-mypy==0.0.4
lxml==5.0.0
markdown-it-py==3.0.0
MarkupSafe==2.1.3
marshmallow==3.20.1
matplotlib==3.9.1
matplotlib-inline==0.1.7
@@ -110,7 +108,6 @@ mdit-py-plugins==0.4.0
mdurl==0.1.2
mistune==3.0.2
more-itertools==10.1.0
mpmath==1.3.0
msal==1.30.0
msal-extensions==1.2.0
msgpack==1.0.8
@@ -124,24 +121,11 @@ nbconvert==7.16.4
nbformat==5.10.4
ndindex==1.8
nest-asyncio==1.6.0
networkx==3.2.1
nh3==0.2.15
notebook==7.2.1
notebook_shim==0.2.4
numexpr==2.10.1
numpy==1.26.2
nvidia-cublas-cu12==12.1.3.1
nvidia-cuda-cupti-cu12==12.1.105
nvidia-cuda-nvrtc-cu12==12.1.105
nvidia-cuda-runtime-cu12==12.1.105
nvidia-cudnn-cu12==8.9.2.26
nvidia-cufft-cu12==11.0.2.54
nvidia-curand-cu12==10.3.2.106
nvidia-cusolver-cu12==11.4.5.107
nvidia-cusparse-cu12==12.1.0.106
nvidia-nccl-cu12==2.18.1
nvidia-nvjitlink-cu12==12.3.101
nvidia-nvtx-cu12==12.1.105
oauthlib==3.2.2
openai==1.6.1
overrides==7.7.0
@@ -153,7 +137,6 @@ parso==0.8.4
pathspec==0.12.1
patsy==0.5.6
pexpect==4.9.0
pillow==10.4.0
pkginfo==1.9.6
platformdirs==4.1.0
pluggy==1.3.0
@@ -201,7 +184,6 @@ ruamel.yaml==0.18.5
ruamel.yaml.clib==0.2.8
ruff==0.4.5
scikit-learn==1.5.1
scipy==1.11.4
SecretStorage==3.3.3
semver==3.0.2
Send2Trash==1.8.3
@@ -226,7 +208,6 @@ sphinxcontrib-serializinghtml==1.1.9
SQLAlchemy==2.0.24
stack-data==0.6.3
statsmodels==0.14.2
sympy==1.12
tables==3.9.2
tabulate==0.9.0
tenacity==8.2.3
@@ -238,14 +219,11 @@ tinycss2==1.3.0
toml-sort==0.23.1
tomli==2.0.1
tomlkit==0.12.3
torch==2.1.2
torch_geometric==2.5.3
tornado==6.4
tqdm==4.66.1
traitlets==5.14.3
tree-sitter==0.22.3
tree-sitter-python==0.21.0
triton==2.1.0
twine==4.0.2
typer==0.9.0
types-psutil==6.0.0.20240621
@@ -253,7 +231,6 @@ types-python-dateutil==2.9.0.20240316
types-PyYAML==6.0.12.20240724
types-tqdm==4.66.0.20240417
typing-inspect==0.9.0
typing_extensions==4.9.0
tzdata==2023.4
uri-template==1.3.0
urllib3==2.1.0
-23
View File
@@ -69,7 +69,6 @@ isort==5.13.2
jaraco.classes==3.3.0
jedi==0.19.1
jeepney==0.8.0
Jinja2==3.1.2
joblib==1.4.2
json5==0.9.25
jsonpatch==1.33
@@ -100,7 +99,6 @@ loguru==0.7.2
loguru-mypy==0.0.4
lxml==5.0.0
markdown-it-py==3.0.0
MarkupSafe==2.1.3
marshmallow==3.20.1
matplotlib==3.9.1
matplotlib-inline==0.1.7
@@ -108,7 +106,6 @@ mdit-py-plugins==0.4.0
mdurl==0.1.2
mistune==3.0.2
more-itertools==10.1.0
mpmath==1.3.0
msal==1.30.0
msal-extensions==1.2.0
msgpack==1.0.8
@@ -122,24 +119,11 @@ nbconvert==7.16.4
nbformat==5.10.4
ndindex==1.8
nest-asyncio==1.6.0
networkx==3.2.1
nh3==0.2.15
notebook==7.2.1
notebook_shim==0.2.4
numexpr==2.10.1
numpy==1.26.2
nvidia-cublas-cu12==12.1.3.1
nvidia-cuda-cupti-cu12==12.1.105
nvidia-cuda-nvrtc-cu12==12.1.105
nvidia-cuda-runtime-cu12==12.1.105
nvidia-cudnn-cu12==8.9.2.26
nvidia-cufft-cu12==11.0.2.54
nvidia-curand-cu12==10.3.2.106
nvidia-cusolver-cu12==11.4.5.107
nvidia-cusparse-cu12==12.1.0.106
nvidia-nccl-cu12==2.18.1
nvidia-nvjitlink-cu12==12.3.101
nvidia-nvtx-cu12==12.1.105
oauthlib==3.2.2
openai==1.6.1
overrides==7.7.0
@@ -151,7 +135,6 @@ parso==0.8.4
pathspec==0.12.1
patsy==0.5.6
pexpect==4.9.0
pillow==10.4.0
pkginfo==1.9.6
platformdirs==4.1.0
pluggy==1.3.0
@@ -199,7 +182,6 @@ ruamel.yaml==0.18.5
ruamel.yaml.clib==0.2.8
ruff==0.4.5
scikit-learn==1.5.1
scipy==1.11.4
SecretStorage==3.3.3
semver==3.0.2
Send2Trash==1.8.3
@@ -224,7 +206,6 @@ sphinxcontrib-serializinghtml==1.1.9
SQLAlchemy==2.0.24
stack-data==0.6.3
statsmodels==0.14.2
sympy==1.12
tables==3.9.2
tabulate==0.9.0
tenacity==8.2.3
@@ -235,14 +216,11 @@ tiktoken==0.7.0
tinycss2==1.3.0
toml-sort==0.23.1
tomlkit==0.12.3
torch==2.1.2
torch_geometric==2.5.3
tornado==6.4
tqdm==4.66.1
traitlets==5.14.3
tree-sitter==0.22.3
tree-sitter-python==0.21.0
triton==2.1.0
twine==4.0.2
typer==0.9.0
types-psutil==6.0.0.20240621
@@ -250,7 +228,6 @@ types-python-dateutil==2.9.0.20240316
types-PyYAML==6.0.12.20240724
types-tqdm==4.66.0.20240417
typing-inspect==0.9.0
typing_extensions==4.9.0
tzdata==2023.4
uri-template==1.3.0
urllib3==2.1.0
@@ -4,7 +4,6 @@ from pathlib import Path
from typing import List, Tuple
import numpy as np
import torch
from jinja2 import Environment, StrictUndefined
from rdagent.components.coder.model_coder.conf import MODEL_IMPL_SETTINGS
@@ -25,7 +24,7 @@ from rdagent.oai.llm_utils import APIBackend
evaluate_prompts = Prompts(file_path=Path(__file__).parent.parent / "prompts.yaml")
def shape_evaluator(prediction: torch.Tensor | np.ndarray, target_shape: Tuple = None) -> Tuple[str, bool]:
def shape_evaluator(prediction: np.ndarray, target_shape: Tuple = None) -> Tuple[str, bool]:
if target_shape is None or prediction is None:
return (
"No output generated from the model. No shape evaluation conducted.",
@@ -42,18 +41,10 @@ def shape_evaluator(prediction: torch.Tensor | np.ndarray, target_shape: Tuple =
)
def reshape_tensor(original_tensor, target_shape):
new_tensor = torch.zeros(target_shape)
for i, dim in enumerate(original_tensor.shape):
new_tensor = new_tensor.narrow(i, 0, dim).copy_(original_tensor)
return new_tensor
def value_evaluator(
prediction: torch.Tensor,
target: torch.Tensor,
) -> Tuple[torch.Tensor, bool]:
prediction: np.ndarray,
target: np.ndarray,
) -> Tuple[np.ndarray, bool]:
if prediction is None:
return "No output generated from the model. Skip value evaluation", False
elif target is None:
@@ -63,7 +54,7 @@ def value_evaluator(
)
else:
# Calculate the mean absolute difference
diff = torch.mean(torch.abs(target - prediction)).item()
diff = np.mean(np.abs(target - prediction))
return (
f"The value of the output is correct. The mean absolute difference is {diff}.",
diff < 0.1,
@@ -273,7 +264,7 @@ class ModelCoderEvaluator(Evaluator):
param_init_value = 0.6
assert isinstance(implementation, ModelFBWorkspace)
model_execution_feedback, gen_tensor = implementation.execute(
model_execution_feedback, gen_np_array = implementation.execute(
batch_size=batch_size,
num_features=num_features,
num_timesteps=num_timesteps,
@@ -282,7 +273,7 @@ class ModelCoderEvaluator(Evaluator):
)
if gt_implementation is not None:
assert isinstance(gt_implementation, ModelFBWorkspace)
_, gt_tensor = gt_implementation.execute(
_, gt_np_array = gt_implementation.execute(
batch_size=batch_size,
num_features=num_features,
num_timesteps=num_timesteps,
@@ -290,10 +281,10 @@ class ModelCoderEvaluator(Evaluator):
param_init_value=param_init_value,
)
else:
gt_tensor = None
gt_np_array = None
shape_feedback, shape_decision = shape_evaluator(gen_tensor, (batch_size, 1))
value_feedback, value_decision = value_evaluator(gen_tensor, gt_tensor)
shape_feedback, shape_decision = shape_evaluator(gen_np_array, (batch_size, 1))
value_feedback, value_decision = value_evaluator(gen_np_array, gt_np_array)
code_feedback, _ = ModelCodeEvaluator(scen=self.scen).evaluate(
target_task=target_task,
implementation=implementation,
@@ -37,7 +37,7 @@ if MODEL_TYPE == "Graph":
else:
out = m(data)
execution_model_output = out.cpu().detach()
execution_model_output = out.cpu().detach().numpy()
execution_feedback_str = f"Execution successful, output tensor shape: {execution_model_output.shape}"
pickle.dump(execution_model_output, open("execution_model_output.pkl", "wb"))
@@ -12,7 +12,7 @@ valid_X = pd.DataFrame(np.random.randn(8, 30), columns=[f"{i}" for i in range(30
valid_y = pd.Series(np.random.randint(0, 2, 8))
model = fit(train_X, train_y, valid_X, valid_y)
execution_model_output = predict(model, valid_X)
execution_model_output = predict(model, valid_X).cpu().detach().numpy()
execution_feedback_str = f"Execution successful, output numpy ndarray shape: {execution_model_output.shape}"
-4
View File
@@ -3,7 +3,6 @@ pydantic-settings
typer[all]
cython
scipy
python-Levenshtein
scikit-learn
filelock
@@ -14,8 +13,6 @@ fuzzywuzzy
openai
ruamel-yaml
torch
torch_geometric
tabulate # Convert pandas dataframe to markdown table to make it more readable to LLM
numpy # we use numpy as default data format. So we have to install numpy
pandas # we use pandas as default data format. So we have to install pandas
@@ -69,5 +66,4 @@ seaborn
setuptools-scm
# This is a temporary package installed to pass the test_import test
xgboost
lightgbm
+2
View File
@@ -21,6 +21,8 @@ class TestRDAgentImports(unittest.TestCase):
continue
if "_template" in fstr:
continue
if "model_coder" in fstr:
continue
if (
fstr.endswith("rdagent/log/ui/app.py")
or fstr.endswith("rdagent/app/cli.py")