Skip to content

Added metrics docstrings#1392

Open
rsyue wants to merge 8 commits intomainfrom
richard/metric_docstring
Open

Added metrics docstrings#1392
rsyue wants to merge 8 commits intomainfrom
richard/metric_docstring

Conversation

@rsyue
Copy link
Contributor

@rsyue rsyue commented Oct 22, 2025

What does this PR do? Please describe:
Added docstrings to files in the metrics module

Fixes #1360

Check list:

  • Was the content of this PR discussed and approved via a GitHub issue? (no need for typos or documentation improvements)
  • Did you read the contributor guideline?
  • Did you make sure that your PR does only one thing instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests?
  • Did you verify new and existing tests pass locally with your changes?
  • Did you update the CHANGELOG? (no need for typos, documentation, or minor internal changes)

@rsyue rsyue requested a review from cbalioglu as a code owner October 22, 2025 01:01
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 22, 2025
Copy link
Contributor

@cbalioglu cbalioglu left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, however I don't think we should be overriding docstrs of the base MetricRecorder methods in each subclass.

We also certainly should not be adding docstrs to private methods/functions. If they are not descriptive enough, we should ideally think about how we can refactor them or if that is not feasible just have some regular inline comments instead of docstrs.

My suggestion is that if you think there is more info needed to make the API reference more clear, to add them either to MetricRecorder or to the class docstr of corresponding metric recorders.

Having said that, we will likely have to have a lot more documentation on how these metric recorders behave. I am fine with adding more preliminary docs to them for now, but note that we will certainly significantly overhaul the current docs in the near future.

def record_metric_values(
self, category: str, values: Mapping[str, object], step_nr: int | None = None
) -> None:
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need to add documentation for overridden methods. The docstr of the method on the corresponding interface (in this case MetricRecorder) should be descriptive enough to explain the expected behavior of the metod.

@override
def close(self) -> None:
"""
Closes and removes the :class:MetricRecorder
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.

self, category: str, values: Mapping[str, object], step_nr: int | None = None
) -> None:
"""
Gets, sorts, and maps metrics, their values, and descriptions to a ``dict``
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, no need to override the docstr of base interface. Any behavior specific to this subclass should ideally be described in the class docstr.

values_and_descriptors.sort(key=lambda p: (p[1].priority, p[1].display_name))

def sanitize(value: object) -> object:
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an inline function. No need for docstr.

raise_operational_system_error(ex)

def _get_stream(self, category: str) -> TextIO:
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to document private functions.

@override
def close(self) -> None:
"""
Closes the stream and clears object
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document fairseq2.metrics

2 participants