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

Fix direct usage of TransformerModel #619

Merged
merged 2 commits into from
Oct 11, 2023

Conversation

pquentin
Copy link
Member

Closes #617

@@ -112,6 +112,8 @@ def test(session, pandas_version: str):
"python",
"-m",
"pytest",
"-ra",
Copy link
Member Author

Choose a reason for hiding this comment

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

This reports all test except passes, which is useful to see why a specific would have been skipped.

@@ -112,6 +112,8 @@ def test(session, pandas_version: str):
"python",
"-m",
"pytest",
"-ra",
"--tb=native",
Copy link
Member Author

Choose a reason for hiding this comment

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

This shows the Python native traceback, instead of the overly verbose pytest tracebacks that display the source code (I don't need it, I can see it in my editor).

transformers[torch]>=4.12.0,<=4.27.4; python_version<'3.11'
transformers[torch]>=4.31.0,<=4.33.2; python_version<'3.11'
Copy link
Member Author

Choose a reason for hiding this comment

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

A newer version of transformers is needed to get access token support. This was already upgraded in setup.py, but not here. I'll have to avoid the duplication in the future.

@@ -103,31 +112,17 @@ def download_model_and_start_deployment(tmp_dir, quantize, model_id, task):


class TestPytorchModel:
def __init__(self):
Copy link
Member Author

Choose a reason for hiding this comment

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

pytest will not run any test classes when an __init__ method is defined. So we had a test but it was not run, and pytest only warns about it. I've switched to a pytest fixture instead.

@@ -584,7 +584,7 @@ def __init__(
self,
*,
model_id: str,
access_token: Optional[str],
access_token: Optional[str] = None,
Copy link
Member Author

Choose a reason for hiding this comment

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

The order of access_token does not matter because those are kwargs-only parameter that can't be passed conditionally.

Copy link
Member

Choose a reason for hiding this comment

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

Stylistically, I always prefer default args are at the end, but I don't know if this is more or less Pythonic. Either way is fine, just curious

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, that's an interesting consideration. I don't know if there's one choice that's more Pythonic than the other (I haven't seen enough such cases to tell).

I don't have a strong preference so I am happy to change this.

Copy link
Member

@joshdevins joshdevins left a comment

Choose a reason for hiding this comment

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

LGTM. I see two changes in this PR though. All of the other changes, aside from the argument default are related to something else? It's fine in one PR, not a big deal, just wanted to understand why the other changes.

@@ -584,7 +584,7 @@ def __init__(
self,
*,
model_id: str,
access_token: Optional[str],
access_token: Optional[str] = None,
Copy link
Member

Choose a reason for hiding this comment

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

Stylistically, I always prefer default args are at the end, but I don't know if this is more or less Pythonic. Either way is fine, just curious

@pquentin
Copy link
Member Author

pquentin commented Oct 11, 2023

Thanks. My intention is always to make a single change per pull request. In that case, there is indeed a single changed line in the core Eland package. The rest of the pull request fixes the tests that should have caught the bug but were skipped due to a pytest technicality. Does that make sense?

@pquentin
Copy link
Member Author

Tested the latest commit with eland_import_hub_model and the PyTorchModel API, merging.

@pquentin pquentin merged commit c6ce4b2 into elastic:main Oct 11, 2023
@pquentin pquentin deleted the fix-transformer-model-usage branch October 11, 2023 09:56
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.

Make access_token an optional parameter in TransformerModel
2 participants