Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
wejoncy committed Nov 9, 2024
1 parent ddd4b1e commit 2b23670
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Status SoftmaxOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder,
NodeAttrHelper helper(node);
int32_t axis_default_value = (node.SinceVersion() < 13) ? 1 : -1;
const auto axis = helper.Get("axis", axis_default_value);
auto axis_nonnegative = HandleNegativeAxis(axis, data_shape.size());
auto axis_nonnegative = HandleNegativeAxis(axis, data_shape.size());

#if defined(COREML_ENABLE_MLPROGRAM)
// CoreML's softmax match onnx's softmax behavior since opset 13.
Expand All @@ -47,15 +47,15 @@ Status SoftmaxOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder,
const int32_t elem_type = static_cast<int32_t>(input_dtype);

std::string_view layer_input_name_x = node.InputDefs()[0]->Name();
const bool need_reshape = node.SinceVersion() < 13 && axis_nonnegative != static_cast<int64_t>(data_shape.size()) - 1;
const bool need_reshape = node.SinceVersion() < 13 && axis_nonnegative != static_cast<int64_t>(data_shape.size()) - 1;
std::vector<int64_t> target_shape;
if (need_reshape) {
// reshape to 2D to simulate onnx softmax behavior
auto reshape1 = model_builder.CreateOperation(node, "reshape", "pre");
TensorShape input_shape(data_shape);
target_shape.push_back(input_shape.SizeToDimension(axis_nonnegative ));
target_shape.push_back(input_shape.SizeFromDimension(axis_nonnegative ));
axis_nonnegative = 1;
target_shape.push_back(input_shape.SizeToDimension(axis_nonnegative));
target_shape.push_back(input_shape.SizeFromDimension(axis_nonnegative));
axis_nonnegative = 1;
AddOperationInput(*reshape1, "x", layer_input_name_x);
AddOperationInput(*reshape1, "shape", model_builder.AddConstant(reshape1->type(), "shape1", target_shape));
layer_input_name_x = model_builder.GetUniqueName(node, "ln_reshape1_");
Expand All @@ -64,7 +64,7 @@ Status SoftmaxOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder,
}
std::unique_ptr<Operation> op = model_builder.CreateOperation(node, "softmax");
AddOperationInput(*op, "x", layer_input_name_x);
AddOperationInput(*op, "axis", model_builder.AddScalarConstant(op->type(), "axis", axis_nonnegative ));
AddOperationInput(*op, "axis", model_builder.AddScalarConstant(op->type(), "axis", axis_nonnegative));
if (!need_reshape) {
AddOperationOutput(*op, *node.OutputDefs()[0]);
model_builder.AddOperation(std::move(op));
Expand All @@ -91,8 +91,8 @@ Status SoftmaxOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder,
// note: if opsets < 13, onnx Softmax coerces the input shape to be 2D based on axis.
// we need to manually reshape to 2D and apply SoftmaxND to axis -1 to achieve equivalent results for CoreML.
TensorShape input_shape(data_shape);
const auto size_to_dimension = input_shape.SizeToDimension(axis_nonnegative );
const auto size_from_dimension = input_shape.SizeFromDimension(axis_nonnegative );
const auto size_to_dimension = input_shape.SizeToDimension(axis_nonnegative);
const auto size_from_dimension = input_shape.SizeFromDimension(axis_nonnegative);

TensorShapeVector target_shape;
target_shape.push_back(size_to_dimension);
Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/core/providers/cpu/tensor/unsqueeze.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class UnsqueezeBase {
};

Status PrepareCompute(OpKernelContext* context, Prepare& p) const;
static TensorShapeVector ComputeOutputShape(
static TensorShapeVector ComputeOutputShape(
const TensorShape& input_shape,
const TensorShapeVector& axes) {
TensorShapeVector output_shape;
Expand Down

0 comments on commit 2b23670

Please sign in to comment.