-
Notifications
You must be signed in to change notification settings - Fork 179
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
Refactor incremental spmd algos #2248
Draft
ethanglaser
wants to merge
1
commit into
uxlfoundation:main
Choose a base branch
from
ethanglaser:dev/eglaser-online-spmd-refactor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,84 +14,14 @@ | |
# limitations under the License. | ||
# ============================================================================== | ||
|
||
import numpy as np | ||
|
||
from daal4py.sklearn._utils import get_dtype | ||
|
||
from ...common.hyperparameters import get_hyperparameters | ||
from ...datatypes import to_table | ||
from ...linear_model import ( | ||
IncrementalLinearRegression as base_IncrementalLinearRegression, | ||
) | ||
from ...utils import _check_X_y, _num_features | ||
from ..._device_offload import support_input_format | ||
from .._base import BaseEstimatorSPMD | ||
|
||
|
||
class IncrementalLinearRegression(BaseEstimatorSPMD, base_IncrementalLinearRegression): | ||
""" | ||
Distributed incremental Linear Regression oneDAL implementation. | ||
|
||
API is the same as for `onedal.linear_model.IncrementalLinearRegression`. | ||
""" | ||
|
||
def _reset(self): | ||
self._partial_result = super(base_IncrementalLinearRegression, self)._get_backend( | ||
"linear_model", "regression", "partial_train_result" | ||
) | ||
|
||
@support_input_format() | ||
def partial_fit(self, X, y, queue=None): | ||
""" | ||
Computes partial data for linear regression | ||
from data batch X and saves it to `_partial_result`. | ||
Parameters | ||
---------- | ||
X : array-like of shape (n_samples, n_features) | ||
Training data batch, where `n_samples` is the number of samples | ||
in the batch, and `n_features` is the number of features. | ||
|
||
y: array-like of shape (n_samples,) or (n_samples, n_targets) in | ||
case of multiple targets | ||
Responses for training data. | ||
|
||
queue : dpctl.SyclQueue | ||
If not None, use this queue for computations. | ||
Returns | ||
------- | ||
self : object | ||
Returns the instance itself. | ||
""" | ||
module = super(base_IncrementalLinearRegression, self)._get_backend( | ||
"linear_model", "regression" | ||
) | ||
|
||
self._queue = queue | ||
policy = super(base_IncrementalLinearRegression, self)._get_policy(queue, X) | ||
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 think this was done for the wonkiness of the get_backend + when the spmd policy is used and when the dpc policy is used. |
||
|
||
X, y = _check_X_y( | ||
X, y, dtype=[np.float64, np.float32], accept_2d_y=True, force_all_finite=False | ||
) | ||
|
||
X_table, y_table = to_table(X, y, queue=queue) | ||
|
||
if not hasattr(self, "_dtype"): | ||
self._dtype = X_table.dtype | ||
self._params = self._get_onedal_params(self._dtype) | ||
|
||
y = np.asarray(y, dtype=self._dtype) | ||
|
||
self.n_features_in_ = _num_features(X, fallback_1d=True) | ||
|
||
hparams = get_hyperparameters("linear_regression", "train") | ||
if hparams is not None and not hparams.is_default: | ||
self._partial_result = module.partial_train( | ||
policy, | ||
self._params, | ||
hparams.backend, | ||
self._partial_result, | ||
X_table, | ||
y_table, | ||
) | ||
else: | ||
self._partial_result = module.partial_train( | ||
policy, self._params, self._partial_result, X_table, y_table | ||
) | ||
return super().partial_fit(X, y, queue=queue) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Zero copy support will move away from support input format, as we will fully generate #2206 #2207 and #2189