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

Refactor existing HuggingFace support to a more robust one #1044

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Anindyadeep
Copy link
Contributor

@Anindyadeep Anindyadeep commented May 20, 2024

Current status: WIP

The PR motivation started from this issue: #1018

What this PR do?

We have an existing HuggingFace model integration on DsPY. However developers can not use this class with much flexibility. So the goal of the PR is to provide a balanced abstraction such that developers can

  1. add their own model object
  2. or add just different configs and arguments while instantiating, example: quantization_config, lora_config directly in the dspy.HF class
  3. make it also directly compatible with the finetuning procedures (might not be applicable now)

The reason is, HuggingFace is very popular for sometimes writing out entire lifecycle. So writing entre pipelines with huggingface and dspy might need to have almost all the supported configs and HF's own addons (like bitsandbytes, peft etc), so that they can focus more on dspy instead of finding wayaround on how to add this or that with dspy huggingface.

Todos

  • Initial working draft implementation
  • Testing the implementation passing HF models object
  • Testing the implementation passing HF models object as string
  • Testing the implementation passing HF models with quantization support
  • Testing the implementation passing HF models with multi-gpu support (currently not have multi gpu settings)
  • Refine the code (check once more, typos, check on some todos I wrote inside the code etc)
  • Write good tutorial like documentation for this
  • Fininshing (link etc)

cc: @okhat, let's discuss more about this approach and feel free to provide feedbacks :)

@Anindyadeep Anindyadeep marked this pull request as draft May 20, 2024 04:08
@Anindyadeep Anindyadeep changed the title Migrating existing HuggingFace support to a more robust one Refactor existing HuggingFace support to a more robust one May 20, 2024
@Anindyadeep
Copy link
Contributor Author

Hi would love to get your thoughts on this, so that according to the feedbacks I can move forward. Thanks

cc: @arnavsinghvi11

@Anindyadeep
Copy link
Contributor Author

Current status: WIP

The PR motivation started from this issue: #1018

What this PR do?

We have an existing HuggingFace model integration on DsPY. However developers can not use this class with much flexibility. So the goal of the PR is to provide a balanced abstraction such that developers can

  1. add their own model object
  2. or add just different configs and arguments while instantiating, example: quantization_config, lora_config directly in the dspy.HF class
  3. make it also directly compatible with the finetuning procedures (might not be applicable now)

The reason is, HuggingFace is very popular for sometimes writing out entire lifecycle. So writing entre pipelines with huggingface and dspy might need to have almost all the supported configs and HF's own addons (like bitsandbytes, peft etc), so that they can focus more on dspy instead of finding wayaround on how to add this or that with dspy huggingface.

Todos

  • Initial working draft implementation
  • Testing the implementation passing HF models object
  • Testing the implementation passing HF models object as string
  • Testing the implementation passing HF models with quantization support
  • Testing the implementation passing HF models with multi-gpu support (currently not have multi gpu settings)
  • Refine the code (check once more, typos, check on some todos I wrote inside the code etc)
  • Write good tutorial like documentation for this
  • Fininshing (link etc)

cc: @okhat, let's discuss more about this approach and feel free to provide feedbacks :)

Hi just wanted to check on whether we can move forward with this PR or not, else we can close it. Thanks :)

@Anindyadeep Anindyadeep marked this pull request as ready for review June 6, 2024 07:54
except ImportError as exc:
raise ModuleNotFoundError(
"You need to install the following libraries: ",
"transformers >= 4.30.0, torch==2.2.2, accelerator"
Copy link
Collaborator

@arnavsinghvi11 arnavsinghvi11 Jun 17, 2024

Choose a reason for hiding this comment

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

would eventually be added to pyproject.toml and/or poetry? also would be helpful to give the pip install command to avoid confusion

@arnavsinghvi11
Copy link
Collaborator

Hi @Anindyadeep , thanks for this PR refactor of HF! This looks great!

I anticipate this PR will eventually replace hf.py so it would be great to either build on the existing file if possible. It would also be easier to understand what’s being retained and any additional differences. Following the leftover todos and testing, let me know if you have any comments/additions to review.

Looking forward to the next stage of this PR!

@Anindyadeep
Copy link
Contributor Author

Hi @Anindyadeep , thanks for this PR refactor of HF! This looks great!

I anticipate this PR will eventually replace hf.py so it would be great to either build on the existing file if possible. It would also be easier to understand what’s being retained and any additional differences. Following the leftover todos and testing, let me know if you have any comments/additions to review.

Looking forward to the next stage of this PR!

Hey thanks for the reply, on a second though I feel this PR is a very big addition so in that case, I could re-start from the PR implementation, where I can break into smaller parts (which could be easier for you all as well for review) and doing changes from hf.py. Does that sounds good to you?

@Anindyadeep
Copy link
Contributor Author

Hi @Anindyadeep , thanks for this PR refactor of HF! This looks great!
I anticipate this PR will eventually replace hf.py so it would be great to either build on the existing file if possible. It would also be easier to understand what’s being retained and any additional differences. Following the leftover todos and testing, let me know if you have any comments/additions to review.
Looking forward to the next stage of this PR!

Hey thanks for the reply, on a second though I feel this PR is a very big addition so in that case, I could re-start from the PR implementation, where I can break into smaller parts (which could be easier for you all as well for review) and doing changes from hf.py. Does that sounds good to you?

Let me know your thoughts @arnavsinghvi11 whenever you find some bandwidth, thanks :)

@arnavsinghvi11
Copy link
Collaborator

I could re-start from the PR implementation, where I can break into smaller parts (which could be easier for you all as well for review) and doing changes from hf.py. Does that sounds good to you?

Yes that would be great!

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

Successfully merging this pull request may close these issues.

None yet

2 participants