Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add package cli scripts #996

Closed
carmocca opened this issue Mar 4, 2024 · 10 comments
Closed

Add package cli scripts #996

carmocca opened this issue Mar 4, 2024 · 10 comments
Assignees

Comments

@carmocca
Copy link
Contributor

carmocca commented Mar 4, 2024

litgpt pretrain ...
litgpt finetune lora ...
litgpt chat
etc.

@carmocca carmocca added this to the Configurability milestone Mar 4, 2024
@carmocca carmocca self-assigned this Mar 6, 2024
@carmocca
Copy link
Contributor Author

carmocca commented Mar 6, 2024

Along the lines of #982 (comment), we need to decide, what are the CLI calls for every script and how are they structured in directories.

@carmocca
Copy link
Contributor Author

carmocca commented Mar 6, 2024

For instance, the top post says litgpt finetune lora. I have a PoC in #1026 but it doesn't support subcommands inside subcommands (lora inside finetune).

It's not clear to me right now if we will have a single finetune.py script with a --algorithm lora|full|adapter.
Or if they will be separate scripts and we need to customize the CLI to support subcommands inside subcommands.
Another option is to expose litgpt finetune_lora, litgpt finetune_full ...

Similar questions apply to generation, especially if we need to choose between base|tp|sequentially (related #1016)

@rasbt
Copy link
Contributor

rasbt commented Mar 6, 2024

I have a slight preference towards litgpt finetune_lora, litgpt finetune_full, so that we are not chaining multiple commands and keep it more similar to litgpt pretrain and litgpt chat.

But one concern is also, hypothetically speaking, suppose we were to add RLHF with PPO & REINFORCE and DPO later. How would it look?

litgpt dpo_lora and litgpt dpo_full? Or litgpt finetune_dpo_lora and litgpt finetune_dpo_full? That's getting very convoluted then.

Or the following is also super complicated:

  • litgpt finetune sft lora
  • litgpt finetune dpo lora
  • litgpt finetune rlhf ppo full
  • litgpt finetune rlhf reinforce full

I will have to think about it more ...

@lantiga
Copy link
Contributor

lantiga commented Mar 6, 2024

I think lora, dpo need to be different flags (--method lora) etc on the finetune subcommmand

@carmocca
Copy link
Contributor Author

There's a jsonargparse bug blocking me from implementing it the way I thought: omni-us/jsonargparse#467. If we cannot find a fix or a workaround in time I would have to try click or something else.

@carmocca
Copy link
Contributor Author

Mauricio replied and seems like --method lora is not really feasible because you would need to do argument parsing in two stages, once to get the method selected and once to add the arguments of the finetune/lora.py script.

Instead I will do subcommands inside subcommands which will require rolling out our custom parser. The gist is:

from jsonargparse import ArgumentParser

finetune_lora = ArgumentParser()
finetune_lora.add_argument("--lr")

finetune = ArgumentParser()

generate = ArgumentParser()
generate.add_argument("--num_tokens")

parser = ArgumentParser()
subcommands = parser.add_subcommands()
subcommands.add_subcommand("finetune", finetune)
subcommands.add_subcommand("generate", generate)

finetune_subcommands = finetune.add_subcommands()
finetune_subcommands.add_subcommand("lora", finetune_lora)

args = parser.parse_args()
print(args)

@mauvilsa
Copy link

I forgot to mention in my initial response, that recently added, it is possible to use jsonargparse.CLI with custom named subcommands. Look at the class Raffle: example in the docs. It has some limitations, but it might fit the use case.

@carmocca
Copy link
Contributor Author

Very interesting @mauvilsa. How do you set help messages in the subcommands? This is what I rolled out and what I would want to replace: https://github.com/Lightning-AI/litgpt/blob/wip/litgpt/__main__.py#L43-L127

@mauvilsa
Copy link

How do you set help messages in the subcommands?

Currently not possible. But I have thought that this could be added like:

components = {
    "weekday": {
        "_help": "Help for weekday",
        "tier1": Raffle(prize=100),
        "tier2": Raffle(prize=50),
    },
    "weekend": {
        "_help": "Help for weekend",
        "tier1": Raffle(prize=300),
        "tier2": Raffle(prize=75),
    },
}

If it is this simple, then implementing it wouldn't be difficult.

@mauvilsa
Copy link

mauvilsa commented Apr 9, 2024

The _help option in jsonargparse.CLI is now implemented in omni-us/jsonargparse#485.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants