Skip to content

Commit

Permalink
fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
lsy323 committed Nov 13, 2023
1 parent 23ee18c commit 48f931b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion torch_xla/csrc/elementwise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace torch_xla {
namespace {

static const bool experimental_unbounded_dynamism =
runtime::sys_util::GetEnvBool("EXPERIMENTAL_XLA_UNBOUNDED_DYNAMISM", false);
runtime::sys_util::GetEnvBool("EXPERIMENTAL_XLA_UNBOUNDED_DYNAMISM", false);

xla::XlaOp Between(xla::XlaOp input, const at::Scalar& min_val,
const at::Scalar& max_val) {
Expand Down
9 changes: 4 additions & 5 deletions torch_xla/csrc/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
namespace torch_xla {
namespace {


static const bool experimental_unbounded_dynamism =
runtime::sys_util::GetEnvBool("EXPERIMENTAL_XLA_UNBOUNDED_DYNAMISM", false);
runtime::sys_util::GetEnvBool("EXPERIMENTAL_XLA_UNBOUNDED_DYNAMISM", false);

// TODO(lsy323): Get reserved number for unbounded dim after it's added in XLA.
static constexpr int64_t kUnboundedSize = std::numeric_limits<int64_t>::min();
Expand Down Expand Up @@ -334,7 +333,7 @@ xla::XlaOp XlaHelpers::DynamicReshapeAs(xla::XlaOp input,

bool XlaHelpers::IsUnboundedDynamic(const xla::Shape& shape) {
XLA_CHECK(experimental_unbounded_dynamism)
<< "EXPERIMENTAL_XLA_UNBOUNDED_DYNAMISM needs to be turned on.";
<< "EXPERIMENTAL_XLA_UNBOUNDED_DYNAMISM needs to be turned on.";
const absl::Span<const int64_t> dims = shape.dimensions();
return std::any_of(dims.begin(), dims.end(),
[](int64_t size) { return size == kUnboundedSize; });
Expand All @@ -344,7 +343,7 @@ xla::XlaOp XlaHelpers::DynamicUnboundedReshape(
xla::XlaOp input, xla::XlaOp aux_input,
absl::Span<const int64_t> output_sizes) {
XLA_CHECK(experimental_unbounded_dynamism)
<< "EXPERIMENTAL_XLA_UNBOUNDED_DYNAMISM needs to be turned on.";
<< "EXPERIMENTAL_XLA_UNBOUNDED_DYNAMISM needs to be turned on.";
const xla::Shape& aux_input_shape = ShapeHelper::ShapeOfXlaOp(aux_input);
XLA_CHECK(output_sizes.size() == aux_input_shape.rank())
<< "XlaHelpers::DynamicUnboundedReshape constrainled failed!";
Expand Down Expand Up @@ -387,7 +386,7 @@ xla::XlaOp XlaHelpers::DynamicUnboundedBroadcast(
xla::XlaOp input, xla::XlaOp aux_input,
absl::Span<const int64_t> aux_input_dimensions) {
XLA_CHECK(experimental_unbounded_dynamism)
<< "EXPERIMENTAL_XLA_UNBOUNDED_DYNAMISM needs to be turned on.";
<< "EXPERIMENTAL_XLA_UNBOUNDED_DYNAMISM needs to be turned on.";
const xla::Shape& input_shape = ShapeHelper::ShapeOfXlaOp(input);
const xla::Shape& aux_input_shape = ShapeHelper::ShapeOfXlaOp(aux_input);
bool all_static = true;
Expand Down
8 changes: 4 additions & 4 deletions torch_xla/csrc/ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ class XlaNode : public torch::lazy::Node {

std::string ToString() const override;

void MarkDynamicDimension(uint32_t dim) {
dynamic_dims_.insert(dim);
}
void MarkDynamicDimension(uint32_t dim) { dynamic_dims_.insert(dim); }

const std::unordered_set<uint32_t>& dynamic_dims() const { return dynamic_dims_; }
const std::unordered_set<uint32_t>& dynamic_dims() const {
return dynamic_dims_;
}

protected:
std::unordered_set<uint32_t> dynamic_dims_;
Expand Down
3 changes: 2 additions & 1 deletion torch_xla/csrc/lowering_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ xla::XlaOp LoweringContext::GetParameter(
parameters_.push_back(data);
} else {
XLA_CHECK(unbounded_dynamic_dims.empty())
<< "The unbounded dynamic dims can only be set when Parameter is created.";
<< "The unbounded dynamic dims can only be set when Parameter is "
"created.";
}
parameter_sequence_.push_back(it->second.index);
return it->second.param;
Expand Down
5 changes: 3 additions & 2 deletions torch_xla/csrc/lowering_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ class LoweringContext : public torch::lazy::LoweringContext {
// If a parameter associated with data has already been declared, it will be
// returned. Otherwise a new one will be created, associated with the tensor
// held in data.
xla::XlaOp GetParameter(const std::shared_ptr<torch::lazy::BackendData>& data,
const std::unordered_set<uint32_t>& dynamic_dims = {});
xla::XlaOp GetParameter(
const std::shared_ptr<torch::lazy::BackendData>& data,
const std::unordered_set<uint32_t>& dynamic_dims = {});

// Retrieves the vector holding all the tensors associated with the parameter
// instructions which have been created.
Expand Down
11 changes: 6 additions & 5 deletions torch_xla/csrc/reduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct SummationResult {
};

static const bool experimental_unbounded_dynamism =
runtime::sys_util::GetEnvBool("EXPERIMENTAL_XLA_UNBOUNDED_DYNAMISM", false);
runtime::sys_util::GetEnvBool("EXPERIMENTAL_XLA_UNBOUNDED_DYNAMISM", false);

ReductionInfo GetReductionInfo(xla::XlaOp input, const xla::Shape& shape,
absl::Span<const int64_t> dimensions,
Expand Down Expand Up @@ -121,12 +121,13 @@ SummationResult CreateSummation(xla::XlaOp input,
}
if (keep_reduced_dimensions) {
if (experimental_unbounded_dynamism) {
// TODO(lsy323): Use XLA DynamicReshape once unbounded dynamism support is added.
// TODO(lsy323): Use XLA DynamicReshape once unbounded dynamism support is
// added.
result.result = XlaHelpers::DynamicUnboundedReshape(
result.result, input, result.rinfo.new_dimensions);
result.result, input, result.rinfo.new_dimensions);
} else {
result.result =
XlaHelpers::DynamicReshape(result.result, result.rinfo.new_dimensions);
result.result = XlaHelpers::DynamicReshape(result.result,
result.rinfo.new_dimensions);
}
}
return result;
Expand Down

0 comments on commit 48f931b

Please sign in to comment.