Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Add list-suts command (#257) #263

Merged
merged 11 commits into from
Mar 20, 2024
Merged

Add list-suts command (#257) #263

merged 11 commits into from
Mar 20, 2024

Conversation

0xkerem
Copy link
Member

@0xkerem 0xkerem commented Mar 9, 2024

This pull request encompasses the addition of the 'list-suts' command as outlined in issue #257, along with the necessary test for this new feature. The key activities included are as follows:

  • list-suts Command Implementation: A new command has been introduced to list valid values for the --sut option. This command also indicates whether a SUT requires secrets.

  • Testing Process: Tests pertinent to the newly added command have been written and executed successfully. These tests verify that the command functions as expected.

  • Documentation Update: Information on how to use the newly added 'list-suts' command has been incorporated into the project documentation.

Here are terminal output examples showcasing the list-suts command in action: one displaying a SUT with its required secrets, and the other indicating a SUT with missing secrets.

$ poetry run python newhelm/main.py list-suts

gpt2
class=HuggingFaceSUT
args=['gpt2', SerializedSecret(module='newhelm.suts.huggingface_client', qual_name='HuggingFaceToken')]
kwargs={}
Uses required secrets:
{'demo': {'demo_api_key': '12345'}}

Cannot display SUT llama-2-7b because it requires the following secrets:
scope='together' key='api_key' instructions='See https://api.together.xyz/settings/api-keys'

* Implemented the list-suts command in newhelm_cli
* Added functionality to display each SUT with required secrets
* Refactored some parts of the display logic for better clarity
* This is the base version of the function, it will be imprpoved
* secret_values.py: InjectSecret.__repr__ initialized
* main.py: list_suts output formatted for SUTs with required secrets
* Updated list_suts for desired output.
* Updated dev_quick_start.md to include new list-suts command.
* Restored secret_values.py (No need for this issue)
- Add test_list_suts to test_cli.py
- Use @expensive_tests decorator for conditional skipping
- Confirm test passes when run without the @expensive_tests
Copy link

github-actions bot commented Mar 9, 2024

MLCommons CLA bot All contributors have signed the MLCommons CLA ✍️ ✅

@0xkerem
Copy link
Member Author

0xkerem commented Mar 9, 2024

Hello @brianwgoldman , I read CONTRIBUTING.md before PR, but I could not access the form specified in the link.

@mkly
Copy link
Member

mkly commented Mar 9, 2024

Hi @0xkerem ! Very excited to see your interest in contributing. Are you able to access https://mlcommons.org/community/subscribe/ ?

If so, you can add your name, email address, and Github ID to that form? You should receive an email with with a document to fill out for the CLA. If you do not receive a response to that within a day or two please let me know here. Thanks.

@0xkerem
Copy link
Member Author

0xkerem commented Mar 9, 2024

Hi @0xkerem ! Very excited to see your interest in contributing. Are you able to access https://mlcommons.org/community/subscribe/ ?

@mkly Unfortunately, this page does not open, I encounter the error notification shown in the screenshot.

image

@mkly
Copy link
Member

mkly commented Mar 9, 2024

Thanks for that additional info. I would go ahead and send an email to support@mlcommons.org with your full name and Github ID. I would also link to this thread and include that you are looking to sign the ML Commons Contributor License Agreement(CLA). Sorry for the trouble!

@0xkerem
Copy link
Member Author

0xkerem commented Mar 9, 2024

Thank you so much for your help. No problem :)

@0xkerem
Copy link
Member Author

0xkerem commented Mar 11, 2024

@mkly Hi! Have you received any answers?

newhelm/main.py Outdated
click.echo(f"args={sut_obj._initialization_record.args}") # Consider create getter function for `_initialization_record`
click.echo(f"kwargs={sut_obj._initialization_record.kwargs}")
click.echo(f"Uses required secrets:")
click.echo(secrets)
Copy link
Contributor

Choose a reason for hiding this comment

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

secrets here is everything you defined in your config/secrets.toml file, and will be the same for all SUTs.

In order to get this behavior I think we are going to need to add functionality to dependency_injection that tells us what dependencies were used.

newhelm/main.py Outdated

display_header(sut)
click.echo(f"class={sut_obj.__class__.__name__}")
click.echo(f"args={sut_obj._initialization_record.args}") # Consider create getter function for `_initialization_record`
Copy link
Contributor

Choose a reason for hiding this comment

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

The sut_entry variable in this loop is a FactoryEntry which has all the args and kwargs in it already. You can get this information without attempting to construct the sut_obj.

newhelm/main.py Outdated

display_header(sut)
click.echo(f"class={sut_obj.__class__.__name__}")
click.echo(f"args={sut_obj._initialization_record.args}") # Consider create getter function for `_initialization_record`
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider create getter function for _initialization_record

You can use get_initialization_record, although as mentioned in my other comment getting this data directly from FactorEntry is probably cleaner.

Copy link
Member Author

Choose a reason for hiding this comment

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

@brianwgoldman Hello, you explained it very well again, thank you for this and for your feedback. I tried to understand and apply it as accurately as I could. If I make a mistake again, I'm waiting for your feedback!

Sample printouts for missing secret:

$ poetry run python newhelm/main.py list-suts

llama-2-7b
class=TogetherCompletionsSUT
args=('togethercomputer/llama-2-7b', <newhelm.secret_values.InjectSecret object at 0x0000021F76C56740>)
kwargs={}
Missing required secrets:
scope='together' key='api_key', instructions='See https://api.together.xyz/settings/api-keys'

gpt-3.5-turbo
class=OpenAIChat
args=('gpt-3.5-turbo', <newhelm.secret_values.InjectSecret object at 0x0000021F772FA3B0>, <newhelm.secret_values.InjectSecret object at 0x0000021F772FAF20>)
kwargs={}
Missing required secrets:
scope='openai' key='api_key', instructions='See https://platform.openai.com/api-keys'

Sample outputs when the required secret conditions are met:

$ poetry run python newhelm/main.py list-suts

demo_yes_no
class=DemoYesNoSUT
args=()
kwargs={}
Uses required secrets:
[]

gpt2
class=HuggingFaceSUT
args=('gpt2', <newhelm.secret_values.InjectSecret object at 0x0000021F0D09BCD0>)
kwargs={}
Uses required secrets:
[HuggingFaceToken()]

gpt-3.5-turbo
class=OpenAIChat
args=('gpt-3.5-turbo', <newhelm.secret_values.InjectSecret object at 0x000002168868A350>, <newhelm.secret_values.InjectSecret object at 0x000002168868AEC0>)
kwargs={}
Uses required secrets:
[OpenAIApiKey(), OpenAIOrgId()]

@mkly
Copy link
Member

mkly commented Mar 11, 2024

@0xkerem I should have mentioned that it might take a few days for them to get back to you. I'll follow up tomorrow if you still have not received anything. Thanks for your patience.

* Improved readability and structure of list_suts.
* Updated inject_dependencies to handle new secrets.
* Enhanced inject_dependencies with three return values.
* Modified all occurrences of inject_dependencies to align with its updated usage.
@@ -11,28 +11,40 @@

def inject_dependencies(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the modifications to this method make the most common use case (setting dependencies) unnecessarily complicated to support a rare use case (check dependencies).

I think we should keep the signature of this method, and instead create a peer that is something like list_dependency_usage which returns:

  • All dependencies that were successfully read.
  • All dependencies that were required but not provided.
  • (Maybe) all dependencies that were optional but not provided.

Sorry for potentially misleading you with my previous comment.

newhelm/main.py Outdated
try:
_, _, used_secrets = inject_dependencies(sut_entry.args, sut_entry.kwargs, secrets)

flag = "Uses"
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally if a SUT had one secret provide and one missing, we could report both of those at the same time.

Copy link
Member Author

Choose a reason for hiding this comment

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

@brianwgoldman No problem! I'm glad to contribute code improvements. :) I've restored the inject_dependencies function and introduced list_dependency_usage. Currently, it doesn't return optional secrets, but but I will add it when I have time soon. Also, I've updated the formatting for better clarity: now, if there are both used and missing requirements, they will be displayed simultaneously. If there are no missing requirements, they won't be shown. Additionally, in cases where no secrets are needed, the message No Secrets Used. will be displayed.

Example for sut without used secrets and with missing secrets:

$ poetry run python newhelm/main.py list-suts

llama-2-7b
Class: TogetherCompletionsSUT
Args: ('togethercomputer/llama-2-7b', <newhelm.secret_values.InjectSecret object at 0x00000228F06DBCD0>)
Kwargs: {}
No Secrets Used.
Missing Secrets:
Scope: 'together', Key: 'api_key', Instructions: 'See https://api.together.xyz/settings/api-keys'

Example for sut with used secrets and without missing secrets:

$ poetry run python newhelm/main.py list-suts

gpt2
Class: HuggingFaceSUT
Args: ('gpt2', <newhelm.secret_values.InjectSecret object at 0x0000022886B9BA30>)
Kwargs: {}
Used Secrets:
[HuggingFaceToken()]

Example for sut without both used and missing secrets:

$ poetry run python newhelm/main.py list-suts

Class: DemoYesNoSUT
Args: ()
Kwargs: {}
No Secrets Used.

Example for sut with both used and missing secrets:

$ poetry run python newhelm/main.py list-suts

gpt-3.5-turbo
Class: OpenAIChat
Args: ('gpt-3.5-turbo', <newhelm.secret_values.InjectSecret object at 0x00000228F0D7A110>, <newhelm.secret_values.InjectSecret object at 0x00000228F0D7AC80>)
Kwargs: {}
Used Secrets:
[OpenAIOrgId()]
Missing Secrets:
Scope: 'openai', Key: 'api_key', Instructions: 'See https://platform.openai.com/api-keys'

I'm sorry that I accidentally used the name of the internal function in the commit message because I was distracted.

0xkerem and others added 2 commits March 13, 2024 23:43
* Reverted modifications in inject_dependencies to original state.
* Introduced format_missing_secrets function.
* Corrected usage of inject_dependencies across codebase.
* Improved formatting and clarity in list_suts function.
@nathanw-mlc
Copy link
Member

nathanw-mlc commented Mar 14, 2024

Unfortunately, this page does not open, I encounter the error notification shown in the screenshot.

image

@0xkerem are you using a DNS ad-blocker of some kind? I've found that some lists block Mailchimp domains.

@0xkerem
Copy link
Member Author

0xkerem commented Mar 14, 2024

@0xkerem are you using a DNS ad-blocker of some kind? I've found that some lists block Mailchimp domains.

@nathanw-mlc I use regular ad blocker but when I disabled it, it didn't work. Then I tried disabling the antivirus and using another browser, but still the same error. I thought connecting via VPN might help, this time I can open the form, I will fill it out now. I hope it's okay to use vpn to fill out the form.

@nathanw-mlc
Copy link
Member

I hope it's okay to use vpn to fill out the form.

So long as the VPN provider doesn't have DNS rules that block the form, there's absolutely no problem with using a VPN.

@0xkerem
Copy link
Member Author

0xkerem commented Mar 14, 2024

@mkly and @nathanw-mlc Thank you very much for your help. I filled out the form and digitally filled out and signed the agreement in the email I received. Then I sent it to the specified email.

@0xkerem
Copy link
Member Author

0xkerem commented Mar 14, 2024

recheck

@mkly
Copy link
Member

mkly commented Mar 19, 2024

@0xkerem Looks like there are a few formatting issues with the linter. You can run the following in the root of the repo to fix those.

poetry run black .

After that, you should be green to merge this in. Thanks again!

@0xkerem
Copy link
Member Author

0xkerem commented Mar 20, 2024

@mkly Thank you! I fixed that and the remaining errors. I guess there is no problem anymore.

@mkly mkly merged commit f78627f into mlcommons:main Mar 20, 2024
2 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants