8000 fix: model.fit metric not collected issue. by Genesis929 · Pull Request #1085 · googleapis/python-bigquery-dataframes · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@Genesis929
Copy link
Collaborator

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

@product-auto-label product-auto-label bot added size: xs Pull request size is extra small. api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. labels Oct 15, 2024
@Genesis929 Genesis929 marked this pull request as ready for review October 15, 2024 17:15
@Genesis929 Genesis929 requested review from a team as code owners October 15, 2024 17:15
@Genesis929 Genesis929 added the owlbot:run Add this label to trigger the Owlbot post processor. label Oct 15, 2024
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Oct 15, 2024
@Genesis929 Genesis929 requested review from chelsea-lin and shobsi and removed request for chelsea-lin October 15, 2024 18:04
# fit the model, synchronously
_, job = session._start_query_ml_ddl(sql)
if session._metrics is not None:
session._metrics.count_job_stats(job)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we not do this inside _start_query_ml_ddl? That way all ML DDLs will be accounted in the session metrics

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated, and added an assertion in test for register.


start_execution_count = df._block._expr.session._metrics.execution_count

model.fit(X_train, y_train)
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 we have the opportunity to make this work work all ML APIs - fit, score, predict, transform, .... We should write such tests for all APIs by writing the metrics collection logic in more central place in the code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

score, predict works, seems internally is calling other functions.

Copy link
Contributor
@shobsi shobsi Oct 15, 2024

Choose a reason for hiding this comment

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

Good to know, thanks for checking! We could just pick one or two of the existing tests that does fit, score, predict, register and transform and assert everywhere that we are counting stats for those operations.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Test Added.

@product-auto-label product-auto-label bot added size: s Pull request size is small. and removed size: xs Pull request size is extra small. labels Oct 15, 2024
@Genesis929 Genesis929 requested a review from shobsi October 15, 2024 20:23
job_config.destination_encryption_configuration = None

return bf_io_bigquery.start_query_with_client(self.bqclient, sql, job_config)
results_iterator, query_job = bf_io_bigquery.start_query_with_client(
Copy link
Contributor

Choose a reason for hiding this comment

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

I see start_query_with_client already has the stats update

if metrics is not None:
metrics.count_job_stats(query_job)

so feels like we could be adding double counting

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's not double counting, but yes here we can send the metric into the start_query_with_client, thanks for point that out.

model.fit(X_train, y_train)

end_execution_count = df._block._expr.session._metrics.execution_count
assert end_execution_count - start_execution_count == 2
Copy link
Contributor

Choose a reason for hiding this comment

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

Worth adding a comment why fit does 2 queries

@Genesis929 Genesis929 requested a review from shobsi October 15, 2024 21:51
@Genesis929 Genesis929 merged commit 06cec00 into main Oct 15, 2024
@Genesis929 Genesis929 deleted the model_fit_metric_fix branch October 15, 2024 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. size: s Pull request size is small.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0