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

Avoid local dir creation, ensure dense array ordering during UMAP save() #823

Merged
merged 8 commits into from
Jan 14, 2025

Conversation

rishic3
Copy link
Collaborator

@rishic3 rishic3 commented Jan 13, 2025

No description provided.

@rishic3
Copy link
Collaborator Author

rishic3 commented Jan 13, 2025

build

@rishic3 rishic3 changed the title Avoid local dir creation, fix dense ordering Avoid local dir creation, ensure dense array ordering during UMAP save() Jan 13, 2025
@rishic3 rishic3 changed the base branch from branch-25.02 to branch-24.12 January 13, 2025 18:27
@rishic3 rishic3 marked this pull request as ready for review January 13, 2025 18:39
@rishic3 rishic3 requested a review from eordentlich January 13, 2025 19:16
pd.DataFrame(
{
"row_id": range(array.shape[0]),
"data": array.tolist(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this better than list(array) ?

Pretty sure we create pandas dfs array columns from np arrays and vice versa elsewhere in our code and would be good to be consistent and/or use best way through out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

While list(array) is more efficient since tolist() does a deep conversion of each row to python lists, Spark will throw an error with list(array) if spark.sql.execution.arrow.pyspark.enabled=false, since pyarrow would no longer handle the numpy -> arrow array conversion.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We pretty much require that to be enabled to get good data transfer from jvm to python workers.

}
),
schema=schema,
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Below and elsewhere in this class is it correct to use overwrite when writing? This might be counter to the overwrite MLWriter api. If that is not invoked, a user would not expect overwrite to be allowed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done, thx

data_df = spark.read.parquet(df_path)
return np.array(data_df.collect(), dtype=np.float32)
data_df = spark.read.parquet(df_path).orderBy("row_id")
return np.array([row.data for row in data_df.collect()], dtype=np.float32)
Copy link
Collaborator

Choose a reason for hiding this comment

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

toPandas might be better here followed by np.array(list(data_pandas_df.data))

@@ -1495,8 +1504,6 @@ def write_dense_array(array: np.ndarray, df_path: str) -> None:
assert model_attributes is not None

data_path = os.path.join(path, "data")
if not os.path.exists(data_path):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be good to have a test that checks for expected files and directories?

@@ -1547,8 +1554,8 @@ def read_sparse_array(
return scipy.sparse.csr_matrix((data, indices, indptr), shape=csr_shape)

def read_dense_array(df_path: str) -> np.ndarray:
data_df = spark.read.parquet(df_path)
return np.array(data_df.collect(), dtype=np.float32)
data_df = spark.read.parquet(df_path).orderBy("row_id")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if there is test for the order, one that would fail if orderby was omitted.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A multi-gpu env (e.g., DGX) where Spark's default parallelism is >1 would have caught it and I should have tested there with the last PR.
Forcing >1 parallelism would require changing CleanSparkSession to allow a new conf to override the default conf - not sure if that's worth it

@eordentlich
Copy link
Collaborator

build

Copy link
Collaborator

@eordentlich eordentlich left a comment

Choose a reason for hiding this comment

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

👍

@rishic3 rishic3 merged commit f9624be into NVIDIA:branch-24.12 Jan 14, 2025
3 checks passed
@rishic3 rishic3 deleted the umap-save-dense branch January 14, 2025 16:31
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.

2 participants