Skip to content

Commit

Permalink
Fix bugs in ArgParser
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongkaifu committed Nov 14, 2024
1 parent 5faf982 commit e8a9884
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 29 deletions.
45 changes: 18 additions & 27 deletions AdvUtils/Arg/ArgParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ public class ArgParser
object m_o;
List<ArgField> m_arrayArgs;

public static void UpdateFieldValue(object obj, string fieldName, string newValue)
{
// Get the Type of the object
Type objType = obj.GetType();

// Get the FieldInfo for the specified field name
FieldInfo fieldInfo = objType.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

// If the field is found, set the new value
if (fieldInfo != null)
{
fieldInfo.SetValue(obj, newValue);
}
else
{
Console.WriteLine($"Field '{fieldName}' not found in the class.");
}
}
//public static void UpdateFieldValue(object obj, string fieldName, string newValue)
//{
// // Get the Type of the object
// Type objType = obj.GetType();

// // Get the FieldInfo for the specified field name
// FieldInfo fieldInfo = objType.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

// // If the field is found, set the new value
// if (fieldInfo != null)
// {
// fieldInfo.SetValue(obj, newValue);
// }
// else
// {
// Console.WriteLine($"Field '{fieldName}' not found in the class.");
// }
//}

public ArgParser(string[] args, object o)
{
Expand All @@ -43,11 +43,6 @@ public ArgParser(string[] args, object o)
}
}

RewriteSettings(args, o);
}

public void RewriteSettings(string[] args, object o)
{
try
{
for (int i = 0; i < args.Length; i++)
Expand All @@ -64,10 +59,6 @@ public void RewriteSettings(string[] args, object o)
}

intarg.Set(strArgValue);

Console.WriteLine($"Rewrite field '{strArgName}' value.");
UpdateFieldValue(o, strArgName, strArgValue);

i++;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tools/GPTConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private static void Main(string[] args)
{
Console.WriteLine($"Loading config file from '{opts.ConfigFilePath}'");
opts = JsonConvert.DeserializeObject<Seq2SeqOptions>(File.ReadAllText(opts.ConfigFilePath));
argParser.RewriteSettings(args, opts);
argParser = new ArgParser(args, opts);
}

Logger.Initialize(opts.LogDestination, opts.LogLevel, $"{nameof(GPTConsole)}_{opts.Task}_{Utils.GetTimeStamp(DateTime.Now)}.log");
Expand Down
2 changes: 1 addition & 1 deletion Tools/Seq2SeqConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private static void Main(string[] args)
try
{
opts = JsonConvert.DeserializeObject<Seq2SeqOptions>(File.ReadAllText(opts.ConfigFilePath));
argParser.RewriteSettings(args, opts);
argParser = new ArgParser(args, opts);
}
catch(Exception ex)
{
Expand Down

0 comments on commit e8a9884

Please sign in to comment.