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

fix roll on CPU #1840

Merged
merged 1 commit into from
Nov 23, 2024
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
4 changes: 2 additions & 2 deletions mindnlp/accelerate/big_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ def register_empty_parameter(module, name, param):
if param is not None:
kwargs = module._parameters[name].__dict__
kwargs["requires_grad"] = param.requires_grad
module._parameters[name].assign_value(Tensor_(shape=(), dtype=module._parameters[name].dtype))
module._parameters[name].assign_value(Tensor_(shape=module._parameters[name].shape, dtype=module._parameters[name].dtype))
module._parameters[name].meta = True

def register_empty_buffer(module, name, buffer, persistent=True):
old_register_buffer(module, name, buffer, persistent=persistent)
if buffer is not None:
module._buffers[name].assign_value(Tensor_(shape=(), dtype=module._buffers[name].dtype))
module._buffers[name].assign_value(Tensor_(shape=module._parameters[name].shape, dtype=module._buffers[name].dtype))
module._buffers[name].meta = True

try:
Expand Down
3 changes: 3 additions & 0 deletions mindnlp/core/ops/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,9 +619,12 @@ def repeat_interleave(input, repeats, dim=None):
return input.repeat(repeats, dim)

# roll
DEVICE_TARGET = mindspore.get_context('device_target')
def roll(input, shifts, dims=None):
if use_pyboost():
return mindspore.mint.roll(input, shifts, dims)
if DEVICE_TARGET == 'CPU':
return mindspore.numpy.roll(input, shifts, dims)
return ops.roll(input, shifts, dims)

# searchsorted
Expand Down
4 changes: 3 additions & 1 deletion mindnlp/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy as np
import mindspore
from mindspore import Tensor
from mindnlp.configs import GENERATOR_SEED

def infer_value_for_BroadcastTo(x, shape):
"""Infer value for BroadcastTo op."""
Expand All @@ -18,4 +19,5 @@ def none_in_tuple_or_list(x):
np_data = np.broadcast_to(x.asnumpy(), shape)
return Tensor(np_data)

mindspore.ops.operations.manually_defined.ops_def.infer_value_for_BroadcastTo = infer_value_for_BroadcastTo
if GENERATOR_SEED:
mindspore.ops.operations.manually_defined.ops_def.infer_value_for_BroadcastTo = infer_value_for_BroadcastTo
Loading