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

feat: dspy instrumentation enhancements #158

Merged
merged 32 commits into from
Feb 1, 2024
Merged

Conversation

axiomofjoy
Copy link
Contributor

@axiomofjoy axiomofjoy commented Jan 30, 2024

  • instruments Retriever.forward
  • instruments implicit Module.forward via Module.__call__
  • instruments ColBERTv2.__call__
  • switches requests-mock for responses, which has wider adoption

@axiomofjoy axiomofjoy force-pushed the dspy-module-retriever branch from 26966b0 to fd39918 Compare January 30, 2024 21:20
This was linked to issues Jan 30, 2024
@axiomofjoy axiomofjoy marked this pull request as ready for review February 1, 2024 00:49
@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Feb 1, 2024
SpanAttributes.OUTPUT_MIME_TYPE: OpenInferenceMimeTypeValues.JSON.value,
}
dict(
_flatten(
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure I follow why flatten is need in these cases

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not needed in several cases, only in cases where the attribute values include a list of objects. I included everywhere for the sake of consistency, but can remove if it's confusing.

_flatten(
{
OPENINFERENCE_SPAN_KIND: CHAIN.value,
INPUT_VALUE: _get_input_value(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: _get_input_value isn't actually generic is it? It's specific to predict right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's pretty generic? The problem it is trying to solve is that the contents of args and kwargs depends on whether the user passed arguments positionally or via keyword arguments. That is a problem we'll face for every kind of span.

span.record_exception(exception)
raise
span.set_attributes(
dict(
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above, can't flatten just return a dict?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

_flatten is copy-pasted from our other instrumentation libraries. I think there's some value in keeping it the same in case we want to factor it out at some point.

"usage": {"prompt_tokens": 39, "completion_tokens": 396, "total_tokens": 435},
"system_fingerprint": None,
}
responses.add(
Copy link
Contributor

Choose a reason for hiding this comment

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

nice

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 1, 2024
Comment on lines -17 to +27
@pytest.fixture(scope="module")
@pytest.fixture()
def in_memory_span_exporter() -> InMemorySpanExporter:
return InMemorySpanExporter()


@pytest.fixture(scope="module")
@pytest.fixture()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The instrumentor was not being properly uninstrumented for some reason.

@axiomofjoy axiomofjoy merged commit ff828bb into main Feb 1, 2024
4 checks passed
@axiomofjoy axiomofjoy deleted the dspy-module-retriever branch February 1, 2024 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm This PR has been approved by a maintainer size:XL This PR changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[python][dspy] instrument module [Python][DSPy] trace RM Calls
2 participants