Hi WorriedParrot51
Let me shed some light on this complicated mechanism, because this is not very straight forward.
Basically the agent signals the trains package it should ignore the code calls, and use a specific Task in the backend (i.e. if in manual mode, the trains package logs the data into the trains-server, in agent mode (remote mode), it does the opposite and takes the data from the trains-server "into" the code)
Specifically, just like in manual mode, calling argparse.parse is being patched by Trains, and logs the parsed arguments, the same happens in remote mode only it put backs the values instead of reading them.
Calling parse before/after the Task.init is already taken care by the trains logic (whether manual or remote mope)
Specifically, where is the issue in your case, i.e. what happens with the argparser? Do you get the updated values ?
I was trying to call parse (earlier than necessary) only in case it runs on agent. Therefore I was trying to get the current task, assuming, that when I am calling if from agent, the Task is already initialized. So, as I am getting it right, the agent is not creating (initializing) the Task, correct?
Thanks for reply. It gave me little bit more understanding I needed.
In my case, I am trying to integrate trains to already existing code, which has little bit more complicated args parsing, which forces me to get trains-server stored parameters during the parser definition. I think I understand the issue a little bit more now, so l will try some new approaches. Thanks Martin, your responses are very good.
AgitatedDove14 One more. So how can I call get_parameters_as_dict() from agent as I do not have task?
Hi WorriedParrot51
Assuming you run the code "manually" once (i.e. without the agent). Then when you call Task.init it will register the argparser.
When running with the agent, the first time you will call parse, it will automatically override the argparse defaults with the values stored in the Task.
Make sesne?
am getting None for Task.current_task() at the beginning of my script.
Task.init() is doing the magic , only after this call you will have current_task (either running manually or with an agent)
(i.e. importing the trains package is enough to patch the argparser, only when you call the task.init the arguments will be logged, before they are stored in memory)
Oh, did you try task.connect_configuration
?
https://allegro.ai/docs/examples/reporting/model_config/#using-a-configuration-file
or shall I call the Task.init even from the agent
WorriedParrot51 I think something is lost here.
Task.init() is always called, even when the agent is executing the code. The difference is in what happens inside the Task.init() call. When the codebase itself is executed by the trains-agent, it signals through OS environment to the task.init() that instead of a new created task, it should use the already created one. from this point all data flows from the trains-server back into the code.
Make sense to you?
WorriedParrot51 trains should support subparsers etc.
Even if your code calls the parsing before trains.
The only thing you need is to import the package when argparser is called (not to initialize it, that can happen later)
It should (hopefully) solve the issue.
Hi WorriedParrot51 , what do you mean by "call get_parameters_as_dict() from agent" ?
Do you mean like change the trains-agent to run the task differently?
Or inside your code while the trains agent runs it?
From the code itself (regardless off how you run it) you can always call, and get the current states parameters (i.e. from backend if running with trains-agent, or copied from the code, if running manually)task.get_parameters_as_dict()
I see ... not sure if it is what I need, but how you can use:config_file = task.connect_configuration(config_file)
when (and I might be getting it not right) you did not inited the task locally ... or shall I call the Task.init even from the agent?
well I have certain parameters, that are not in args, but are in separate file. I am trying to use the file when calling locally, but to use trains-server-set parameters when being called from agent.
It will store the entire content of the file, then you can edit it in the UI, and in remote it will return a new local copy of the file (based on the data in the UI) for you to read.
on the other hand, I probably can get them from args as well ...