Skip to content
This repository was archived by the owner on Apr 23, 2026. It is now read-only.

feat: add serve config for teacher model in ilab data generate - #1777

Merged
mergify[bot] merged 4 commits into
instructlab:mainfrom
alimaredia:data-generate-serve-config
Jul 22, 2024
Merged

feat: add serve config for teacher model in ilab data generate#1777
mergify[bot] merged 4 commits into
instructlab:mainfrom
alimaredia:data-generate-serve-config

Conversation

@alimaredia

Copy link
Copy Markdown
Contributor

Currently ilab data generate uses the configuration from the serve section of configuration file to serve the teacher model in the background.

In the case where a user is using a specific model only as the teacher model, the user would have to edit the serve section of the config with the teacher model's settings.

Since the teacher model and it's configuration is static, and the serve section is dynamic, the teacher model and it's configuration should live in the generate section of the configuration.

Giving the teacher model it's own configuration section also prevents the user from accidentally serving the teacher model, if they have not changed the serve section.

This PR is meant to be a starting point. Further work should evolve the configuration of the teacher model in ilab data generate to be similar to how the ilab model evaluate command configures the judge model for MT-Bench.

This PR also includes a commit that adds the --enable-serving-output flag to ilab data generate. This flag serves the same purpose as it does in ilab model evaluate.

Checklist:

  • Commit Message Formatting: Commit titles and messages follow guidelines in the
    conventional commits.
  • Changelog updated with breaking and/or notable changes for the next minor release.
  • Documentation has been updated, if necessary.
  • Unit tests have been added, if necessary.
  • Integration tests have been added, if necessary.

@alimaredia
alimaredia requested review from leseb and russellb July 18, 2024 09:19
@mergify mergify Bot added the testing Relates to testing label Jul 18, 2024
@alimaredia alimaredia added this to the 0.18.0a3 milestone Jul 18, 2024
@mergify mergify Bot added the ci-failure PR has at least one CI failure label Jul 18, 2024
@alimaredia alimaredia added the hold In-progress PR. Tag should be removed before merge. label Jul 18, 2024
@alimaredia

Copy link
Copy Markdown
Contributor Author

Adding the hold label, which will be removed after I'm done testing this PR by hand. Reviews are still welcome.

@alimaredia
alimaredia force-pushed the data-generate-serve-config branch from 3f9d799 to ab070ae Compare July 18, 2024 09:32
@mergify mergify Bot removed the ci-failure PR has at least one CI failure label Jul 18, 2024

@leseb leseb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks ok to me but I'm missing some context. Can you explain how is configured the teacher model? Thanks

@russellb

Copy link
Copy Markdown
Contributor

I guess I just don’t feel this is necessary. Here’s how I think about it: something has to go in the serve config. What is the majority use case that is fair to expect should be in there? My thought: the teacher model config.

An alternative answer to that could be “the target model to be trained, for use with ilab chat to test model behavior.”

Is the latter what you were thinking?

I’ll also say that I don’t like “general inference use cases” as an answer here because I don’t think using ilab makes much sense for that vs running vllm directly (via systemd). I’m not sure what value ilab provides in that case.

@alimaredia

Copy link
Copy Markdown
Contributor Author

@leseb The teacher model can be a separate model that specializes just generating the data from the taxonomy. One model you could use for example is Mixtral. This is similar to how we have a judge model just for MT-Bench in evaluation. The model is prometheus.

The teacher model could have it's own set of configuration, ex: vllm_args.

@alimaredia

Copy link
Copy Markdown
Contributor Author

I guess I just don’t feel this is necessary. Here’s how I think about it: something has to go in the serve config. What is the majority use case that is fair to expect should be in there? My thought: the teacher model config.

An alternative answer to that could be “the target model to be trained, for use with ilab chat to test model behavior.”

Is the latter what you were thinking?

I’ll also say that I don’t like “general inference use cases” as an answer here because I don’t think using ilab makes much sense for that vs running vllm directly (via systemd). I’m not sure what value ilab provides in that case.

The alternative answer along with inference use cases is what I was thinking. Here's how I see the entire ilab workflow along with when models are served:

  1. Download all the necessary models. These are the Base, Teacher, and Judge models.
  2. Chat with the Base model on how much it knows the information you want it to know about. Right now chat reads from the serve config if the model is started up in the background.
  3. Make changes to the taxonomy, adding new skills and knowledge.
  4. Run data generation. Right now the model started up in the background also reads from the serve config.
  5. Train the model. Here MT-Bench is used in multiphase training. I think @JamesKunstle is calling the exact same functions in model/evaluate.py for the base and judge model and not reading anything from the serve config.
  6. Chat with the trained model to see what the model learned. As mentioned in step 2 right now chat reads from the serve config if the model is started up in the background but since it's derived from the base model, I think it's serving configuration should exactly be the same except for the model path.
  7. Run evaluation. For MT-Bench the necessary base and judge model configuration happens within evaluate.py, not in the serve config.

