File: test_cleanup_passes.cpp

package info (click to toggle)
pytorch 1.13.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 139,252 kB
  • sloc: cpp: 1,100,274; python: 706,454; ansic: 83,052; asm: 7,618; java: 3,273; sh: 2,841; javascript: 612; makefile: 323; xml: 269; ruby: 185; yacc: 144; objc: 68; lex: 44
file content (49 lines) | stat: -rw-r--r-- 1,455 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <gtest/gtest.h>

#include <torch/csrc/jit/frontend/ir_emitter.h>
#include <torch/csrc/jit/ir/ir.h>
#include <torch/csrc/jit/ir/irparser.h>
#include <torch/csrc/jit/testing/file_check.h>

namespace torch {
namespace jit {

TEST(CleanupPassTest, Basic) {
  // Tests stability of clean up passes when dealing with constant pooling
  // and constant propagation.
  auto graph = std::make_shared<Graph>();
  parseIR(
      R"IR(
graph(%cond.1 : Tensor,
      %suffix.1 : str):
  %3 : bool = aten::Bool(%cond.1) # o.py:6:7
  %25 : str = prim::If(%3) # o.py:6:4
    block0():
      %a.1 : str = prim::Constant[value="same string"]()
      %b.1 : str = prim::Constant[value=" with a twist"]()
      %7 : str = aten::add(%a.1, %b.1)
      %11 : str = aten::add(%7, %suffix.1) # o.py:10:15
      -> (%11)
    block1():
      %c.1 : str = prim::Constant[value="same string"]()
      %d.1 : str = prim::Constant[value=" with a twist"]()
      %12 : str = aten::add(%c.1, %d.1)
      -> (%12)
  return (%25)
  )IR",
      &*graph);
  runCleanupPasses(graph);
  testing::FileCheck()
      .check_count(
          "prim::Constant[value=\"same string with a twist\"]",
          1,
          /*exactly=*/true)
      ->run(*graph);

  auto graph_after_pass_once = graph->toString();
  runCleanupPasses(graph);
  auto graph_after_pass_twice = graph->toString();
  ASSERT_EQ(graph_after_pass_once, graph_after_pass_twice);
}
} // namespace jit
} // namespace torch