mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-07-29 08:27:43 +00:00
d1019cb568
* fix model input shape bug and costeer_model bug * fix a bug * fix a bug in docker result extraction * a system-level optimization * add a filter of stdout * update * add stdout to model * model training_hyperparameters update * quant scenario * update some quant settings * llm choose action * Thompson Sampling Bandit for action choosing * refine both scens * add trace messages for quant scen * fix some bugs * fix some bugs * update * update * update * fix * fix * fix * update for merge * fix ci * fix some bugs * fix ci * fix ci * fix ci * fix ci * refactor * default qlib4rdagent local env downloading * fix ci * fix ci * fix a bug * fix ci * fix: align all prompts on template (#908) * use template to render all prompts * fix CI --------- Co-authored-by: Xu Yang <xuyang1@microsoft.com> * add fin_quant in cli * fix a bug * fix ci * fix some bugs * refactor * remove the columns in hypothesis if no value generated in this column * fix a bug * fix ci * fix conda env * add qlib gitignore * remove existed qlib folder & install torch in qlib conda * fix workspace ui in feedback * align model config in coder and runner in docker or conda * fix CI * fix CI --------- Co-authored-by: Xu Yang <peteryang@vip.qq.com> Co-authored-by: Xu Yang <xuyang1@microsoft.com>
63 lines
2.8 KiB
Python
63 lines
2.8 KiB
Python
# TODO:
|
|
# Implement to feedback.
|
|
|
|
import json
|
|
from pathlib import Path
|
|
from typing import Dict
|
|
|
|
from rdagent.core.experiment import Experiment
|
|
from rdagent.core.proposal import Experiment2Feedback, HypothesisFeedback, Trace
|
|
from rdagent.log import rdagent_logger as logger
|
|
from rdagent.oai.llm_utils import APIBackend
|
|
from rdagent.utils import convert2bool
|
|
from rdagent.utils.agent.tpl import T
|
|
|
|
DIRNAME = Path(__file__).absolute().resolve().parent
|
|
|
|
|
|
class DMModelExperiment2Feedback(Experiment2Feedback):
|
|
"""Generated feedbacks on the hypothesis from **Executed** Implementations of different tasks & their comparisons with previous performances"""
|
|
|
|
def generate_feedback(self, exp: Experiment, trace: Trace) -> HypothesisFeedback:
|
|
"""
|
|
The `ti` should be executed and the results should be included, as well as the comparison between previous results (done by LLM).
|
|
For example: `mlflow` of Qlib will be included.
|
|
"""
|
|
hypothesis = exp.hypothesis
|
|
|
|
logger.info("Generating feedback...")
|
|
# Define the system prompt for hypothesis feedback
|
|
system_prompt = T("scenarios.qlib.prompts:model_feedback_generation.system").r()
|
|
|
|
# Define the user prompt for hypothesis feedback
|
|
context = trace.scen
|
|
SOTA_hypothesis, SOTA_experiment = trace.get_sota_hypothesis_and_experiment()
|
|
|
|
user_prompt = T("scenarios.qlib.prompts:model_feedback_generation.user").r(
|
|
context=context,
|
|
last_hypothesis=SOTA_hypothesis,
|
|
last_task=SOTA_experiment.sub_tasks[0].get_task_information() if SOTA_hypothesis else None,
|
|
last_code=SOTA_experiment.sub_workspace_list[0].file_dict.get("model.py") if SOTA_hypothesis else None,
|
|
last_result=SOTA_experiment.result if SOTA_hypothesis else None,
|
|
hypothesis=hypothesis,
|
|
exp=exp,
|
|
)
|
|
|
|
# Call the APIBackend to generate the response for hypothesis feedback
|
|
response_hypothesis = APIBackend().build_messages_and_create_chat_completion(
|
|
user_prompt=user_prompt,
|
|
system_prompt=system_prompt,
|
|
json_mode=True,
|
|
json_target_type=Dict[str, str | bool | int],
|
|
)
|
|
|
|
# Parse the JSON response to extract the feedback
|
|
response_json_hypothesis = json.loads(response_hypothesis)
|
|
return HypothesisFeedback(
|
|
observations=response_json_hypothesis.get("Observations", "No observations provided"),
|
|
hypothesis_evaluation=response_json_hypothesis.get("Feedback for Hypothesis", "No feedback provided"),
|
|
new_hypothesis=response_json_hypothesis.get("New Hypothesis", "No new hypothesis provided"),
|
|
reason=response_json_hypothesis.get("Reasoning", "No reasoning provided"),
|
|
decision=convert2bool(response_json_hypothesis.get("Decision", "false")),
|
|
)
|