bmaltais / kohya_ss

Apache License 2.0
8.79k stars 1.14k forks source link

Is there a way to hard code the config file in Lora training? #2611

Open AlvaroBadiaAlcaraz opened 1 week ago

AlvaroBadiaAlcaraz commented 1 week ago

I am making some tests and I was wondering if it is possible to modify the source code so that i can specify a config file for lora training before opening the gui, so when i start the gui it is already marked in the configuration box, and the contents of this config file are already applied in the parameters and folder structure of the lora training.

Thanks in advance.

bmaltais commented 1 week ago

I will welcome a PR to do this if someone want to tackle it.

AlvaroBadiaAlcaraz commented 1 week ago

I can start looking into it, but could you tell me please which files are responsible for the logic of that part?

bmaltais commented 1 week ago

I can start looking into it, but could you tell me please which files are responsible for the logic of that part?

That is the issue... many files will need to be updated to allow for this. The GUI was not designed to allow this and therefore does not land itself to such a change. It will require a lot of code change and testing across the GUI.

b-fission commented 1 week ago

I think using config.toml or specifying --config=myconfigfile.toml gets very close to fulfilling the requested behavior.

It would be more convenient if there was a way to save/export the toml from the GUI rather than needing to edit it by hand. There's save_config() in class_gui_config.py which appears to be unused.

Also, before anyone asks, the toml files that get generated when starting training are not compatible with config.toml for initializing the GUI.

AlvaroBadiaAlcaraz commented 1 week ago

If the config.toml that gets generated is not compatible, how does this file have to be in order to be compatible, also I was thinking of using a json file fot the configuration, do you know if that is compatible?

bmaltais commented 1 week ago

I might have made bad choices for the default config values. Had I stuck to the json format, I could that made it easy to pass a config and set the gui values to that.

one issue is that each trainer will inherit those values as there is no provision to specify if it is for a Lora, dreambooth or other. So even the json would be messy. There is no clean solution. If gradio allowed to execute a function on load it would be easy to pass a config for a specific tab a load it… but I have not found a way to do that.

this would be the cleanest method.

b-fission commented 1 week ago

If the config.toml that gets generated is not compatible, how does this file have to be in order to be compatible

There is a template file called config example.toml in the main kohya_ss folder that you can use.

...

If gradio allowed to execute a function on load it would be easy to pass a config for a specific tab a load it… but I have not found a way to do that.

Doesn't gradio's gr.Interface.load() provide that capability? https://www.gradio.app/docs/gradio/interface#interface-load

load gradio.Interface.load(block, ···)

Description This listener is triggered when the Interface initially loads in the browser.

AlvaroBadiaAlcaraz commented 1 week ago

Sorry i haven't used gradio before, how would that work?

b-fission commented 1 week ago

Sorry i haven't used gradio before, how would that work?

For using a config.toml file? It's not gradio specific, but the quickest way to start is just take config example.toml and save as config.toml in the kohya_ss directory. The gui should be able to load it the next time you start it.

AlvaroBadiaAlcaraz commented 1 week ago

Thank you, that was exactly what i was looking for.

On the other hand, do you know is it is possible to call some function in the code from another file to start the training without opening the gui?

b-fission commented 1 week ago

On the other hand, do you know is it is possible to call some function in the code from another file to start the training without opening the gui?

There is a button at the bottom of the gui called "Print training command" which will show the command line (and toml) in the log output. You can use that command to run the training process without the gui.

AlvaroBadiaAlcaraz commented 1 week ago

Thank you so much!