YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Llama2Device_ParamsParser.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6
7// Generated by yarpDeviceParamParserGenerator (2.0)
8// This is an automatically generated file. Please do not edit it.
9// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON.
10
11// Generated on: Mon Apr 13 16:55:49 2026
12
13
15#include <yarp/os/LogStream.h>
16#include <yarp/os/Value.h>
17
18namespace {
19 YARP_LOG_COMPONENT(Llama2DeviceParamsCOMPONENT, "yarp.device.Llama2Device")
20}
21
22
26
27
28std::vector<std::string> Llama2Device_ParamsParser::getListOfParams() const
29{
30 std::vector<std::string> params;
31 params.push_back("model_context");
32 params.push_back("model_name");
33 params.push_back("npredict");
34 params.push_back("ngl");
35 params.push_back("offload_gpu");
36 params.push_back("context");
37 params.push_back("prompt_file");
38 params.push_back("prompt_context");
39 return params;
40}
41
42
43bool Llama2Device_ParamsParser::getParamValue(const std::string& paramName, std::string& paramValue) const
44{
45 if (paramName =="model_context")
46 {
47 paramValue = m_model_context;
48 return true;
49 }
50 if (paramName =="model_name")
51 {
52 paramValue = m_model_name;
53 return true;
54 }
55 if (paramName =="npredict")
56 {
57 paramValue = std::to_string(m_npredict);
58 return true;
59 }
60 if (paramName =="ngl")
61 {
62 paramValue = std::to_string(m_ngl);
63 return true;
64 }
65 if (paramName =="offload_gpu")
66 {
67 if (m_offload_gpu==true) paramValue = "true";
68 else paramValue = "false";
69 return true;
70 }
71 if (paramName =="context")
72 {
73 paramValue = std::to_string(m_context);
74 return true;
75 }
76 if (paramName =="prompt_file")
77 {
78 paramValue = m_prompt_file;
79 return true;
80 }
81 if (paramName =="prompt_context")
82 {
83 paramValue = m_prompt_context;
84 return true;
85 }
86
87 yError() <<"parameter '" << paramName << "' was not found";
88 return false;
89
90}
91
92
94{
95 //This is a sub-optimal solution.
96 //Ideally getConfiguration() should return all parameters but it is currently
97 //returning only user provided parameters (excluding default values)
98 //This behaviour will be fixed in the near future.
99 std::string s_cfg = m_provided_configuration;
100 return s_cfg;
101}
102
104{
105 //Check for --help option
106 if (config.check("help"))
107 {
108 yCInfo(Llama2DeviceParamsCOMPONENT) << getDocumentationOfDeviceParams();
109 }
110
113 //Parser of parameter model_context
114 {
115 if (config.check("model_context"))
116 {
117 m_model_context = config.find("model_context").asString();
118 yCInfo(Llama2DeviceParamsCOMPONENT) << "Parameter 'model_context' using value:" << m_model_context;
119 }
120 else
121 {
122 yCInfo(Llama2DeviceParamsCOMPONENT) << "Parameter 'model_context' using DEFAULT value:" << m_model_context;
123 }
124 prop_check.unput("model_context");
125 }
126
127 //Parser of parameter model_name
128 {
129 if (config.check("model_name"))
130 {
131 m_model_name = config.find("model_name").asString();
132 yCInfo(Llama2DeviceParamsCOMPONENT) << "Parameter 'model_name' using value:" << m_model_name;
133 }
134 else
135 {
136 yCError(Llama2DeviceParamsCOMPONENT) << "Mandatory parameter 'model_name' not found!";
137 yCError(Llama2DeviceParamsCOMPONENT) << "Description of the parameter: name of Llama2 model";
138 return false;
139 }
140 prop_check.unput("model_name");
141 }
142
143 //Parser of parameter npredict
144 {
145 if (config.check("npredict"))
146 {
147 m_npredict = config.find("npredict").asInt64();
148 yCInfo(Llama2DeviceParamsCOMPONENT) << "Parameter 'npredict' using value:" << m_npredict;
149 }
150 else
151 {
152 yCInfo(Llama2DeviceParamsCOMPONENT) << "Parameter 'npredict' using DEFAULT value:" << m_npredict;
153 }
154 prop_check.unput("npredict");
155 }
156
157 //Parser of parameter ngl
158 {
159 if (config.check("ngl"))
160 {
161 m_ngl = config.find("ngl").asInt64();
162 yCInfo(Llama2DeviceParamsCOMPONENT) << "Parameter 'ngl' using value:" << m_ngl;
163 }
164 else
165 {
166 yCInfo(Llama2DeviceParamsCOMPONENT) << "Parameter 'ngl' using DEFAULT value:" << m_ngl;
167 }
168 prop_check.unput("ngl");
169 }
170
171 //Parser of parameter offload_gpu
172 {
173 if (config.check("offload_gpu"))
174 {
175 m_offload_gpu = config.find("offload_gpu").asBool();
176 yCInfo(Llama2DeviceParamsCOMPONENT) << "Parameter 'offload_gpu' using value:" << m_offload_gpu;
177 }
178 else
179 {
180 yCInfo(Llama2DeviceParamsCOMPONENT) << "Parameter 'offload_gpu' using DEFAULT value:" << m_offload_gpu;
181 }
182 prop_check.unput("offload_gpu");
183 }
184
185 //Parser of parameter context
186 {
187 if (config.check("context"))
188 {
189 m_context = config.find("context").asInt64();
190 yCInfo(Llama2DeviceParamsCOMPONENT) << "Parameter 'context' using value:" << m_context;
191 }
192 else
193 {
194 yCInfo(Llama2DeviceParamsCOMPONENT) << "Parameter 'context' using DEFAULT value:" << m_context;
195 }
196 prop_check.unput("context");
197 }
198
199 //Parser of parameter prompt_file
200 {
201 if (config.check("prompt_file"))
202 {
203 m_prompt_file = config.find("prompt_file").asString();
204 yCInfo(Llama2DeviceParamsCOMPONENT) << "Parameter 'prompt_file' using value:" << m_prompt_file;
205 }
206 else
207 {
208 yCInfo(Llama2DeviceParamsCOMPONENT) << "Parameter 'prompt_file' using DEFAULT value:" << m_prompt_file;
209 }
210 prop_check.unput("prompt_file");
211 }
212
213 //Parser of parameter prompt_context
214 {
215 if (config.check("prompt_context"))
216 {
217 m_prompt_context = config.find("prompt_context").asString();
218 yCInfo(Llama2DeviceParamsCOMPONENT) << "Parameter 'prompt_context' using value:" << m_prompt_context;
219 }
220 else
221 {
222 yCInfo(Llama2DeviceParamsCOMPONENT) << "Parameter 'prompt_context' using DEFAULT value:" << m_prompt_context;
223 }
224 prop_check.unput("prompt_context");
225 }
226
227 /*
228 //This code check if the user set some parameter which are not check by the parser
229 //If the parser is set in strict mode, this will generate an error
230 if (prop_check.size() > 0)
231 {
232 bool extra_params_found = false;
233 for (auto it=prop_check.begin(); it!=prop_check.end(); it++)
234 {
235 if (m_parser_is_strict)
236 {
237 yCError(Llama2DeviceParamsCOMPONENT) << "User asking for parameter: "<<it->name <<" which is unknown to this parser!";
238 extra_params_found = true;
239 }
240 else
241 {
242 yCWarning(Llama2DeviceParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!";
243 }
244 }
245
246 if (m_parser_is_strict && extra_params_found)
247 {
248 return false;
249 }
250 }
251 */
252 return true;
253}
254
255
257{
258 std::string doc;
259 doc = doc + std::string("\n=============================================\n");
260 doc = doc + std::string("This is the help for device: Llama2Device\n");
261 doc = doc + std::string("\n");
262 doc = doc + std::string("This is the list of the parameters accepted by the device:\n");
263 doc = doc + std::string("'model_context': context of Llama2 model\n");
264 doc = doc + std::string("'model_name': name of Llama2 model\n");
265 doc = doc + std::string("'npredict': number of tokens generated by the model\n");
266 doc = doc + std::string("'ngl': number of layers to offload to the gpu\n");
267 doc = doc + std::string("'offload_gpu': bool value to offload computations to gpu (default = true)\n");
268 doc = doc + std::string("'context': context size (use ctx_size = 0 to load context size from the model)\n");
269 doc = doc + std::string("'prompt_file': The file containing the prompt for the LLM\n");
270 doc = doc + std::string("'prompt_context': The yarp context from which the prompt file should be loaded\n");
271 doc = doc + std::string("\n");
272 doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n");
273 doc = doc + " yarpdev --device yarp_llama2Device --model_context <optional_value> --model_name <mandatory_value> --npredict 128 --ngl 50 --offload_gpu true --context 4096 --prompt_file <optional_value> --prompt_context <optional_value>\n";
274 doc = doc + std::string("Using only mandatory params:\n");
275 doc = doc + " yarpdev --device yarp_llama2Device --model_name <mandatory_value>\n";
276 doc = doc + std::string("=============================================\n\n"); return doc;
277}
#define yError(...)
Definition Log.h:361
std::vector< std::string > getListOfParams() const override
Return a list of all params used by the device.
std::string getDocumentationOfDeviceParams() const override
Get the documentation of the DeviceDriver's parameters.
bool getParamValue(const std::string &paramName, std::string &paramValue) const override
Return the value (represented as a string) of the requested parameter.
std::string getConfiguration() const override
Return the configuration of the device.
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
A class for storing options and configuration information.
Definition Property.h:32
void unput(const std::string &key)
Remove the association from the given key to a value, if present.
A base class for nested structures that can be searched.
Definition Searchable.h:31
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
#define yCInfo(component,...)
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)