Skip to content

Conversation

@steventk-g
Copy link
Collaborator

Generated LazyIr.h:

class Tanh : public XlaNode {
 public:
  static torch::lazy::OpKind ClassOpKind() {
    return torch::lazy::OpKind(at::aten::tanh);
  }

  Tanh(const torch::lazy::Value& self, std::vector<torch::lazy::Shape>&& shapes)
      : XlaNode(torch::lazy::OpKind(at::aten::tanh),
              {self}, std::move(shapes),
              [&]() { return TanhOutputShape(self); },
              /* num_outputs */ 1,
              torch::lazy::MHash())
  {
    
  }

  std::string ToString() const override {
    std::stringstream ss;
    ss << XlaNode::ToString();
    
    return ss.str();
  }

  

  bool CanBeReused(const torch::lazy::Value& self) const {
    return false;
    }

  torch_xla::XlaOpVector Lower(LoweringContext* loctx) const override;

  
  

};

Generated XLANativeFunctions.cpp:

    at::Tensor XLANativeFunctions::tanh(const at::Tensor & self) {
        
        XLA_FN_COUNTER("xla::");
        auto common_device = torch_xla::bridge::GetXlaDevice(self);
        TORCH_INTERNAL_ASSERT(common_device);
        
        torch_xla::XLATensorPtr lazy_self = torch_xla::bridge::GetXlaTensorOrCreateForWrappedNumber(self, *common_device);
        torch::lazy::NodePtr node = torch::lazy::ReuseNode<Tanh>(lazy_self->GetIrValue());
        if (!node) {
                    auto self_meta = to_meta(self);
        auto out_meta = at::meta::tanh(self_meta);
        
std::vector<torch::lazy::Shape> shapes{torch::lazy::Shape(out_meta.scalar_type(), out_meta.sizes().vec())};
            TORCH_INTERNAL_ASSERT(shapes.size() == 1);
            if(torch::lazy::symbolicShapeEnabled()){
                std::vector<torch::jit::IValue> inputs = { self };
                const char* schema_str = "aten::tanh(Tensor self) -> Tensor";
                applySymbolicShapesOnLT(schema_str, inputs, shapes);
            }
        
            node = torch::lazy::MakeNode<Tanh>(lazy_self->GetIrValue(), std::move(shapes));
            CacheNode(node);
        }
        
        auto result = torch_xla::bridge::AtenFromXlaTensor(
                torch_xla::XLATensor::Create(std::move(node), *common_device));
        return result;
    };

@steventk-g steventk-g requested review from JackCaoG and wonjoo-wj July 19, 2022 00:13
@steventk-g steventk-g force-pushed the steventk-first-codegen branch from 1f4b697 to 68d8b0f Compare July 19, 2022 00:18
@steventk-g steventk-g force-pushed the steventk-first-codegen branch from 98d64ad to 966ff1a Compare July 19, 2022 00:35
Copy link
Collaborator

@wonjoo-wj wonjoo-wj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks! 👍

@wonjoo-wj
Copy link
Collaborator

@steventk-g, also curious what was the cause of the problem you mentioned before regarding the Node being not found?

@JackCaoG JackCaoG merged commit 1262dd4 into master Jul 19, 2022
@JackCaoG JackCaoG deleted the steventk-first-codegen branch July 19, 2022 17:00
@steventk-g
Copy link
Collaborator Author

steventk-g commented Jul 19, 2022

@steventk-g, also curious what was the cause of the problem you mentioned before regarding the Node being not found?

I hadn't removed the Tanh definition from ops.h, so it was interfering with the template somehow. It wasn't clear from the compiler error, though. Once I removed it everything built fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants