项目文件夹

文件
wehub-resource-sync 5cbd3f29e3
Fuzz / Run fuzz harnesses (${{ github.event_name == 'schedule' && 'nightly' || 'smoke' }}) (push) Has been cancelled
Create Releases / call-mac (push) Has been cancelled
Create Releases / call-linux (push) Has been cancelled
Create Releases / call-sdist (push) Has been cancelled
Create Releases / call-win (push) Has been cancelled
Create Releases / call-pyodide (push) Has been cancelled
Windows_No_Exception_CI / build (x64, 3.10) (push) Has been cancelled
Check URLs / build (push) Has been cancelled
Create Releases / Attest CI build artifacts (push) Has been cancelled
Create Releases / Check for Publish release build to pypi (push) Has been cancelled
Create Releases / Check for Publish preview build to test.pypi-weekly (push) Has been cancelled
Create Releases / Publish preview build to test.pypi-weekly (push) Has been cancelled
Create Releases / Check for Publish release build to test.pypi (rc-candidates) (push) Has been cancelled
Create Releases / Publish release build to test.pypi (push) Has been cancelled
Create Releases / Check for Publish preview build to pypi-weekly (push) Has been cancelled
Create Releases / Publish preview build to pypi-weekly (push) Has been cancelled
Create Releases / Publish release build to pypi (push) Has been cancelled
Create Releases / test source distribution (push) Has been cancelled
clang-tidy / clang-tidy (push) Has been cancelled
Lint / Validate SBOM (push) Has been cancelled
Lint / Enforce style (push) Has been cancelled
CI / Test windows-2022, 3.14, External, debug=0, unity_build=0, onnx_ml=1, autogen=0 (push) Has been cancelled
CI / Test windows-latest, 3.10, Internal, debug=0, unity_build=0, onnx_ml=1, autogen=0 (push) Has been cancelled
CI / Test windows-latest, 3.14, Internal, debug=0, unity_build=0, onnx_ml=1, autogen=0 (push) Has been cancelled
CI / Test windows-latest, 3.14t, Internal, debug=0, unity_build=0, onnx_ml=1, autogen=0 (push) Has been cancelled
CI / Test ubuntu-24.04, 3.14, Internal, debug=1, unity_build=0, onnx_ml=1, autogen=0 (push) Has been cancelled
CI / Test ubuntu-24.04, 3.14, External, debug=0, unity_build=1, onnx_ml=1, autogen=1 (push) Has been cancelled
CI / Test ubuntu-24.04, 3.14, External, debug=0, unity_build=0, onnx_ml=0, autogen=0 (push) Has been cancelled
CI / Test macos-latest, 3.10, Internal, debug=0, unity_build=0, onnx_ml=1, autogen=0 (push) Has been cancelled
CI / Test macos-latest, 3.14, Internal, debug=0, unity_build=0, onnx_ml=1, autogen=0 (push) Has been cancelled
CI / Test macos-latest, 3.14t, Internal, debug=0, unity_build=0, onnx_ml=1, autogen=0 (push) Has been cancelled
CI / Test ubuntu-24.04, 3.14, External, debug=0, unity_build=0, onnx_ml=1, autogen=0 (push) Has been cancelled
CI / Test ubuntu-24.04, 3.10, Internal, debug=0, unity_build=0, onnx_ml=1, autogen=0 (push) Has been cancelled
CI / Test ubuntu-24.04, 3.14, Internal, debug=0, unity_build=0, onnx_ml=1, autogen=0 (push) Has been cancelled
CI / Test ubuntu-24.04, 3.14t, Internal, debug=0, unity_build=0, onnx_ml=1, autogen=0 (push) Has been cancelled
Pixi CI / Install and lint (ubuntu-24.04-arm) (push) Has been cancelled
Pixi CI / Install and lint (windows-2022) (push) Has been cancelled
Pixi CI / Xcode generator build (push) Has been cancelled
Pixi CI / Install and test (macos-latest, default) (push) Has been cancelled
Pixi CI / Install and test (ubuntu-24.04-arm, default) (push) Has been cancelled
Pixi CI / Install and test (ubuntu-latest, default) (push) Has been cancelled
Pixi CI / Install and test (windows-2022, default) (push) Has been cancelled
Pixi CI / Install and test (macos-latest, oldies) (push) Has been cancelled
Pixi CI / Install and test (ubuntu-24.04-arm, oldies) (push) Has been cancelled
Pixi CI / Install and test (ubuntu-latest, oldies) (push) Has been cancelled
Pixi CI / Install and test (windows-2022, oldies) (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (cpp) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Copilot Setup Steps / copilot-setup-steps (push) Has been cancelled
Generate and publish ONNX docs / build (push) Has been cancelled
Generate and publish ONNX docs / deploy (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:41:19 +08:00

156 行
4.7 KiB
Python

# Copyright (c) ONNX Project Contributors
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations
import numpy as np
from onnx.reference.op_run import OpRun
class CommonRNN(OpRun):
def __init__(self, onnx_node, run_params):
OpRun.__init__(self, onnx_node, run_params)
if self.direction in ("forward", "reverse"):
self.num_directions = 1
elif self.direction == "bidirectional":
self.num_directions = 2
else:
raise RuntimeError(f"Unknown direction {self.direction!r}.")
if (
self.activation_alpha is not None
and len(self.activation_alpha) != self.num_directions
):
raise RuntimeError(
f"activation_alpha must have the same size as num_directions={self.num_directions}."
)
if (
self.activation_beta is not None
and len(self.activation_beta) != self.num_directions
):
raise RuntimeError(
f"activation_beta must have the same size as num_directions={self.num_directions}."
)
self.f1 = self.choose_act(
self.activations[0],
(
self.activation_alpha[0]
if self.activation_alpha is not None and len(self.activation_alpha) > 0
else None
),
(
self.activation_beta[0]
if self.activation_beta is not None and len(self.activation_beta) > 0
else None
),
)
if len(self.activations) > 1:
self.f2 = self.choose_act(
self.activations[1],
(
self.activation_alpha[1]
if self.activation_alpha is not None
and len(self.activation_alpha) > 1
else None
),
(
self.activation_beta[1]
if self.activation_beta is not None
and len(self.activation_beta) > 1
else None
),
)
self.n_outputs = len(onnx_node.output)
def choose_act(self, name, alpha, beta):
if name in ("Tanh", "tanh"):
return self._f_tanh
if name in ("Affine", "affine"):
return lambda x: x * alpha + beta
raise RuntimeError(f"Unknown activation function {name!r}.")
def _f_tanh(self, x):
return np.tanh(x)
def _step(self, X, R, B, W, H_0):
h_list = []
H_t = H_0
for x in np.split(X, X.shape[0], axis=0):
H = self.f1(
np.dot(x, np.transpose(W))
+ np.dot(H_t, np.transpose(R))
+ np.add(*np.split(B, 2))
)
h_list.append(H)
H_t = H
concatenated = np.concatenate(h_list)
if self.num_directions == 1:
output = np.expand_dims(concatenated, 1)
return output, h_list[-1]
def _run(
self,
X,
W,
R,
B=None,
sequence_lens=None,
initial_h=None,
activation_alpha=None, # noqa: ARG002
activation_beta=None, # noqa: ARG002
activations=None, # noqa: ARG002
clip=None, # noqa: ARG002
direction=None, # noqa: ARG002
hidden_size=None,
layout=None,
):
# TODO: support overridden attributes.
self.num_directions = W.shape[0]
if self.num_directions == 1:
R = np.squeeze(R, axis=0)
W = np.squeeze(W, axis=0)
if B is not None:
B = np.squeeze(B, axis=0)
if sequence_lens is not None:
sequence_lens = np.squeeze(sequence_lens, axis=0)
if initial_h is not None:
initial_h = np.squeeze(initial_h, axis=0)
hidden_size = R.shape[-1]
batch_size = X.shape[1]
X = X if layout == 0 else np.swapaxes(X, 0, 1)
b = B if B is not None else np.zeros(2 * hidden_size, dtype=X.dtype)
h_0 = (
initial_h
if initial_h is not None
else np.zeros((batch_size, hidden_size), dtype=X.dtype)
)
B = b
H_0 = h_0
else:
raise NotImplementedError(
f"Unsupported value {self.num_directions} for num_directions and operator {self.__class__.__name__!r}."
)
Y, Y_h = self._step(X, R, B, W, H_0)
if layout == 1:
Y = np.transpose(Y, [2, 0, 1, 3])
Y_h = Y[:, :, -1, :]
Y = Y.astype(X.dtype)
return (Y,) if self.n_outputs == 1 else (Y, Y_h)
class RNN_7(CommonRNN):
pass
class RNN_14(CommonRNN):
pass