As I mentioned above I think since the teacher model can be viewed as something static similar to the judge model, that's a good reason for it to have it's own config in the generate section.

@leseb @n1hility do you have anything to add about the inference use case?

@russellb

Copy link
Copy Markdown
Contributor

OK - I buy that the base model is a better thing to assume stays in the base serve config. Thanks.

return get_api_base(self.host_port)


class _generate(BaseModel):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason you needed to move this? It makes it harder to see what actually changed.

If you feel it needs to move, I would generally recommend doing that type of refactoring in a dedicated commit that includes no functional changes. That way you can still see the real code changes in the commit series.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved it below the _serve classes because those need to be declared first in order for _generate to have a member of that type. Without this move I get a NameError whenever ilab is invoked.

I wish I didn't have to move the class, but the only thing that has changed in the _generate class is just the addition of the teacher_serve_config variable.

@booxter booxter Jul 18, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can reference via string, as described here

class Foo(BaseModel):
    bar: 'Bar'

class Bar(BaseModel):
    pass

(though I'm fine with the class being moved too)

Comment thread src/instructlab/configuration.py Outdated
taxonomy_base: StrictStr

# additional fields with defaults
teacher_serve_config: _serve

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please look into backwards compatibility? I haven't tested this, but I'm guessing that old configs will be broken by this?

My preference would be to use the default serve config if it is not specified in this section.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The addition of this in the _serve config would not make the data generate command able to work with older configs. Especially since the code change I made in generate.py now expects the teacher_serve_config.

Backwards compatibility within the older config wasn't something I considered when I made this PR simply because I thought there have been so many changes to the config that we're not expecting the older configs to be fowards compatible.

It's for this reason I think #1749 should include a check that causes ilab to error out if a config doesn't have the version field.

What I could do is add a check in generate.py to see if the config has the teacher_serve_config section in the generate section and if it doesn't fall back to using the serve section of the config. How does that sound?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That config versioning PR merged (#1749) -- are you planning to update this PR to bump the version in some way?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that the config version if for the release and not meant to be changed between PRs before v0.18.0.

This is not meant to be a take on when the config version should be changed, just that it should not be changed before the v0.18.0 release.

@alinaryan alinaryan modified the milestones: 0.18.0a3, 0.18.0a4 Jul 18, 2024
taxonomy_path: StrictStr
taxonomy_base: StrictStr

# additional fields with defaults

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new section doesn't seem to have a default value set in the model. Should it be defined elsewhere, so that this comment doesn't apply to it? (But see below.)

Comment thread src/instructlab/configuration.py Outdated
taxonomy_base: StrictStr

# additional fields with defaults
teacher_serve_config: _serve

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the name for the new section is not ideal. I don't think it should have _config suffix (it's redundant - the context here is well known already). Perhaps even the _serve mid-prefix could also be dropped, to simplify the name even more. What exactly does it communicate to the user beyond what teacher name could already do?

