Skip to content

Enforce Dataframe Backend Checks #514

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

Merged
merged 14 commits into from
Feb 6, 2025
Merged

Enforce Dataframe Backend Checks #514

merged 14 commits into from
Feb 6, 2025

Conversation

ryantwolf
Copy link
Contributor

@ryantwolf ryantwolf commented Feb 3, 2025

Description

Refactors all modules to inherit from nemo_curator.modules.base.Module. With this change, the base class now checks to see if the dataframe backend for the Module matches what is passed in, and will throw an error prior to computation if there is a mismatch. We also prove a new module ToBackend() that allows easy chaining of CPU and GPU modules.

Usage

from nemo_curator import Module, Sequential, ToBackend
from nemo_curator.datasets import DocumentDataset

class CPUModule(Module):
    def __init__(self):
        super().__init__(input_backend="pandas")

    def call(self, dataset: DocumentDataset):
        dataset.df["cpu_lengths"] = dataset.df["text"].str.len()
        return dataset


class GPUModule(Module):
    def __init__(self):
        super().__init__(input_backend="cudf")

    def call(self, dataset: DocumentDataset):
        dataset.df["gpu_lengths"] = dataset.df["text"].str.len()
        return dataset

def main():
  client = get_client(cluster_type="gpu")
  # Load a dataset with a pandas CPU backend
  dataset = DocumentDataset.from_pandas(...)
  pipeline = Sequential([
    CPUModule(),
    ToBackend("cudf"),
    GPUModule(),
  ])

  curated_dataset = pipeline(dataset)
  curated_dataset.to_json(...)

if __name__ == "__main__":
  main()

Checklist

  • I am familiar with the Contributing Guide.
  • New or Existing tests cover these changes.
  • The documentation is up to date with these changes.

Signed-off-by: Ryan Wolf <[email protected]>
Signed-off-by: Ryan Wolf <[email protected]>
Signed-off-by: Ryan Wolf <[email protected]>
Signed-off-by: Ryan Wolf <[email protected]>
Signed-off-by: Ryan Wolf <[email protected]>
Signed-off-by: Ryan Wolf <[email protected]>
@ryantwolf ryantwolf requested review from VibhuJawa, sarahyurick, ayushdg and praateekmahajan and removed request for sarahyurick February 3, 2025 21:57
if self.input_backend == "any":
return

