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

[load_from_hf_hub] Add dataset_length, set_index #339

Merged
merged 4 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions components/load_from_hf_hub/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,26 @@ def load(self) -> dd.DataFrame:
)

# 3) Rename columns
logger.info("Renaming columns...")
dask_df = dask_df.rename(columns=self.column_name_mapping)

# 4) Optional: only return specific amount of rows
if self.n_rows_to_load:
dask_df = dask_df.head(self.n_rows_to_load)
dask_df = dd.from_pandas(dask_df, npartitions=1)
if self.n_rows_to_load is not None:
partitions_length = 0
for npartitions, partition in enumerate(dask_df.partitions):
if partitions_length >= self.n_rows_to_load:
logger.info(f"""Required number of partitions to load\n
{self.n_rows_to_load} is {npartitions}""")
break
partitions_length += len(partition)
dask_df = dask_df.head(self.n_rows_to_load, npartitions=npartitions)
dask_df = dd.from_pandas(dask_df, npartitions=npartitions)

# Set monotonically increasing index
logger.info("Setting the index...")
dask_df["id"] = 1
dask_df["id"] = dask_df.id.cumsum()
dask_df = dask_df.set_index("id", sort=True)

return dask_df

Expand Down
13 changes: 1 addition & 12 deletions examples/pipelines/datacomp/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@

from pipeline_configs import PipelineConfigs

from fondant.compiler import DockerCompiler
from fondant.pipeline import ComponentOp, Pipeline, Client

logger = logging.getLogger(__name__)

# Initialize pipeline and client
pipeline = Pipeline(
pipeline_name="Datacomp filtering pipeline",
pipeline_name="datacomp-filtering",
pipeline_description="A pipeline for filtering the Datacomp dataset",
# base_path=PipelineConfigs.BASE_PATH,
base_path="/Users/nielsrogge/Documents/fondant_artifacts_datacomp",
Expand Down Expand Up @@ -69,13 +68,3 @@
pipeline.add_op(filter_complexity_op, dependencies=filter_image_resolution_op)
pipeline.add_op(cluster_image_embeddings_op, dependencies=filter_complexity_op)
# TODO add more ops

# compile
if __name__ == "__main__":
compiler = DockerCompiler()
# mount the gcloud credentials to the container
extra_volumes = [
"$HOME/.config/gcloud/application_default_credentials.json:/root/.config/gcloud/application_default_credentials.json:ro"
]
compiler.compile(pipeline=pipeline, extra_volumes=extra_volumes)
logger.info("Run `docker compose up` to run the pipeline.")