-
Notifications
You must be signed in to change notification settings - Fork 30
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
Changes from 2 commits
ed0360d
ba6220a
297c486
2a6e886
3cf20c5
7b3048c
3bf1f51
c0e8b5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -790,8 +790,9 @@ class UMAP(UMAPClass, _CumlEstimatorSupervised, _UMAPCumlParams): | |
|
||
sample_fraction : float (optional, default=1.0) | ||
The fraction of the dataset to be used for fitting the model. Since fitting is done on a single node, very large | ||
datasets must be subsampled to fit within the node's memory and execute in a reasonable time. Smaller fractions | ||
will result in faster training, but may result in sub-optimal embeddings. | ||
datasets must be subsampled to fit within the node's memory. Smaller fractions will result in faster training, but | ||
may decrease embedding quality. Note: this is not guaranteed to provide exactly the fraction specified of the total | ||
count of the given DataFrame. | ||
|
||
featuresCol: str or List[str] | ||
The feature column names, spark-rapids-ml supports vector, array and columnar as the input.\n | ||
|
@@ -1473,11 +1474,19 @@ def write_sparse_array(array: scipy.sparse.spmatrix, df_dir: str) -> None: | |
def write_dense_array(array: np.ndarray, df_path: str) -> None: | ||
schema = StructType( | ||
[ | ||
StructField(f"_{i}", FloatType(), False) | ||
for i in range(1, array.shape[1] + 1) | ||
StructField("row_id", LongType(), False), | ||
StructField("data", ArrayType(FloatType(), False), False), | ||
] | ||
) | ||
data_df = spark.createDataFrame(pd.DataFrame(array), schema=schema) | ||
data_df = spark.createDataFrame( | ||
pd.DataFrame( | ||
{ | ||
"row_id": range(array.shape[0]), | ||
"data": array.tolist(), | ||
} | ||
), | ||
schema=schema, | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, thx |
||
data_df.write.parquet(df_path, mode="overwrite") | ||
|
||
DefaultParamsWriter.saveMetadata( | ||
|
@@ -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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
os.makedirs(data_path) | ||
|
||
for key in ["embedding_", "raw_data_"]: | ||
array = model_attributes[key] | ||
|
@@ -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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
return np.array([row.data for row in data_df.collect()], dtype=np.float32) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)) |
||
|
||
metadata = DefaultParamsReader.loadMetadata(path, self.sc) | ||
data_path = os.path.join(path, "data") | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.