Comment thread src/instructlab/configuration.py Outdated
model=DEFAULTS.DEFAULT_MODEL,
taxonomy_path=DEFAULTS.TAXONOMY_DIR,
taxonomy_base=DEFAULTS.TAXONOMY_BASE,
teacher_serve_config=_serve(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default section seems to be identical to what is used for serve section. I suggest to avoid the duplication of the code here and in lines 413+: put the default value for both sections in a variable, then refer from both locations.

(That said, I think these defaults belong to the model spec, see above.)

Comment thread src/instructlab/configuration.py Outdated
taxonomy_base: StrictStr

# additional fields with defaults
teacher_serve_config: _serve

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could specify a default value for the field, and make all the nested models provide reasonable defaults; then you wouldn't need to pass the teacher argument below in get_default_config. To see what I mean, refer to: https://gist.github.com/booxter/e1332bbe3a5344ee217409d133a13776

I believe this will tackle the backwards compatibility concern by Russell too.

@alimaredia
alimaredia force-pushed the data-generate-serve-config branch from ab070ae to fe85b64 Compare July 19, 2024 12:23
@mergify mergify Bot added the ci-failure PR has at least one CI failure label Jul 19, 2024
@alimaredia
alimaredia force-pushed the data-generate-serve-config branch from fe85b64 to fc46dd4 Compare July 19, 2024 12:33
@mergify mergify Bot removed the ci-failure PR has at least one CI failure label Jul 19, 2024
@alimaredia
alimaredia force-pushed the data-generate-serve-config branch from fc46dd4 to bbcdd17 Compare July 19, 2024 12:35
@mergify mergify Bot added the ci-failure PR has at least one CI failure label Jul 19, 2024
@alimaredia
alimaredia force-pushed the data-generate-serve-config branch from bbcdd17 to bbd8824 Compare July 19, 2024 12:46
@mergify mergify Bot removed the ci-failure PR has at least one CI failure label Jul 19, 2024
@booxter

booxter commented Jul 19, 2024

Copy link
Copy Markdown
Contributor

Note: the last patch should be squashed before merging.

@alimaredia
alimaredia force-pushed the data-generate-serve-config branch from bbd8824 to 710190a Compare July 19, 2024 17:41
@booxter
booxter requested a review from russellb July 19, 2024 23:21
@alimaredia alimaredia removed the hold In-progress PR. Tag should be removed before merge. label Jul 22, 2024
@alimaredia

Copy link
Copy Markdown
Contributor Author

@booxter Ran the branch by hand, and serving worked as expected. I've removed the hold label.

@mergify

mergify Bot commented Jul 22, 2024

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. @alimaredia please rebase it. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase This Pull Request needs to be rebased label Jul 22, 2024
@alinaryan alinaryan modified the milestones: 0.18.0a4, 0.18.0a5 Jul 22, 2024
Signed-off-by: Ali Maredia <amaredia@redhat.com>
Passing this flag ensures that the stdout and stderr
of  vLLM will be output when ilab data generate
is run. This is useful for debugging purposes.

Signed-off-by: Ali Maredia <amaredia@redhat.com>
If the teacher section is not included in the
config.yaml and read by ilab, the value of
ctx.obj.generate.teacher is set to the default
value of teacher in _generate.

Signed-off-by: Ali Maredia <amaredia@redhat.com>
@alimaredia
alimaredia force-pushed the data-generate-serve-config branch from 0c21abc to 6e05cfa Compare July 22, 2024 15:33
@mergify mergify Bot removed the needs-rebase This Pull Request needs to be rebased label Jul 22, 2024
@russellb
russellb dismissed their stale review July 22, 2024 15:42

My preference would be to adopt more disciplined handling of config file changes instead of waiting until some point in the future since I don't think it's a ton of extra work. However, I will just bow out of this review so I'm not blocking anything.

@russellb
russellb removed their request for review July 22, 2024 15:42

@booxter booxter left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for quick respin.

Comment thread src/instructlab/configuration.py Outdated
chunk_word_count: PositiveInt = DEFAULTS.CHUNK_WORD_COUNT
# DEPRECATED: see sdg_scale_factor instead
# Left in place so that we can still detect and give a warning if its
# specified in an old configuraiton file.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configuration

- Add entry for --enable-serving-output flag for
  ilab data generate
- Add entry for new teacher section in the
  generate section of the config

Signed-off-by: Ali Maredia <amaredia@redhat.com>
@alimaredia
alimaredia force-pushed the data-generate-serve-config branch from 6e05cfa to e6744d2 Compare July 22, 2024 15:44
@alinaryan alinaryan modified the milestones: 0.18.0a5, 0.18.0a6 Jul 22, 2024
@alimaredia

Copy link
Copy Markdown
Contributor Author

@russellb could you approve this PR so it merges?

default=-1, deprecated="see 'sdg_scale_factor' instead", exclude=True
)
sdg_scale_factor: Optional[PositiveInt] = DEFAULTS.SDG_SCALE_FACTOR
output_dir: StrictStr = Field(default_factory=lambda: DEFAULTS.DATASETS_DIR)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove these Fields as they were previously used to prevent the config values from being cached before we ran tests. Nowadays, each test will reset the home directories to point to the temporary path fixture.

Suggested change
output_dir: StrictStr = Field(default_factory=lambda: DEFAULTS.DATASETS_DIR)
output_dir: StrictStr = DEFAULTS.DATASETS_DIR

@alimaredia alimaredia Jul 22, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RobotSail The entire _generate section was moved in this PR, and one addition was made, the addition of the teacher member.

The line you mentioned is the same as what's in main here (https://github.com/instructlab/instructlab/blob/main/src/instructlab/configuration.py#L266). To keep the scope of this PR focused I'd prefer to open up a follow up PR with that change, and possibly changes to any other variables in this section.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, let's approve this then and then fix it later.

@RobotSail RobotSail left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have one comment but once that's addressed we can merge this.

@RobotSail RobotSail left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mergify mergify Bot added the one-approval PR has one approval from a maintainer label Jul 22, 2024
@mergify
mergify Bot merged commit 8a97762 into instructlab:main Jul 22, 2024
@mergify mergify Bot removed the one-approval PR has one approval from a maintainer label Jul 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

testing Relates to testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants