Skip to content

Commit d7a61f0

Browse files
authored
Renamed op type members. (#2469)
Renamed op type members from attr to legacy_attrs_ and from named_attrs to named_attrs_.
1 parent a076423 commit d7a61f0

24 files changed

+154
-146
lines changed

forge/csrc/autograd/autograd.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,13 @@ void autograd_engine::create_backward_graph(const grad_map &requires_grad_map)
360360
{
361361
if (tm.type() == ops::OpType::Broadcast)
362362
{
363-
TT_ASSERT(tm.attr.size() <= 3);
363+
TT_ASSERT(tm.legacy_attrs_.size() <= 3);
364364
log_debug(
365365
tt::LogAutograd,
366366
"Edge has broadcast: dim={} size={}",
367-
std::get<int>(tm.attr[0]),
368-
std::get<int>(tm.attr[1]));
369-
int dim = std::get<int>(tm.attr[0]);
367+
std::get<int>(tm.legacy_attrs_[0]),
368+
std::get<int>(tm.legacy_attrs_[1]));
369+
int dim = std::get<int>(tm.legacy_attrs_[0]);
370370

371371
NodeContext src = last_out;
372372
last_out = create_backward_op(

forge/csrc/graph_lib/node_types.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ void EdgeAttributes::clear_broadcast_dims()
335335
void EdgeAttributes::remove_broadcast_dim(int dim)
336336
{
337337
auto filter = [=](const OpType &o)
338-
{ return o.type() == ops::OpType::Broadcast && std::get<int>(o.attr[0]) == dim; };
338+
{ return o.type() == ops::OpType::Broadcast && std::get<int>(o.legacy_attrs_[0]) == dim; };
339339
tms.erase(std::remove_if(tms.begin(), tms.end(), filter), tms.end());
340340
}
341341

forge/csrc/graph_lib/node_types.hpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -374,15 +374,15 @@ struct OpType
374374
using Attrs = ForgeOpAttrs;
375375

376376
std::string op_;
377-
std::vector<Attr> attr; // legacy path
378-
Attrs named_attrs; // new path
377+
std::vector<Attr> legacy_attrs_; // legacy path
378+
Attrs named_attrs_; // new path
379379

380380
private:
381381
ops::Op new_op_;
382382

383383
public:
384384
OpType(std::string const &op, std::vector<Attr> const &attr = {}, Attrs named_attrs = {}) :
385-
op_(op), attr(attr), named_attrs(std::move(named_attrs)), new_op_(*this)
385+
op_(op), legacy_attrs_(attr), named_attrs_(std::move(named_attrs)), new_op_(*this)
386386
{
387387
}
388388

@@ -391,14 +391,14 @@ struct OpType
391391

392392
bool operator==(const OpType &other) const
393393
{
394-
return *this == other.type() and attr == other.attr and named_attrs == other.named_attrs;
394+
return *this == other.type() and legacy_attrs_ == other.legacy_attrs_ and named_attrs_ == other.named_attrs_;
395395
}
396396
bool operator!=(const OpType &other) const { return !(*this == other); }
397397

398398
ops::OpType type() const { return new_op_.type(); }
399399
ops::Op const &new_op() const { return new_op_; }
400-
Attr const &get_attr(std::string const &name) const { return named_attrs.at(name); }
401-
Attr &get_attr(std::string const &name) { return named_attrs.at(name); }
400+
Attr const &get_attr(std::string const &name) const { return named_attrs_.at(name); }
401+
Attr &get_attr(std::string const &name) { return named_attrs_.at(name); }
402402
template <typename T>
403403
T const &get_attr_as(std::string const &name) const
404404
{
@@ -412,7 +412,7 @@ struct OpType
412412

413413
void set_attr(std::string const &name, Attr attr)
414414
{
415-
named_attrs[name] = attr;
415+
named_attrs_[name] = attr;
416416
new_op_.set_attr(name, std::move(attr));
417417
}
418418

@@ -421,30 +421,30 @@ struct OpType
421421
std::string as_string() const
422422
{
423423
std::string ret = op_;
424-
if (attr.size() > 0)
424+
if (legacy_attrs_.size() > 0)
425425
{
426426
ret += "(";
427-
for (unsigned int i = 0; i < attr.size(); i++)
427+
for (unsigned int i = 0; i < legacy_attrs_.size(); i++)
428428
{
429-
if (std::holds_alternative<bool>(attr[i]))
429+
if (std::holds_alternative<bool>(legacy_attrs_[i]))
430430
{
431-
ret += std::to_string(std::get<bool>(attr[i])) + ",";
431+
ret += std::to_string(std::get<bool>(legacy_attrs_[i])) + ",";
432432
}
433-
else if (std::holds_alternative<int>(attr[i]))
433+
else if (std::holds_alternative<int>(legacy_attrs_[i]))
434434
{
435-
ret += std::to_string(std::get<int>(attr[i])) + ",";
435+
ret += std::to_string(std::get<int>(legacy_attrs_[i])) + ",";
436436
}
437-
else if (std::holds_alternative<float>(attr[i]))
437+
else if (std::holds_alternative<float>(legacy_attrs_[i]))
438438
{
439-
ret += std::to_string(std::get<float>(attr[i])) + ",";
439+
ret += std::to_string(std::get<float>(legacy_attrs_[i])) + ",";
440440
}
441-
else if (std::holds_alternative<std::string>(attr[i]))
441+
else if (std::holds_alternative<std::string>(legacy_attrs_[i]))
442442
{
443-
ret += std::get<std::string>(attr[i]) + ",";
443+
ret += std::get<std::string>(legacy_attrs_[i]) + ",";
444444
}
445-
else if (std::holds_alternative<std::vector<int>>(attr[i]))
445+
else if (std::holds_alternative<std::vector<int>>(legacy_attrs_[i]))
446446
{
447-
auto attr_val = std::get<std::vector<int>>(attr[i]);
447+
auto attr_val = std::get<std::vector<int>>(legacy_attrs_[i]);
448448
size_t num_items = attr_val.size();
449449

450450
ret += "[";
@@ -466,13 +466,13 @@ struct OpType
466466
ret += ")";
467467
}
468468

469-
if (named_attrs.size() > 0)
469+
if (named_attrs_.size() > 0)
470470
{
471471
using tt::operator<<;
472472
std::stringstream ss;
473473
bool first = true;
474474
ss << "{";
475-
for (auto const &[name, value] : named_attrs)
475+
for (auto const &[name, value] : named_attrs_)
476476
{
477477
if (not first)
478478
ss << ", ";
@@ -549,8 +549,8 @@ class OpNode : public TaggedNode
549549
OpType const *op_type_ptr() const { return &op_type_; }
550550
IRLevel get_ir_level() const { return IRLevel::IR_TT_FORGE; }
551551
const std::string &op_name() const { return op_type_.name(); }
552-
const std::vector<OpType::Attr> &op_attrs() const { return op_type_.attr; }
553-
const OpType::Attrs &named_attrs() { return op_type_.named_attrs; }
552+
const std::vector<OpType::Attr> &op_legacy_attrs() const { return op_type_.legacy_attrs_; }
553+
const OpType::Attrs &named_attrs() { return op_type_.named_attrs_; }
554554
const OpType::Attr &op_attr(std::string const &name) const { return op_type_.get_attr(name); }
555555
template <typename T>
556556
const T &op_attr_as(std::string const &name) const

forge/csrc/graph_lib/python_bindings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,8 @@ void GraphModule(py::module &m_graph)
293293
py::arg("attr") = std::vector<tt::graphlib::OpType::Attr>{},
294294
py::arg("named_attrs") = tt::graphlib::OpType::Attrs{})
295295
.def_readonly("op", &tt::graphlib::OpType::op_)
296-
.def_readonly("attr", &tt::graphlib::OpType::attr)
297-
.def_readonly("named_attrs", &tt::graphlib::OpType::named_attrs)
296+
.def_readonly("attr", &tt::graphlib::OpType::legacy_attrs_)
297+
.def_readonly("named_attrs", &tt::graphlib::OpType::named_attrs_)
298298
.def("eval", &tt::graphlib::OpType::eval)
299299
.def("shape", &tt::graphlib::OpType::shape)
300300
.def(

forge/csrc/graph_lib/utils.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,7 @@ void convert_implicit_to_explicit_bcasts(Graph *graph, Edge edge)
11481148
if (op_type.type() == ops::OpType::Broadcast)
11491149
{
11501150
constexpr bool explicit_bcast = true;
1151-
std::get<bool>(op_type.attr[2]) = explicit_bcast;
1151+
std::get<bool>(op_type.legacy_attrs_[2]) = explicit_bcast;
11521152
}
11531153
}
11541154
}
@@ -1208,9 +1208,9 @@ bool swap_broadcast_dims(graphlib::Graph *graph, graphlib::Edge edge, int old_di
12081208
{
12091209
if (op_type.type() == ops::OpType::Broadcast)
12101210
{
1211-
int dim = std::get<int>(op_type.attr[0]);
1212-
int size = std::get<int>(op_type.attr[1]);
1213-
bool explicit_bcast = std::get<bool>(op_type.attr[2]);
1211+
int dim = std::get<int>(op_type.legacy_attrs_[0]);
1212+
int size = std::get<int>(op_type.legacy_attrs_[1]);
1213+
bool explicit_bcast = std::get<bool>(op_type.legacy_attrs_[2]);
12141214
if (dim == old_dim)
12151215
{
12161216
graphlib::OpType updated_bcast("broadcast", {new_dim, size, explicit_bcast});
@@ -1310,8 +1310,8 @@ void handle_change_rank(graphlib::Graph *graph, graphlib::Edge edge)
13101310
{
13111311
if (op_type.type() == ops::OpType::Broadcast)
13121312
{
1313-
if (std::get<int>(op_type.attr[0]) >= 0)
1314-
std::get<int>(op_type.attr[0]) += diff;
1313+
if (std::get<int>(op_type.legacy_attrs_[0]) >= 0)
1314+
std::get<int>(op_type.legacy_attrs_[0]) += diff;
13151315
}
13161316
}
13171317
graph->get_edge_attributes(edge)->set_tms(tms);
@@ -1846,9 +1846,9 @@ bool is_consteval_capable_input_no_operand_forks(Graph *graph, InputNode *input)
18461846
if (not std::all_of(user_ops.begin(), user_ops.end(), [op_name](OpNode *n) { return n->op_name() == op_name; }))
18471847
return false;
18481848

1849-
auto attrs = user_ops[0]->op_attrs();
1849+
auto attrs = user_ops[0]->op_legacy_attrs();
18501850
for (OpNode *op : user_ops)
1851-
if (attrs != op->op_attrs())
1851+
if (attrs != op->op_legacy_attrs())
18521852
return false;
18531853

18541854
return true;

forge/csrc/ops/op.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ static NewToOldOpType new_to_old_op_type_mapper;
300300
static OldToNewOpType old_to_new_op_type_mapper;
301301

302302
Op::Op(const graphlib::OpType &old_op_type) :
303-
type_(old_to_new_op_type_mapper[old_op_type.op_]), attrs_(old_op_type.named_attrs)
303+
type_(old_to_new_op_type_mapper[old_op_type.op_]), attrs_(old_op_type.named_attrs_)
304304
{
305305
}
306306

0 commit comments

Comments
 (0)