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 EvolInstruct and EvolInstructGenerator tasks #407

Merged
merged 41 commits into from
Mar 16, 2024

Conversation

alvarobartt
Copy link
Member

@alvarobartt alvarobartt commented Mar 11, 2024

Description

This PR adds both the EvolInstruct and EvolInstructGenerator tasks ported from https://github.com/h2oai/h2o-wizardlm/blob/main/wizardlm.py with some slight modifications to suit our needs, but respecting the evolutionary approach.

Besides that the AsyncLLM has been fixed so as to use asyncio event loops instead of asyncio.run as it was raising some errors when called within a loop, so now the AsyncLLM implementation is more robust. Also the GeneratorTask has been included for tasks like EvolInstructGenerator i.e. generating data without seed data as input.

Closes #408

Example

import time

from distilabel.llm.mistral import MistralLLM
from distilabel.llm.openai import OpenAILLM
from distilabel.pipeline.local import Pipeline
from distilabel.steps.globals.huggingface import PushToHub
from distilabel.steps.task.evol_instruct.generator import EvolInstructGenerator

if __name__ == "__main__":
    start_time = time.time()

    with Pipeline() as pipeline:
        evol_instruct = EvolInstructGenerator(
            name="evol_instruct",
            llm=OpenAILLM(
                model="gpt-4",
                api_key="sk-***",  # type: ignore
            ),
            num_instructions=10,
            generate_answers=False,
        )

        push_to_hub = PushToHub(name="push_to_hub")  # type: ignore
        evol_instruct.connect(push_to_hub)

    pipeline.run(
        parameters={
            "evol_instruct": {
                "generation_kwargs": {
                    "max_new_tokens": 512,
                    "temperature": 0.7,
                },
            },
            "push_to_hub": {
                "repo_id": "alvarobartt/evol-instruct",
                "split": "train",
                "private": False,
                "token": "hf_***",
            },
        }
    )

    print("--- %s seconds ---" % (time.time() - start_time))

Reference

https://github.com/h2oai/h2o-wizardlm/blob/main/wizardlm.py

Differs from the default `EvolInstruct` which will be refactored to be an evolution on top of existing instructions i.e. always expecting `seed_data` (requires modifications on top of the original implementation)
@alvarobartt alvarobartt added enhancement New feature or request task labels Mar 11, 2024
@alvarobartt alvarobartt added this to the 1.0.0 milestone Mar 11, 2024
@alvarobartt alvarobartt self-assigned this Mar 11, 2024
@alvarobartt alvarobartt changed the base branch from main to core-refactor March 11, 2024 13:10
@alvarobartt alvarobartt marked this pull request as ready for review March 13, 2024 08:51
@alvarobartt alvarobartt linked an issue Mar 13, 2024 that may be closed by this pull request
@alvarobartt
Copy link
Member Author

@alvarobartt, I am also missing the system prompt they defined in the paper but we don't want to implement that either? https://github.com/argilla-io/distilabel/blob/main/src/distilabel/tasks/_templates/evol-instruct.jinja2

Fair, we can include it, but I'm afraid that the misalignments between their official implementation and the paper don't have a clear reference, should we take more inspiration from the paper instead? My experience so far is that using GPT-4 for generating and evolving instructions works well so far, but we can try to compare with and without system_prompt. Also does that apply to both the instruction and the answer, or only the instruction? I guess the first one, but LMK

@alvarobartt Also, I seem to be missing the elimination but you wanted to skip this because general state of LLMs have improved and you feel we don't need it anymore, correct? image

Right, I was using gpt-4, mistral-medium and mistral-large, and didn't run into any of those issues to tackle during post-processing, but maybe we can include it just in case, but IMO those were not needed for this small proof of concept. Anyway, all these details will show whenever we implement DEITA using this building blocks to see whether something's off or not, but I'm afraid that some things they added on top of the post-processing where suited for their models, while bigger and more recent ones seem to preduce nice results with minimal post-processing.

@alvarobartt
Copy link
Member Author

Also I've been exploring a bit on GitHub and, is this a more faithful reproduction of EvolInstruct (pre-WizardLM)? https://github.com/nlpxucan/WizardLM/tree/main/Evol_Instruct cc @davidberenstein1957

@davidberenstein1957
Copy link
Member

davidberenstein1957 commented Mar 13, 2024

@alvarobartt I would say so, yes. This is also the way we eventually implemented it initially. I would also go with the more extensive prompts to ensure we've got a higher change to make it work without more advancd models.

Copy link
Member

@gabrielmbmb gabrielmbmb left a comment

Choose a reason for hiding this comment

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

Hi @alvarobartt, it looks good to me. Some methods are quite big so I would split them

src/distilabel/steps/task/base.py Outdated Show resolved Hide resolved
src/distilabel/steps/task/evol_instruct/base.py Outdated Show resolved Hide resolved
src/distilabel/steps/task/evol_instruct/base.py Outdated Show resolved Hide resolved
src/distilabel/steps/task/evol_instruct/base.py Outdated Show resolved Hide resolved
src/distilabel/steps/task/evol_instruct/generator.py Outdated Show resolved Hide resolved
src/distilabel/steps/task/evol_instruct/generator.py Outdated Show resolved Hide resolved
@alvarobartt alvarobartt merged commit 51872f7 into core-refactor Mar 16, 2024
4 checks passed
@alvarobartt alvarobartt deleted the evol-instruct-task branch March 16, 2024 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request task
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Add EvolInstruct faithful reproduction of WizardLM
3 participants