backend = type(ddf._meta).__module__.split(".")[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a test case for this? And also type hints for ddf which would be dd.DataFrame

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What part of this do you want to test? I'm not quite seeing which part of this you want me to isolate.

Copy link
Contributor

Choose a reason for hiding this comment

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

As someone reading this, it's not obviously clear what will be the output of .__module__.split(".")[0] of the type of object's _meta attribute. So I would've proposed that you move this to a function and have tests for that and use that function here.
However I see you've changed this to is_cudf_type(..) which is much more readable, and now we can unittest that directly that.

Copy link
Contributor

@praateekmahajan praateekmahajan left a comment

Choose a reason for hiding this comment

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

This looks great. Left a review, with mostly nits around type hints and function renaming and some class abstraction opinions.

@ryantwolf
Copy link
Contributor Author

@sarahyurick @praateekmahajan thanks for your reviews. I addressed the feedback that I immediately agreed with/understood. I left some follow up comments and questions on the other points.

Signed-off-by: Ryan Wolf <[email protected]>
Copy link
Contributor

@sarahyurick sarahyurick left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@praateekmahajan praateekmahajan left a comment

Choose a reason for hiding this comment

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

LGTM thanks for adding this!

Copy link
Contributor

@ayushdg ayushdg left a comment

Choose a reason for hiding this comment

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

lgtm! Thanks

@ryantwolf ryantwolf merged commit 0a7136e into main Feb 6, 2025
4 checks passed
@ryantwolf ryantwolf deleted the rywolf/clean-interop branch February 6, 2025 21:07
philm001 pushed a commit to philm001/NeMo-Curator that referenced this pull request Feb 10, 2025
* Add module and to backend

Signed-off-by: Ryan Wolf <[email protected]>

* Add backend tests

Signed-off-by: Ryan Wolf <[email protected]>

* Fix tests

Signed-off-by: Ryan Wolf <[email protected]>

* Add switch backend tests

Signed-off-by: Ryan Wolf <[email protected]>

* Update modules to use module interface

Signed-off-by: Ryan Wolf <[email protected]>

* Directly invoke module init

Signed-off-by: Ryan Wolf <[email protected]>

* Fix call method

Signed-off-by: Ryan Wolf <[email protected]>

* Fix shuffle call method

Signed-off-by: Ryan Wolf <[email protected]>

* Add docs and more tests

Signed-off-by: Ryan Wolf <[email protected]>

* Fix list formatting in docs

Signed-off-by: Ryan Wolf <[email protected]>

* Address Sarah and Praateek's reviews

Signed-off-by: Ryan Wolf <[email protected]>

* Fix modifier get_backend to backend

Signed-off-by: Ryan Wolf <[email protected]>

* Address Ayush's review

Signed-off-by: Ryan Wolf <[email protected]>

---------

Signed-off-by: Ryan Wolf <[email protected]>
Signed-off-by: Phillip Mobley <[email protected]>
philm001 pushed a commit to philm001/NeMo-Curator that referenced this pull request Feb 10, 2025
* Add module and to backend

Signed-off-by: Ryan Wolf <[email protected]>

* Add backend tests

Signed-off-by: Ryan Wolf <[email protected]>

* Fix tests

Signed-off-by: Ryan Wolf <[email protected]>

* Add switch backend tests

Signed-off-by: Ryan Wolf <[email protected]>

* Update modules to use module interface

Signed-off-by: Ryan Wolf <[email protected]>

* Directly invoke module init

Signed-off-by: Ryan Wolf <[email protected]>

* Fix call method

Signed-off-by: Ryan Wolf <[email protected]>

* Fix shuffle call method

Signed-off-by: Ryan Wolf <[email protected]>

* Add docs and more tests

Signed-off-by: Ryan Wolf <[email protected]>

* Fix list formatting in docs

Signed-off-by: Ryan Wolf <[email protected]>

* Address Sarah and Praateek's reviews

Signed-off-by: Ryan Wolf <[email protected]>

* Fix modifier get_backend to backend

Signed-off-by: Ryan Wolf <[email protected]>

* Address Ayush's review

Signed-off-by: Ryan Wolf <[email protected]>

---------

Signed-off-by: Ryan Wolf <[email protected]>
Signed-off-by: Phillip Mobley <[email protected]>
philm001 pushed a commit to philm001/NeMo-Curator that referenced this pull request Feb 10, 2025
* Add module and to backend

Signed-off-by: Ryan Wolf <[email protected]>

* Add backend tests

Signed-off-by: Ryan Wolf <[email protected]>

* Fix tests

Signed-off-by: Ryan Wolf <[email protected]>

* Add switch backend tests

Signed-off-by: Ryan Wolf <[email protected]>

* Update modules to use module interface

Signed-off-by: Ryan Wolf <[email protected]>

* Directly invoke module init

Signed-off-by: Ryan Wolf <[email protected]>

* Fix call method

Signed-off-by: Ryan Wolf <[email protected]>

* Fix shuffle call method

Signed-off-by: Ryan Wolf <[email protected]>

* Add docs and more tests

Signed-off-by: Ryan Wolf <[email protected]>

* Fix list formatting in docs

Signed-off-by: Ryan Wolf <[email protected]>

* Address Sarah and Praateek's reviews

Signed-off-by: Ryan Wolf <[email protected]>

* Fix modifier get_backend to backend

Signed-off-by: Ryan Wolf <[email protected]>

* Address Ayush's review

Signed-off-by: Ryan Wolf <[email protected]>

---------

Signed-off-by: Ryan Wolf <[email protected]>
ryantwolf added a commit that referenced this pull request Feb 11, 2025
* ci: Pin twine in release workflow (#512)

* ci: Pin twine in release workflow

Signed-off-by: oliver könig <[email protected]>

* maybe fix?

Signed-off-by: oliver könig <[email protected]>

* fix

Signed-off-by: oliver könig <[email protected]>

---------

Signed-off-by: oliver könig <[email protected]>
Signed-off-by: Phillip Mobley <[email protected]>

* ci: Version bump to 0.7.0rc1.dev0 (#513)

Signed-off-by: oliver könig <[email protected]>
Co-authored-by: oliver könig <[email protected]>
Signed-off-by: Phillip Mobley <[email protected]>

* Enforce Dataframe Backend Checks (#514)

* Add module and to backend

Signed-off-by: Ryan Wolf <[email protected]>

* Add backend tests

Signed-off-by: Ryan Wolf <[email protected]>

* Fix tests

Signed-off-by: Ryan Wolf <[email protected]>

* Add switch backend tests

Signed-off-by: Ryan Wolf <[email protected]>

* Update modules to use module interface

Signed-off-by: Ryan Wolf <[email protected]>

* Directly invoke module init

Signed-off-by: Ryan Wolf <[email protected]>

* Fix call method

Signed-off-by: Ryan Wolf <[email protected]>

* Fix shuffle call method

Signed-off-by: Ryan Wolf <[email protected]>

* Add docs and more tests

Signed-off-by: Ryan Wolf <[email protected]>

* Fix list formatting in docs

Signed-off-by: Ryan Wolf <[email protected]>

* Address Sarah and Praateek's reviews

Signed-off-by: Ryan Wolf <[email protected]>

* Fix modifier get_backend to backend

Signed-off-by: Ryan Wolf <[email protected]>

* Address Ayush's review

Signed-off-by: Ryan Wolf <[email protected]>

---------

Signed-off-by: Ryan Wolf <[email protected]>
Signed-off-by: Phillip Mobley <[email protected]>

* Updated documentation to include packaging requirements

Signed-off-by: Phillip Mobley <[email protected]>

* Fixed formatting issues. Signed-off-by: Phillip Mobley <[email protected]>

Signed-off-by: Phillip Mobley <[email protected]>

* Enable ADD ID to work with CPU/GPU both (#479)

* Enable ADD ID to work with CPU/GPU both

Signed-off-by: Vibhu Jawa <[email protected]>

* Make Test runable in a CPU only environment

Signed-off-by: Vibhu Jawa <[email protected]>

* Fix pytest skipping behavior in CPU/GPU environment

Signed-off-by: Vibhu Jawa <[email protected]>

* Raise error instead of skipping test

Signed-off-by: Vibhu Jawa <[email protected]>

---------

Signed-off-by: Vibhu Jawa <[email protected]>
Signed-off-by: Phillip Mobley <[email protected]>

* Add Pooling Strategy Option for embedding creation (#491)

* Add pooling stratedgy

Signed-off-by: Vibhu Jawa <[email protected]>

* Ensure pytest is importable in a CPU only environment

Signed-off-by: Vibhu Jawa <[email protected]>

* Fix last token based on Avinash's feedback

Signed-off-by: Vibhu Jawa <[email protected]>

* Fix indexing issues

Signed-off-by: Vibhu Jawa <[email protected]>

* Merge in main

Signed-off-by: Vibhu Jawa <[email protected]>

* Fix Doc-string

Signed-off-by: Vibhu Jawa <[email protected]>

* Address Sarah's reviews

Signed-off-by: Vibhu Jawa <[email protected]>

---------

Signed-off-by: Vibhu Jawa <[email protected]>
Signed-off-by: Phillip Mobley <[email protected]>

* Add Partition On Logic  (#519)

* add partition_on logic

Signed-off-by: Vibhu Jawa <[email protected]>

* Add Docstring based on Sarah's review

Signed-off-by: Vibhu Jawa <[email protected]>

* Apply Praateek's suggestion and skip test with using pytest.mark.gpu

Signed-off-by: Vibhu Jawa <[email protected]>

* Apply Praateek's suggestion and force index=False

Signed-off-by: Vibhu Jawa <[email protected]>

---------

Signed-off-by: Vibhu Jawa <[email protected]>
Signed-off-by: Phillip Mobley <[email protected]>

* Add improved cleaning methods from Nemotron-CC (#517)

* Add improved cleaning features

Signed-off-by: Ryan Wolf <[email protected]>

* Fix cleaning tests

Signed-off-by: Ryan Wolf <[email protected]>

* Update documentation and CLI scripts

Signed-off-by: Ryan Wolf <[email protected]>

* Address Sarah and Lawrence's reviews

Signed-off-by: Ryan Wolf <[email protected]>

---------

Signed-off-by: Ryan Wolf <[email protected]>
Signed-off-by: Phillip Mobley <[email protected]>

* Update model nomenclature (#497)

* Update model nomenclature

Signed-off-by: Sarah Yurick <[email protected]>

* minor notebook grammar

Signed-off-by: Sarah Yurick <[email protected]>

* add lawrence's suggestion

Signed-off-by: Sarah Yurick <[email protected]>

---------

Signed-off-by: Sarah Yurick <[email protected]>
Signed-off-by: Phillip Mobley <[email protected]>

* small add_id backend fix (#525)

Signed-off-by: Vibhu Jawa <[email protected]>
Signed-off-by: Phillip Mobley <[email protected]>

* benchmark readme updates (#508)

* benchmark readme updates

Signed-off-by: Lawrence Lane <[email protected]>

* benchmark image update

Signed-off-by: Lawrence Lane <[email protected]>

* benchmark text update

Signed-off-by: Lawrence Lane <[email protected]>

---------

Signed-off-by: Lawrence Lane <[email protected]>
Signed-off-by: Phillip Mobley <[email protected]>

* Removal logic for fuzzy / exact (no class abstraction) (#509)

Signed-off-by: Phillip Mobley <[email protected]>

* ci: Limit unit-test duration (#534)

Signed-off-by: oliver könig <[email protected]>
Signed-off-by: Phillip Mobley <[email protected]>

* Enforce Dataframe Backend Checks (#514)

* Add module and to backend

Signed-off-by: Ryan Wolf <[email protected]>

* Add backend tests

Signed-off-by: Ryan Wolf <[email protected]>

* Fix tests

Signed-off-by: Ryan Wolf <[email protected]>

* Add switch backend tests

Signed-off-by: Ryan Wolf <[email protected]>

* Update modules to use module interface

Signed-off-by: Ryan Wolf <[email protected]>

* Directly invoke module init

Signed-off-by: Ryan Wolf <[email protected]>

* Fix call method

Signed-off-by: Ryan Wolf <[email protected]>

* Fix shuffle call method

Signed-off-by: Ryan Wolf <[email protected]>

* Add docs and more tests

Signed-off-by: Ryan Wolf <[email protected]>

* Fix list formatting in docs

Signed-off-by: Ryan Wolf <[email protected]>

* Address Sarah and Praateek's reviews

Signed-off-by: Ryan Wolf <[email protected]>

* Fix modifier get_backend to backend

Signed-off-by: Ryan Wolf <[email protected]>

* Address Ayush's review

Signed-off-by: Ryan Wolf <[email protected]>

---------

Signed-off-by: Ryan Wolf <[email protected]>

* small add_id backend fix (#525)

Signed-off-by: Vibhu Jawa <[email protected]>
Signed-off-by: Phillip Mobley <[email protected]>

* Removal logic for fuzzy / exact (no class abstraction) (#509)

Signed-off-by: Phillip Mobley <[email protected]>

---------

Signed-off-by: oliver könig <[email protected]>
Signed-off-by: Phillip Mobley <[email protected]>
Signed-off-by: Ryan Wolf <[email protected]>
Signed-off-by: Vibhu Jawa <[email protected]>
Signed-off-by: Sarah Yurick <[email protected]>
Signed-off-by: Lawrence Lane <[email protected]>
Co-authored-by: oliver könig <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Ryan Wolf <[email protected]>
Co-authored-by: Vibhu Jawa <[email protected]>
Co-authored-by: Sarah Yurick <[email protected]>
Co-authored-by: L.B. <[email protected]>
Co-authored-by: Praateek Mahajan <[email protected]>
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.

5 participants