From 94bbb6cdaf17f4691e6e2750e5ad4cf39044f218 Mon Sep 17 00:00:00 2001 From: Manfei <41607353+ManfeiBai@users.noreply.github.com> Date: Thu, 28 Mar 2024 22:11:53 -0700 Subject: [PATCH 001/323] Update test_xla_sharding.cpp --- test/cpp/test_xla_sharding.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/cpp/test_xla_sharding.cpp b/test/cpp/test_xla_sharding.cpp index e1f908b5c80..a17031f148e 100644 --- a/test/cpp/test_xla_sharding.cpp +++ b/test/cpp/test_xla_sharding.cpp @@ -435,5 +435,17 @@ TEST_F(XLAShardingTest, PrepareOutputShardingPropagation) { ->HasValue()); } +TEST_F(XLAShardingTest, TestForiLoopAddUnusedParameterInXlaComputation) { + xla::Shape shape = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {}); + // Build simple addition. + xla::XlaBuilder b("builder"); + auto x = xla::Parameter(&b, /*parameter_number=*/0, shape, "p0"); + xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {}); + auto zzz = xla::Parameter(&b, /*parameter_number=*/1, shape2, "p1"); + auto y = xla::Add(x, xla::ConstantR0(&b, 3)); + xla::XlaComputation xla_computation = + ConsumeValue(b.Build(/*remove_dynamic_dimensions=*/false)); +} + } // namespace cpp_test } // namespace torch_xla From aacaa6279985aa4812f9bc696b097b8f0fb12574 Mon Sep 17 00:00:00 2001 From: Manfei <41607353+ManfeiBai@users.noreply.github.com> Date: Thu, 28 Mar 2024 22:12:40 -0700 Subject: [PATCH 002/323] Update test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py --- ...while_loop_simple_add_dispatch_in_torch.py | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index a76197cc736..e4c5218ccf5 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -18,6 +18,19 @@ def _fake_while_loop(cond_fn, body_fn, operands): operands = body_fn(*operands) return operands +def _fake_fori_loop(lower, upper, body_fun, *init_val): + # operands need to be more than one here + # print("upper - lower: ", upper - lower) + # print("init_val: ", init_val) + # print("type init_val: ", type(init_val)) + (a, b) = init_val + # print("a: ", a) + # print("b: ", b) + for i in range((upper - lower)[0]): + a = body_fun(a, b) + # print("a: ", a) + # print("i: ", i) + return a def _fake_fori_loop(lower, upper, body_fun, *init_val): (plus_value, init_val) = init_val @@ -64,23 +77,23 @@ def body_fn(init, limit_value): expected = _fake_while_loop(cond_fn, body_fn, (init, limit_value)) self.assertEqual(expected, res) - def test_while_loop_tpu_subtraction_nested(self): + def test_fori_loop_tpu_addition(self): + xm.mark_step() device = xm.xla_device() - def cond_fn(init, limit_value): - return limit_value[0] <= init[0] + lower = torch.tensor([2], dtype=torch.int32, device=device) + upper = torch.tensor([52], dtype=torch.int32, device=device) + one_value = torch.tensor([1], dtype=torch.int32, device=device) + init_val = torch.tensor([1], dtype=torch.int32, device=device) - def body_fn(init, limit_value): - one_value = torch.ones(1, dtype=torch.int32, device=device) - two_value = limit_value.clone() - return (torch.sub(torch.sub(init, one_value), one_value), two_value) + def body_fun(a, b): + return torch.add(a, b) - init = torch.tensor([10], dtype=torch.int32, device=device) - limit_value = torch.tensor([0], dtype=torch.int32, device=device) - res = while_loop(cond_fn, body_fn, (init, limit_value)) - expected = _fake_while_loop(cond_fn, body_fn, (init, limit_value)) - self.assertEqual(expected, res) + lower_, upper_, res_ = fori_loop(upper, lower, body_fun, one_value, init_val) + expected = _fake_fori_loop(lower, upper, body_fun, init_val, one_value) + print("expected: ", expected) + self.assertEqual(expected, res_) def test_fori_loop_tpu_addition(self): From a2f7062689c98d538c7971618411438b94f8a995 Mon Sep 17 00:00:00 2001 From: Manfei <41607353+ManfeiBai@users.noreply.github.com> Date: Thu, 28 Mar 2024 22:14:46 -0700 Subject: [PATCH 003/323] Update init_python_bindings.cpp --- torch_xla/csrc/init_python_bindings.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index c603e5d27a5..8890296a61f 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -889,7 +889,17 @@ class PyLoweringContext { : lowering_ctx("PyLoweringContext", device) {} // Builds a HLO graph given a set of output tensors. - void Build(std::vector tensors) { + void Build(std::vector tensors, std::vector input_arguments) { + if (GetNameString() == "condctx") { + xla::XlaBuilder* local_builder = lowering_ctx.builder(); + int64_t parameters_number_i = 2; + for (at::Tensor input_argument : input_arguments) { + xla::Shape shape = xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {1}); + xla::XlaOp x = xla::Parameter(local_builder, parameters_number_i, shape, "UnusedArgumentsPlaceholder"); + parameters_number_i = parameters_number_i + 1; + } + } + // Get the backing XLA tensors from the output torch tensor handles std::vector xtensors = GetXlaTensors(tensors, /*want_all=*/true); From bd4ff83036211feb9fd2f106d78de6b46efb8b05 Mon Sep 17 00:00:00 2001 From: Manfei <41607353+ManfeiBai@users.noreply.github.com> Date: Thu, 28 Mar 2024 22:15:18 -0700 Subject: [PATCH 004/323] Update fori_loop.py --- torch_xla/experimental/fori_loop.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index bf32a712f3e..3533949fccd 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -11,6 +11,28 @@ import torch._higher_order_ops.while_loop from torch._higher_order_ops.while_loop import while_loop_op +def fori_loop(lower, upper, body_fun, one_value, init_val): + + device = xm.xla_device() + + def cond_fn(upper, lower, x): + return lower[0] < upper[0] + + def body_fn(upper, lower, x): + one_value = torch.ones(1, dtype=torch.int32, device=device) + return (torch.sub(upper, one_value), lower, body_fun(one_value, x)) + + def old_cond_fn(one_value, lower, upper, init_val): + lower_compare = torch.add(lower, one_value) + return lower_compare[0] <= upper[0] + + def old_body_fn(one_value, lower, upper, init_val): + new_lower = torch.add(lower, one_value) + new_init_val = body_fun(init_val, one_value) + return (one_value, new_lower, upper, new_init_val) + + res = _xla_while_loop(cond_fn, body_fn, lower, upper, init_val) + return res def fori_loop(lower, upper, user_body_func, *init_val): From 5765405e9ea751b5f2d786140d20a3e8700b6c44 Mon Sep 17 00:00:00 2001 From: Manfei <41607353+ManfeiBai@users.noreply.github.com> Date: Thu, 28 Mar 2024 22:26:59 -0700 Subject: [PATCH 005/323] format --- torch_xla/csrc/init_python_bindings.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index 8890296a61f..c876e56bd8e 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -889,13 +889,16 @@ class PyLoweringContext { : lowering_ctx("PyLoweringContext", device) {} // Builds a HLO graph given a set of output tensors. - void Build(std::vector tensors, std::vector input_arguments) { + void Build(std::vector tensors, + std::vector input_arguments) { if (GetNameString() == "condctx") { xla::XlaBuilder* local_builder = lowering_ctx.builder(); int64_t parameters_number_i = 2; for (at::Tensor input_argument : input_arguments) { - xla::Shape shape = xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {1}); - xla::XlaOp x = xla::Parameter(local_builder, parameters_number_i, shape, "UnusedArgumentsPlaceholder"); + xla::Shape shape = + xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {1}); + xla::XlaOp x = xla::Parameter(local_builder, parameters_number_i, shape, + "UnusedArgumentsPlaceholder"); parameters_number_i = parameters_number_i + 1; } } From b518a1386df8fcc888599fb705b575fc311e9403 Mon Sep 17 00:00:00 2001 From: Manfei <41607353+ManfeiBai@users.noreply.github.com> Date: Thu, 28 Mar 2024 22:29:51 -0700 Subject: [PATCH 006/323] format --- ...fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index e4c5218ccf5..727ec9dadb8 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -18,6 +18,7 @@ def _fake_while_loop(cond_fn, body_fn, operands): operands = body_fn(*operands) return operands + def _fake_fori_loop(lower, upper, body_fun, *init_val): # operands need to be more than one here # print("upper - lower: ", upper - lower) @@ -38,7 +39,6 @@ def _fake_fori_loop(lower, upper, body_fun, *init_val): plus_value, init_val = body_fun(plus_value, init_val) return init_val - class WhileLoopTest(unittest.TestCase): def test_while_loop_tpu_subtraction(self): @@ -90,7 +90,8 @@ def test_fori_loop_tpu_addition(self): def body_fun(a, b): return torch.add(a, b) - lower_, upper_, res_ = fori_loop(upper, lower, body_fun, one_value, init_val) + lower_, upper_, res_ = fori_loop(upper, lower, body_fun, one_value, + init_val) expected = _fake_fori_loop(lower, upper, body_fun, init_val, one_value) print("expected: ", expected) self.assertEqual(expected, res_) From aacb407c4441b20dcdefa809329136a97686ce39 Mon Sep 17 00:00:00 2001 From: Manfei <41607353+ManfeiBai@users.noreply.github.com> Date: Thu, 28 Mar 2024 22:32:22 -0700 Subject: [PATCH 007/323] format --- torch_xla/experimental/fori_loop.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 3533949fccd..d34e4e8855d 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -11,6 +11,7 @@ import torch._higher_order_ops.while_loop from torch._higher_order_ops.while_loop import while_loop_op + def fori_loop(lower, upper, body_fun, one_value, init_val): device = xm.xla_device() @@ -22,7 +23,7 @@ def body_fn(upper, lower, x): one_value = torch.ones(1, dtype=torch.int32, device=device) return (torch.sub(upper, one_value), lower, body_fun(one_value, x)) - def old_cond_fn(one_value, lower, upper, init_val): + def old_cond_fn(one_value, lower, upper, init_val): lower_compare = torch.add(lower, one_value) return lower_compare[0] <= upper[0] @@ -51,7 +52,6 @@ def body_fn(upper, lower, *init_val): res = while_loop(cond_fn, body_fn, (lower, upper, *init_val)) return res - @while_loop_op.py_impl(DispatchKey.XLA) def while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): # TODO(@manfei): PyTorch require carried_inputs to be list/tuple, PyTorch/XLA _xla_while_loop only accept *operands, *operands would tuple items again: (a, '') From ff115afa9a783e3876f49e2cb1fa4ccc0ab592c2 Mon Sep 17 00:00:00 2001 From: Manfei <41607353+ManfeiBai@users.noreply.github.com> Date: Fri, 29 Mar 2024 00:07:57 -0700 Subject: [PATCH 008/323] Update init_python_bindings.cpp --- torch_xla/csrc/init_python_bindings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index c876e56bd8e..25ffae673f6 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -890,7 +890,7 @@ class PyLoweringContext { // Builds a HLO graph given a set of output tensors. void Build(std::vector tensors, - std::vector input_arguments) { + std::vector input_arguments = std::vector::empty) { if (GetNameString() == "condctx") { xla::XlaBuilder* local_builder = lowering_ctx.builder(); int64_t parameters_number_i = 2; From b53e87faf11a7521a59fcea33cc28afa68cae64a Mon Sep 17 00:00:00 2001 From: Manfei <41607353+ManfeiBai@users.noreply.github.com> Date: Fri, 29 Mar 2024 01:27:13 -0700 Subject: [PATCH 009/323] Update init_python_bindings.cpp --- torch_xla/csrc/init_python_bindings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index 25ffae673f6..2b0221cb0a1 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -890,7 +890,7 @@ class PyLoweringContext { // Builds a HLO graph given a set of output tensors. void Build(std::vector tensors, - std::vector input_arguments = std::vector::empty) { + std::vector input_arguments = {}) { if (GetNameString() == "condctx") { xla::XlaBuilder* local_builder = lowering_ctx.builder(); int64_t parameters_number_i = 2; From 27639c487d503e184cb85f72de25d7e579dc9f14 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 29 Mar 2024 17:47:17 +0000 Subject: [PATCH 010/323] test formal change --- ...p_with_while_loop_simple_add_dispatch_in_torch.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 727ec9dadb8..3578434bef3 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -20,17 +20,9 @@ def _fake_while_loop(cond_fn, body_fn, operands): def _fake_fori_loop(lower, upper, body_fun, *init_val): - # operands need to be more than one here - # print("upper - lower: ", upper - lower) - # print("init_val: ", init_val) - # print("type init_val: ", type(init_val)) (a, b) = init_val - # print("a: ", a) - # print("b: ", b) for i in range((upper - lower)[0]): a = body_fun(a, b) - # print("a: ", a) - # print("i: ", i) return a def _fake_fori_loop(lower, upper, body_fun, *init_val): @@ -55,7 +47,7 @@ def body_fn(init, limit_value): init = torch.tensor([10], dtype=torch.int32, device=device) limit_value = torch.tensor([0], dtype=torch.int32, device=device) - res = while_loop(cond_fn, body_fn, (init, limit_value)) + res = while_loop(cond_fn, body_fn, init, limit_value) # (init, limit_value)) expected = _fake_while_loop(cond_fn, body_fn, (init, limit_value)) self.assertEqual(expected, res) @@ -73,7 +65,7 @@ def body_fn(init, limit_value): # TODO(@manfei): init and limit_value has to be torch.tensor. init = torch.tensor([0], dtype=torch.int32, device=device) limit_value = torch.tensor([10], dtype=torch.int32, device=device) - res = while_loop(cond_fn, body_fn, (init, limit_value)) + res = while_loop(cond_fn, body_fn, init, limit_value) # (init, limit_value)) expected = _fake_while_loop(cond_fn, body_fn, (init, limit_value)) self.assertEqual(expected, res) From cf8b7bc8ae5f350d9bd81d8b391fc917ba1a7a2a Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 29 Mar 2024 17:48:16 +0000 Subject: [PATCH 011/323] test formal change --- torch_xla/experimental/fori_loop.py | 95 ++++++++++++++--------------- 1 file changed, 45 insertions(+), 50 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index d34e4e8855d..57f7162bf3f 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -12,45 +12,35 @@ from torch._higher_order_ops.while_loop import while_loop_op -def fori_loop(lower, upper, body_fun, one_value, init_val): +# TODO(@manfei): delete one_value? +def fori_loop(upper, lower, body_fun, init_val, *input_value): device = xm.xla_device() + # weight_0 = body_fun.weight + # bias_0 = body_fun.bias + # one_value = torch.tensor([1], dtype=torch.int32, device=device) - def cond_fn(upper, lower, x): + def cond_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bias_0): # , bias_0): # , output_value): return lower[0] < upper[0] - def body_fn(upper, lower, x): - one_value = torch.ones(1, dtype=torch.int32, device=device) - return (torch.sub(upper, one_value), lower, body_fun(one_value, x)) - - def old_cond_fn(one_value, lower, upper, init_val): - lower_compare = torch.add(lower, one_value) - return lower_compare[0] <= upper[0] - - def old_body_fn(one_value, lower, upper, init_val): - new_lower = torch.add(lower, one_value) - new_init_val = body_fun(init_val, one_value) - return (one_value, new_lower, upper, new_init_val) - - res = _xla_while_loop(cond_fn, body_fn, lower, upper, init_val) + def body_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bias_0): # , bias_0): + # weight = body_fun.weight + new_lower = torch.add(one_value, lower) ### !!! this matter, torch.add might would change the second argument's value, even we use a new variable to catch the result!!! + output_value = body_fun(*input_value) ### !!! due to the output_value is not actually used here, + # --- !!! its original value would not be used, and it would be replaces by the result of body_fun + # --- !!! so, due to PTXLA is traced from result tensor, so the arguments `output_value` would not be included in the body_xlacomputation + # --- !!! so, we need to modify ini_python_binding.cpp to add a fake arguments in the xlacompputation + weight = body_fun.weight + bias = body_fun.bias + return upper, new_lower, one_value, torch.add(one_value, x), *input_value, weight, bias, output_value + + output_value = torch.zeros([20], dtype=torch.float32, device=device) + weight_0 = body_fun.weight + bias_0 = body_fun.bias + one_value = torch.tensor([1], dtype=torch.int32, device=device) + res = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, *input_value, weight_0, bias_0, output_value)) return res -def fori_loop(lower, upper, user_body_func, *init_val): - - device = xm.xla_device() - - def cond_fn(upper, lower, *init_val): - return lower[0] < upper[0] - - def body_fn(upper, lower, *init_val): - one_value_i = torch.ones(1, dtype=torch.int32, device=device) - res_list = list(user_body_func(*init_val)) - res_list.insert(0, lower) - res_list.insert(0, torch.sub(upper, one_value_i)) - return res_list - - res = while_loop(cond_fn, body_fn, (lower, upper, *init_val)) - return res @while_loop_op.py_impl(DispatchKey.XLA) def while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): @@ -59,8 +49,7 @@ def while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): # carried_inputs: (Tuple of possibly nested dict/list/tuple of tensors) if additional_inputs is None: additional_inputs = tuple() - return _xla_while_loop( - cond_fn, body_fn, *carried_inputs, additional_inputs=additional_inputs) + return _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=additional_inputs) # a=a, b=b, c=c, def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs): @@ -70,34 +59,27 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs): fake_carried_inputs = [] for carried_input in carried_inputs: device = carried_input.device + #TODO(@manfei) type = carried_input.type fake_carried_inputs.append( torch.randint(10, carried_input.size(), dtype=carried_input.dtype).to(device)) fake_carried_inputs = tuple(fake_carried_inputs) - # trans fake_carried_inputs from list(tensor) to list(xla::op) - kwargs = {} - if type(fake_carried_inputs) is tuple: - shapes = xb.tensor_shape(fake_carried_inputs) - else: - shapes = xb.tensor_shape((fake_carried_inputs)) - builder = xb.create_builder('test_while') - params = [] - for shape in shapes: - p = xb.mkparam(builder, len(params), shape) - params.append(p) - # generate cond_fn xlacomputation - cond_result = cond_fn(*fake_carried_inputs) + # TODO(@manfei): specify which element is for which argument like a,b,c + cond_result = cond_fn(*fake_carried_inputs[:-3], weight_0=fake_carried_inputs[-3], output_value=fake_carried_inputs[-2], bias_0=fake_carried_inputs[-1]) cond_ctx = torch_xla._XLAC.lowering.LoweringContext() cond_ctx.set_name_string("condctx") - cond_ctx.buildforiloop([cond_result], list(fake_carried_inputs[2:])) + additional_inputs_list = list(fake_carried_inputs[2:]) + for i in range(len(additional_inputs)): + additional_inputs_list.append(additional_inputs[0]) + cond_ctx.buildforiloop([cond_result], additional_inputs_list) cond_hlo = cond_ctx.hlo() cond_computation = xb.computation_from_module_proto("condcomputation", cond_hlo) # generate body_fn xlacomputation - body_result = body_fn(*fake_carried_inputs) + body_result = body_fn(*fake_carried_inputs[:-3], weight_0=fake_carried_inputs[-3], output_value=fake_carried_inputs[-2], bias_0=fake_carried_inputs[-1]) body_ctx = torch_xla._XLAC.lowering.LoweringContext() body_ctx.set_name_string("bodyctx") body_ctx.buildforiloop(list(body_result), []) @@ -105,6 +87,18 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs): body_computation = xb.computation_from_module_proto("bodycomputation", body_hlo) + # trans fake_carried_inputs from list(tensor) to list(xla::op), which part could change init of xla::while + kwargs = {} + if type(carried_inputs) is tuple: + shapes = xb.tensor_shape(carried_inputs) + else: + shapes = xb.tensor_shape((carried_inputs)) + builder = xb.create_builder('test_while') + params = [] + for shape in shapes: + p = xb.mkparam(builder, len(params), shape) + params.append(p) + # generate while xlacomputation input_tuple = xb.Op.tuple(tuple(params)) w = xb.mkop( @@ -116,6 +110,7 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs): # gain final result with generated while xlacomputation result = torch_xla._XLAC._xla_user_computation('xla::_op_test_while', - (carried_inputs), computation) + (carried_inputs), + computation) return result \ No newline at end of file From 945ab7ae07e271342c74fdb8173fcb54c35c4e51 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 29 Mar 2024 17:52:16 +0000 Subject: [PATCH 012/323] test formal change --- ...ri_loop_with_while_loop_simple_add_dispatch_in_torch.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 3578434bef3..928e70ffc7e 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -55,10 +55,12 @@ def test_while_loop_tpu_addition(self): device = xm.xla_device() - def cond_fn(init, limit_value): + def cond_fn(loop_carry): # init, limit_value): + init, limit_value = loop_carry return limit_value[0] >= init[0] - def body_fn(init, limit_value): + def body_fn(loop_carry): # init, limit_value): + init, limit_value = loop_carry one_value = torch.ones(1, dtype=torch.int32, device=device) return (torch.add(init, one_value), limit_value.clone()) @@ -85,7 +87,6 @@ def body_fun(a, b): lower_, upper_, res_ = fori_loop(upper, lower, body_fun, one_value, init_val) expected = _fake_fori_loop(lower, upper, body_fun, init_val, one_value) - print("expected: ", expected) self.assertEqual(expected, res_) def test_fori_loop_tpu_addition(self): From f561a127a9cff04cacf96b4cfa176ebdb5c5fb29 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 29 Mar 2024 17:52:59 +0000 Subject: [PATCH 013/323] test formal change --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 928e70ffc7e..b418d0f0ba6 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -47,7 +47,7 @@ def body_fn(init, limit_value): init = torch.tensor([10], dtype=torch.int32, device=device) limit_value = torch.tensor([0], dtype=torch.int32, device=device) - res = while_loop(cond_fn, body_fn, init, limit_value) # (init, limit_value)) + res = while_loop(cond_fn, body_fn, (init, limit_value)) expected = _fake_while_loop(cond_fn, body_fn, (init, limit_value)) self.assertEqual(expected, res) @@ -67,7 +67,7 @@ def body_fn(loop_carry): # init, limit_value): # TODO(@manfei): init and limit_value has to be torch.tensor. init = torch.tensor([0], dtype=torch.int32, device=device) limit_value = torch.tensor([10], dtype=torch.int32, device=device) - res = while_loop(cond_fn, body_fn, init, limit_value) # (init, limit_value)) + res = while_loop(cond_fn, body_fn, (init, limit_value)) expected = _fake_while_loop(cond_fn, body_fn, (init, limit_value)) self.assertEqual(expected, res) From 834cb251c4972153c9ddb4b644246f48f1ba54b8 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 29 Mar 2024 18:24:04 +0000 Subject: [PATCH 014/323] test formal change --- ...ori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index b418d0f0ba6..55a02a55e48 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -55,12 +55,10 @@ def test_while_loop_tpu_addition(self): device = xm.xla_device() - def cond_fn(loop_carry): # init, limit_value): - init, limit_value = loop_carry + def cond_fn(init, limit_value): return limit_value[0] >= init[0] - def body_fn(loop_carry): # init, limit_value): - init, limit_value = loop_carry + def body_fn(init, limit_value): one_value = torch.ones(1, dtype=torch.int32, device=device) return (torch.add(init, one_value), limit_value.clone()) From a9814d2c04bde1729c3a6b015f5462b63024accd Mon Sep 17 00:00:00 2001 From: Manfei <41607353+ManfeiBai@users.noreply.github.com> Date: Mon, 1 Apr 2024 10:57:14 -0700 Subject: [PATCH 015/323] Update test_xla_sharding.cpp --- test/cpp/test_xla_sharding.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/cpp/test_xla_sharding.cpp b/test/cpp/test_xla_sharding.cpp index a17031f148e..b59927cdbf7 100644 --- a/test/cpp/test_xla_sharding.cpp +++ b/test/cpp/test_xla_sharding.cpp @@ -440,11 +440,15 @@ TEST_F(XLAShardingTest, TestForiLoopAddUnusedParameterInXlaComputation) { // Build simple addition. xla::XlaBuilder b("builder"); auto x = xla::Parameter(&b, /*parameter_number=*/0, shape, "p0"); + // Add unused parameter before create xlacomputation xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {}); auto zzz = xla::Parameter(&b, /*parameter_number=*/1, shape2, "p1"); auto y = xla::Add(x, xla::ConstantR0(&b, 3)); xla::XlaComputation xla_computation = ConsumeValue(b.Build(/*remove_dynamic_dimensions=*/false)); + + // Check whether the unused parameter has been included into xlacomputation or not + EXPECT_EQ(xla_computation.GetProgramShape().parameters_size(), 2); } } // namespace cpp_test From feb39cace9acd0e1cad5384f7cf565aee921e6db Mon Sep 17 00:00:00 2001 From: Manfei <41607353+ManfeiBai@users.noreply.github.com> Date: Mon, 1 Apr 2024 11:49:42 -0700 Subject: [PATCH 016/323] Update test_xla_sharding.cpp --- test/cpp/test_xla_sharding.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cpp/test_xla_sharding.cpp b/test/cpp/test_xla_sharding.cpp index b59927cdbf7..55cdc8f1fb4 100644 --- a/test/cpp/test_xla_sharding.cpp +++ b/test/cpp/test_xla_sharding.cpp @@ -448,7 +448,7 @@ TEST_F(XLAShardingTest, TestForiLoopAddUnusedParameterInXlaComputation) { ConsumeValue(b.Build(/*remove_dynamic_dimensions=*/false)); // Check whether the unused parameter has been included into xlacomputation or not - EXPECT_EQ(xla_computation.GetProgramShape().parameters_size(), 2); + EEXPECT_EQ(xla_computation.GetProgramShape()->parameters_size(), 2); } } // namespace cpp_test From 8b2cd86eadde4e4ca7a37b37d93cea770ac35d56 Mon Sep 17 00:00:00 2001 From: Manfei <41607353+ManfeiBai@users.noreply.github.com> Date: Mon, 1 Apr 2024 11:52:57 -0700 Subject: [PATCH 017/323] format --- test/cpp/test_xla_sharding.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cpp/test_xla_sharding.cpp b/test/cpp/test_xla_sharding.cpp index 55cdc8f1fb4..e27be283f66 100644 --- a/test/cpp/test_xla_sharding.cpp +++ b/test/cpp/test_xla_sharding.cpp @@ -447,7 +447,7 @@ TEST_F(XLAShardingTest, TestForiLoopAddUnusedParameterInXlaComputation) { xla::XlaComputation xla_computation = ConsumeValue(b.Build(/*remove_dynamic_dimensions=*/false)); - // Check whether the unused parameter has been included into xlacomputation or not + // Check whether the unused parameter has been included into xlacomputation EEXPECT_EQ(xla_computation.GetProgramShape()->parameters_size(), 2); } From cc1e7ef3a5d19f4c679c63549e762d87b8c9abdf Mon Sep 17 00:00:00 2001 From: Manfei <41607353+ManfeiBai@users.noreply.github.com> Date: Mon, 1 Apr 2024 11:56:01 -0700 Subject: [PATCH 018/323] format --- test/cpp/test_xla_sharding.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cpp/test_xla_sharding.cpp b/test/cpp/test_xla_sharding.cpp index e27be283f66..167ffd753e7 100644 --- a/test/cpp/test_xla_sharding.cpp +++ b/test/cpp/test_xla_sharding.cpp @@ -448,7 +448,7 @@ TEST_F(XLAShardingTest, TestForiLoopAddUnusedParameterInXlaComputation) { ConsumeValue(b.Build(/*remove_dynamic_dimensions=*/false)); // Check whether the unused parameter has been included into xlacomputation - EEXPECT_EQ(xla_computation.GetProgramShape()->parameters_size(), 2); + EXPECT_EQ(xla_computation.GetProgramShape()->parameters_size(), 2); } } // namespace cpp_test From 1c54e4b03552c21b4a9dd66002a36253e9050e2d Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 2 Apr 2024 18:07:15 +0000 Subject: [PATCH 019/323] upstream --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 55a02a55e48..b92d8e0ee44 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -47,7 +47,7 @@ def body_fn(init, limit_value): init = torch.tensor([10], dtype=torch.int32, device=device) limit_value = torch.tensor([0], dtype=torch.int32, device=device) - res = while_loop(cond_fn, body_fn, (init, limit_value)) + res = while_loop(cond_fn, body_fn, init, limit_value) expected = _fake_while_loop(cond_fn, body_fn, (init, limit_value)) self.assertEqual(expected, res) From cb3a5f495d0ba41cdc4081b558945a0b87c6db54 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 2 Apr 2024 18:09:11 +0000 Subject: [PATCH 020/323] upstream --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index b92d8e0ee44..55a02a55e48 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -47,7 +47,7 @@ def body_fn(init, limit_value): init = torch.tensor([10], dtype=torch.int32, device=device) limit_value = torch.tensor([0], dtype=torch.int32, device=device) - res = while_loop(cond_fn, body_fn, init, limit_value) + res = while_loop(cond_fn, body_fn, (init, limit_value)) expected = _fake_while_loop(cond_fn, body_fn, (init, limit_value)) self.assertEqual(expected, res) From 9007442dba389063ae79e0a0ea51cbdbaca25697 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 2 Apr 2024 21:35:42 +0000 Subject: [PATCH 021/323] upstream --- torch_xla/experimental/fori_loop.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 57f7162bf3f..da18f2e8683 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -52,7 +52,9 @@ def while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): return _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=additional_inputs) # a=a, b=b, c=c, -def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs): +def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): + print("carried_inputs: ", carried_inputs) + print("additional_inputs: ", additional_inputs) # untuple carried_inputs from while_loop carried_inputs = carried_inputs[0] # fake carried_inputs to split formal code From 5394b464510398cdd120a1e31c9ef1b747a68346 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 2 Apr 2024 23:12:47 +0000 Subject: [PATCH 022/323] test --- ...fori_loop_simple_linear_model_test_code.py | 193 ++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 test/test_fori_loop_simple_linear_model_test_code.py diff --git a/test/test_fori_loop_simple_linear_model_test_code.py b/test/test_fori_loop_simple_linear_model_test_code.py new file mode 100644 index 00000000000..006b602f001 --- /dev/null +++ b/test/test_fori_loop_simple_linear_model_test_code.py @@ -0,0 +1,193 @@ +import os +# import unittest +# from typing import Callable, Dict, List + +import torch +import torch_xla +# We need to import the underlying implementation function to register with the dispatcher +import torch_xla.experimental.fori_loop +from torch_xla.experimental.fori_loop import fori_loop +# from torch._higher_order_ops.while_loop import while_loop +import torch_xla.core.xla_model as xm +# import torch_xla.core.xla_builder as xb +import torch_xla.utils.utils as xu + +torch.set_grad_enabled(False) + +device = xm.xla_device() + +# --- linear one --- +# l_in = torch.randn(10, device=xm.xla_device()) +# linear = torch.nn.Linear(10, 20).to(xm.xla_device()) +# l_out = linear(l_in) +# print("linear one: ", l_out) + +# --- while test case --- + +lower = torch.tensor([2], dtype=torch.int32, device=device) +upper = torch.tensor([52], dtype=torch.int32, device=device) +one_value = torch.tensor([1], dtype=torch.int32, device=device) +init_val = torch.tensor([1], dtype=torch.int32, device=device) +# one_one = torch.one(1, dtype=torch.int32, device=device) + +# def body_fun(l_in): +# # l_in = torch.randn(10, device=xm.xla_device()) +# linear = torch.nn.Linear(10, 20).to(xm.xla_device()) +# # l_out = linear(l_in) +# return linear(l_in) # torch.add(a, b) # [0]) +linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) + +def body_fun(y, x, l_in_i): + # l_in = torch.randn(10, device=xm.xla_device()) + # linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) + l_out = linear_0(l_in_i) + # placeholder_func = torch.rand(size = l_out.size(), device = device) + # placeholder_input = torch.rand(size = l_in_i.size(), device = device) + # return torch.add(y, x), l_out, placeholder_func, placeholder_input # linear_0(l_in_i), linear_0, l_in_i # additional return: body and input-placeholder # linear(l_in) # torch.add(a, b) # [0]) + return torch.add(y, x), l_out + +# TODO(@manfei), need to create new variable to seperate old/formal HLO/IR +l_in_0 = torch.randn(10, device=xm.xla_device()) + +# def body_fun(x, y, l_in): +# # l_in = torch.randn(10, device=xm.xla_device()) +# linear = torch.nn.Linear(10, 20).to(xm.xla_device()) +# # l_out = linear(l_in) +# return torch.add(x, y), linear(l_in) # linear(l_in) # torch.add(a, b) # [0]) + +# placeholder_func = torch.rand(size = l_out.size(), device = device) +# placeholder_input = torch.rand(size = l_in_i.size(), device = device) +print("test code, body_fun: ", body_fun) + +lower_, upper_, res_ = fori_loop(upper, lower, body_fun, one_value, init_val, l_in_0) # , placeholder_func, placeholder_input) # , linear_0, l_in_0) + +print("lower_: ", lower_) +print("upper_: ", upper_) +print("res_: ", res_) + +# --- linear two --- +# l_in_2 = torch.randn(10, device=xm.xla_device()) +# linear_2 = torch.nn.Linear(10, 20).to(xm.xla_device()) +# l_out_2 = linear(l_in_2) +# print("linear two: ", l_out_2) + +# ================================================================================= + +# import numpy as np +# # create dummy data for training +# # x_values = [i for i in range(11)] +# # x_train = np.array(x_values, dtype=np.float32) +# # x_train = x_train.reshape(-1, 1) + +# # y_values = [2*i + 1 for i in x_values] +# # y_train = np.array(y_values, dtype=np.float32) +# # y_train = y_train.reshape(-1, 1) + +# batch_size = 2 + +# train_loader = xu.SampleGenerator( +# data=(torch.zeros(batch_size, 1), torch.zeros(batch_size, dtype=torch.float32)), +# sample_count=64 // batch_size // xm.xrt_world_size()) +# test_loader = xu.SampleGenerator( +# data=(torch.zeros(batch_size, 1, torch.zeros(batch_size, dtype=torch.float32)), +# sample_count=32 // batch_size // xm.xrt_world_size()) + +# # import torch +# from torch.autograd import Variable + +# class linearRegression(torch.nn.Module): +# def __init__(self, inputSize, outputSize): +# super(linearRegression, self).__init__() +# self.linear = torch.nn.Linear(inputSize, outputSize).to(device) + +# def forward(self, x): +# out = self.linear(x) +# return out + +# # --- training --- +# inputDim = 1 # takes variable 'x' +# outputDim = 1 # takes variable 'y' +# learningRate = 0.01 * xm.xrt_world_size() +# epochs = 10 # 100 + +# model = linearRegression(inputDim, outputDim).to(device) +# # model = MNIST().to(device) +# ##### For GPU ####### +# # if torch.cuda.is_available(): +# # model.cuda() + +# if xr.using_pjrt(): +# xm.broadcast_master_param(model) + +# criterion = torch.nn.MSELoss() +# optimizer = torch.optim.SGD(model.parameters(), lr=learningRate) + +# for epoch in range(epochs): +# # Converting inputs and labels to Variable +# # if torch.cuda.is_available(): +# # inputs = Variable(torch.from_numpy(x_train).cuda()) +# # labels = Variable(torch.from_numpy(y_train).cuda()) +# # else: +# inputs = Variable(torch.from_numpy(x_train)).to(device) +# labels = Variable(torch.from_numpy(y_train)).to(device) + +# # Clear gradient buffers because we don't want any gradient from previous epoch to carry forward, dont want to cummulate gradients +# optimizer.zero_grad() + +# # get output from the model, given the inputs +# outputs = model(inputs) + +# # get loss for the predicted output +# loss = criterion(outputs, labels) +# print(loss) +# # get gradients w.r.t to parameters +# loss.backward() + +# # update parameters +# # optimizer.step() +# xm.optimizer_step(optimizer) + +# print('epoch {}, loss {}'.format(epoch, loss.item())) + +# # --- while simple test case --- + +# # device = xm.xla_device() + +# lower = torch.tensor([2], dtype=torch.int32, device=device) +# upper = torch.tensor([52], dtype=torch.int32, device=device) +# one_value = torch.tensor([1], dtype=torch.int32, device=device) +# init_val = torch.tensor([1], dtype=torch.int32, device=device) + +# def body_fun(a, b): +# return torch.add(a, b) # [0]) + +# lower_, upper_, res_ = fori_loop(upper, lower, body_fun, one_value, init_val) + +# print("lower_: ", lower_) +# print("upper_: ", upper_) +# print("res_: ", res_) + +# # --- test --- +# for epoch in range(epochs): +# with torch.no_grad(): # we don't need gradients in the testing phase +# if torch.cuda.is_available(): +# predicted = model(Variable(torch.from_numpy(x_train).cuda())).cpu().data.numpy() +# else: +# predicted = model(Variable(torch.from_numpy(x_train))).data.numpy() +# print(epoch, "-th prediction finised") # ed result: ", predicted) + +# print("do one more prediction") +# with torch.no_grad(): # we don't need gradients in the testing phase +# if torch.cuda.is_available(): +# predicted = model(Variable(torch.from_numpy(x_train).cuda())).cpu().data.numpy() +# else: +# predicted = model(Variable(torch.from_numpy(x_train))).data.numpy() +# print(predicted) +# print("finished one more prediction") + +# # --- draw --- +# # plt.clf() +# # plt.plot(x_train, y_train, 'go', label='True data', alpha=0.5) +# # plt.plot(x_train, predicted, '--', label='Predictions', alpha=0.5) +# # plt.legend(loc='best') +# # plt.show() \ No newline at end of file From 972bc82f870e26c086670902c8acabf8f08e6938 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 2 Apr 2024 23:27:00 +0000 Subject: [PATCH 023/323] test --- torch_xla/experimental/fori_loop.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index da18f2e8683..cb8866e78ad 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -79,6 +79,9 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): cond_hlo = cond_ctx.hlo() cond_computation = xb.computation_from_module_proto("condcomputation", cond_hlo) + cond_hlo_print = xb.get_computation_hlo(cond_computation) + print("cond computation: !!!!!!!!!") + print(cond_hlo_print) # generate body_fn xlacomputation body_result = body_fn(*fake_carried_inputs[:-3], weight_0=fake_carried_inputs[-3], output_value=fake_carried_inputs[-2], bias_0=fake_carried_inputs[-1]) @@ -88,6 +91,9 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): body_hlo = body_ctx.hlo() body_computation = xb.computation_from_module_proto("bodycomputation", body_hlo) + body_hlo_print = xb.get_computation_hlo(body_computation) + print("body computation: !!!!!!!!!") + print(body_hlo_print) # trans fake_carried_inputs from list(tensor) to list(xla::op), which part could change init of xla::while kwargs = {} @@ -109,6 +115,9 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): body_computation=body_computation) name = 'fori_loop_ed_torch_func' computation = w.build(name) + hlo_print = xb.get_computation_hlo(computation) + print("while computation: !!!!!!!!!") + print(hlo_print) # gain final result with generated while xlacomputation result = torch_xla._XLAC._xla_user_computation('xla::_op_test_while', From 518bdbc124273a6fc547246faab259a7d981b249 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 3 Apr 2024 05:59:59 +0000 Subject: [PATCH 024/323] test --- torch_xla/csrc/init_python_bindings.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index 2b0221cb0a1..a7bed9e0bf9 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -901,6 +901,20 @@ class PyLoweringContext { "UnusedArgumentsPlaceholder"); parameters_number_i = parameters_number_i + 1; } + // hard-code to meet requirement + // f32[20], /*index=5*/f32[20,10], s32[10] + parameters_number_i = parameters_number_i + 1; + xla::Shape shape = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); + xla::XlaOp x = xla::Parameter(local_builder, parameters_number_i, shape, + "OutPutTensor"); + parameters_number_i = parameters_number_i + 1; + xla::Shape shape = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20, 10}); + xla::XlaOp x = xla::Parameter(local_builder, parameters_number_i, shape, + "WeightTensor"); + parameters_number_i = parameters_number_i + 1; + xla::Shape shape = xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {10}); + xla::XlaOp x = xla::Parameter(local_builder, parameters_number_i, shape, + "FinalOneTensor"); } // Get the backing XLA tensors from the output torch tensor handles From 16977fdc46ffca76b3157f810b14ad4403a2c93a Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 3 Apr 2024 06:03:11 +0000 Subject: [PATCH 025/323] test --- torch_xla/csrc/init_python_bindings.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index a7bed9e0bf9..36c0e93fd23 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -904,16 +904,16 @@ class PyLoweringContext { // hard-code to meet requirement // f32[20], /*index=5*/f32[20,10], s32[10] parameters_number_i = parameters_number_i + 1; - xla::Shape shape = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); - xla::XlaOp x = xla::Parameter(local_builder, parameters_number_i, shape, + xla::Shape shape1 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); + xla::XlaOp x1 = xla::Parameter(local_builder, parameters_number_i, shape1, "OutPutTensor"); parameters_number_i = parameters_number_i + 1; - xla::Shape shape = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20, 10}); - xla::XlaOp x = xla::Parameter(local_builder, parameters_number_i, shape, + xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20, 10}); + xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, "WeightTensor"); parameters_number_i = parameters_number_i + 1; - xla::Shape shape = xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {10}); - xla::XlaOp x = xla::Parameter(local_builder, parameters_number_i, shape, + xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {10}); + xla::XlaOp x3 = xla::Parameter(local_builder, parameters_number_i, shape3, "FinalOneTensor"); } From ab00e2ba0ecf23f6c113fbde2438147ccbd7b320 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 3 Apr 2024 06:35:29 +0000 Subject: [PATCH 026/323] test --- torch_xla/experimental/fori_loop.py | 1 + 1 file changed, 1 insertion(+) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index cb8866e78ad..715a94cd4be 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -66,6 +66,7 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): torch.randint(10, carried_input.size(), dtype=carried_input.dtype).to(device)) fake_carried_inputs = tuple(fake_carried_inputs) + print("fake_carried_inputs: ", fake_carried_inputs) # generate cond_fn xlacomputation # TODO(@manfei): specify which element is for which argument like a,b,c From 33f9e070f10160a775d210ce284fe05dde7c3a8d Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 3 Apr 2024 06:48:24 +0000 Subject: [PATCH 027/323] test --- torch_xla/csrc/init_python_bindings.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index 36c0e93fd23..3367968de1a 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -894,7 +894,8 @@ class PyLoweringContext { if (GetNameString() == "condctx") { xla::XlaBuilder* local_builder = lowering_ctx.builder(); int64_t parameters_number_i = 2; - for (at::Tensor input_argument : input_arguments) { + // for (at::Tensor input_argument : input_arguments) { + for (int i = 0; i < 2; i++) { xla::Shape shape = xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {1}); xla::XlaOp x = xla::Parameter(local_builder, parameters_number_i, shape, From 5fd313ae8ba70190777cd0a5b663f5a77e1ac632 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 3 Apr 2024 06:51:21 +0000 Subject: [PATCH 028/323] test --- torch_xla/csrc/init_python_bindings.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index 3367968de1a..0a6ea4af3d7 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -895,13 +895,13 @@ class PyLoweringContext { xla::XlaBuilder* local_builder = lowering_ctx.builder(); int64_t parameters_number_i = 2; // for (at::Tensor input_argument : input_arguments) { - for (int i = 0; i < 2; i++) { - xla::Shape shape = - xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {1}); - xla::XlaOp x = xla::Parameter(local_builder, parameters_number_i, shape, - "UnusedArgumentsPlaceholder"); - parameters_number_i = parameters_number_i + 1; - } + // for (int i = 0; i < 2; i++) { + // xla::Shape shape = + // xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {1}); + // xla::XlaOp x = xla::Parameter(local_builder, parameters_number_i, shape, + // "UnusedArgumentsPlaceholder"); + // parameters_number_i = parameters_number_i + 1; + // } // hard-code to meet requirement // f32[20], /*index=5*/f32[20,10], s32[10] parameters_number_i = parameters_number_i + 1; From a6ba3b892065178d6f7181df5455c6a465671179 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 3 Apr 2024 06:53:47 +0000 Subject: [PATCH 029/323] test --- torch_xla/csrc/init_python_bindings.cpp | 38 ++++++++++++------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index 0a6ea4af3d7..dbbcf1ecf57 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -894,28 +894,28 @@ class PyLoweringContext { if (GetNameString() == "condctx") { xla::XlaBuilder* local_builder = lowering_ctx.builder(); int64_t parameters_number_i = 2; - // for (at::Tensor input_argument : input_arguments) { + for (at::Tensor input_argument : input_arguments) { // for (int i = 0; i < 2; i++) { - // xla::Shape shape = - // xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {1}); - // xla::XlaOp x = xla::Parameter(local_builder, parameters_number_i, shape, - // "UnusedArgumentsPlaceholder"); - // parameters_number_i = parameters_number_i + 1; - // } + xla::Shape shape = + xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {1}); + xla::XlaOp x = xla::Parameter(local_builder, parameters_number_i, shape, + "UnusedArgumentsPlaceholder"); + parameters_number_i = parameters_number_i + 1; + } // hard-code to meet requirement // f32[20], /*index=5*/f32[20,10], s32[10] - parameters_number_i = parameters_number_i + 1; - xla::Shape shape1 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); - xla::XlaOp x1 = xla::Parameter(local_builder, parameters_number_i, shape1, - "OutPutTensor"); - parameters_number_i = parameters_number_i + 1; - xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20, 10}); - xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, - "WeightTensor"); - parameters_number_i = parameters_number_i + 1; - xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {10}); - xla::XlaOp x3 = xla::Parameter(local_builder, parameters_number_i, shape3, - "FinalOneTensor"); + // parameters_number_i = parameters_number_i + 1; + // xla::Shape shape1 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); + // xla::XlaOp x1 = xla::Parameter(local_builder, parameters_number_i, shape1, + // "OutPutTensor"); + // parameters_number_i = parameters_number_i + 1; + // xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20, 10}); + // xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, + // "WeightTensor"); + // parameters_number_i = parameters_number_i + 1; + // xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {10}); + // xla::XlaOp x3 = xla::Parameter(local_builder, parameters_number_i, shape3, + // "FinalOneTensor"); } // Get the backing XLA tensors from the output torch tensor handles From a09457edeb987a5c96a47bd4329f97b28546700b Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 3 Apr 2024 07:08:46 +0000 Subject: [PATCH 030/323] test --- torch_xla/csrc/init_python_bindings.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index dbbcf1ecf57..140c6755b49 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -894,8 +894,8 @@ class PyLoweringContext { if (GetNameString() == "condctx") { xla::XlaBuilder* local_builder = lowering_ctx.builder(); int64_t parameters_number_i = 2; - for (at::Tensor input_argument : input_arguments) { - // for (int i = 0; i < 2; i++) { + // for (at::Tensor input_argument : input_arguments) { + for (int i = 0; i < 5; i++) { xla::Shape shape = xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {1}); xla::XlaOp x = xla::Parameter(local_builder, parameters_number_i, shape, From 8ebc7721b8462a7df93dc8ab523c3b2f1b591c34 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 3 Apr 2024 07:12:50 +0000 Subject: [PATCH 031/323] test --- torch_xla/csrc/init_python_bindings.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index 140c6755b49..04517683ac2 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -895,7 +895,7 @@ class PyLoweringContext { xla::XlaBuilder* local_builder = lowering_ctx.builder(); int64_t parameters_number_i = 2; // for (at::Tensor input_argument : input_arguments) { - for (int i = 0; i < 5; i++) { + for (int i = 0; i < 4; i++) { xla::Shape shape = xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {1}); xla::XlaOp x = xla::Parameter(local_builder, parameters_number_i, shape, @@ -904,10 +904,10 @@ class PyLoweringContext { } // hard-code to meet requirement // f32[20], /*index=5*/f32[20,10], s32[10] - // parameters_number_i = parameters_number_i + 1; - // xla::Shape shape1 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); - // xla::XlaOp x1 = xla::Parameter(local_builder, parameters_number_i, shape1, - // "OutPutTensor"); + parameters_number_i = parameters_number_i + 1; + xla::Shape shape1 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); + xla::XlaOp x1 = xla::Parameter(local_builder, parameters_number_i, shape1, + "OutPutTensor"); // parameters_number_i = parameters_number_i + 1; // xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20, 10}); // xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, From 8bfa5583c14b757c59a4847e4b1eeca9feb06017 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 3 Apr 2024 07:18:06 +0000 Subject: [PATCH 032/323] test --- torch_xla/csrc/init_python_bindings.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index 04517683ac2..ab1103ad373 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -904,11 +904,11 @@ class PyLoweringContext { } // hard-code to meet requirement // f32[20], /*index=5*/f32[20,10], s32[10] - parameters_number_i = parameters_number_i + 1; + // parameters_number_i = parameters_number_i + 1; xla::Shape shape1 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); xla::XlaOp x1 = xla::Parameter(local_builder, parameters_number_i, shape1, "OutPutTensor"); - // parameters_number_i = parameters_number_i + 1; + parameters_number_i = parameters_number_i + 1; // xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20, 10}); // xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, // "WeightTensor"); From 7ed983c93292bade5701df22cfd2db436973f1f3 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 3 Apr 2024 07:22:02 +0000 Subject: [PATCH 033/323] test --- torch_xla/csrc/init_python_bindings.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index ab1103ad373..588a213e197 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -895,7 +895,7 @@ class PyLoweringContext { xla::XlaBuilder* local_builder = lowering_ctx.builder(); int64_t parameters_number_i = 2; // for (at::Tensor input_argument : input_arguments) { - for (int i = 0; i < 4; i++) { + for (int i = 0; i < 3; i++) { xla::Shape shape = xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {1}); xla::XlaOp x = xla::Parameter(local_builder, parameters_number_i, shape, @@ -909,10 +909,10 @@ class PyLoweringContext { xla::XlaOp x1 = xla::Parameter(local_builder, parameters_number_i, shape1, "OutPutTensor"); parameters_number_i = parameters_number_i + 1; - // xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20, 10}); - // xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, - // "WeightTensor"); - // parameters_number_i = parameters_number_i + 1; + xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20, 10}); + xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, + "WeightTensor"); + parameters_number_i = parameters_number_i + 1; // xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {10}); // xla::XlaOp x3 = xla::Parameter(local_builder, parameters_number_i, shape3, // "FinalOneTensor"); From 608191653023bfd2916ecb5ea044cd5daa44c325 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 3 Apr 2024 07:22:19 +0000 Subject: [PATCH 034/323] test --- torch_xla/csrc/init_python_bindings.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index 588a213e197..2c7709bc2e8 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -895,7 +895,7 @@ class PyLoweringContext { xla::XlaBuilder* local_builder = lowering_ctx.builder(); int64_t parameters_number_i = 2; // for (at::Tensor input_argument : input_arguments) { - for (int i = 0; i < 3; i++) { + for (int i = 0; i < 2; i++) { xla::Shape shape = xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {1}); xla::XlaOp x = xla::Parameter(local_builder, parameters_number_i, shape, @@ -913,9 +913,9 @@ class PyLoweringContext { xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, "WeightTensor"); parameters_number_i = parameters_number_i + 1; - // xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {10}); - // xla::XlaOp x3 = xla::Parameter(local_builder, parameters_number_i, shape3, - // "FinalOneTensor"); + xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {10}); + xla::XlaOp x3 = xla::Parameter(local_builder, parameters_number_i, shape3, + "FinalOneTensor"); } // Get the backing XLA tensors from the output torch tensor handles From 9456f7b3bafeeecaed8948e0c95966bd4978a7b1 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 3 Apr 2024 07:41:30 +0000 Subject: [PATCH 035/323] test --- torch_xla/csrc/init_python_bindings.cpp | 13 +++++++++++++ torch_xla/csrc/lowering_context.cpp | 2 ++ 2 files changed, 15 insertions(+) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index 2c7709bc2e8..42e1205f95b 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -692,6 +692,19 @@ std::vector XlaUserComputation( runtime::ComputationClient::ComputationPtr CreateComputation( const std::string& name, xla::XlaOp root) { + xla::XlaBuilder* local_builder = root.builder(); + int64_t parameters_number_i = 4; + xla::Shape shape1 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); + xla::XlaOp x1 = xla::Parameter(local_builder, parameters_number_i, shape1, + "OutPutTensor"); + parameters_number_i = parameters_number_i + 1; + xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20, 10}); + xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, + "WeightTensor"); + parameters_number_i = parameters_number_i + 1; + xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {10}); + xla::XlaOp x3 = xla::Parameter(local_builder, parameters_number_i, shape3, + "FinalOneTensor"); xla::XlaComputation computation = ConsumeValue(root.builder()->Build(root)); return std::make_shared( name, std::move(computation)); diff --git a/torch_xla/csrc/lowering_context.cpp b/torch_xla/csrc/lowering_context.cpp index a530995ca78..39f82a4887b 100644 --- a/torch_xla/csrc/lowering_context.cpp +++ b/torch_xla/csrc/lowering_context.cpp @@ -160,6 +160,8 @@ xla::StatusOr LoweringContext::BuildXla() { if (!root_tuple_.empty() & (root_tuple_.size() == 1) & ((get_name_string() == "condctx") or (get_name_string() == "bodyctx"))) { xla = builder()->Build(root_tuple_.at(0)); + // } else if (!root_tuple_.empty() & (root_tuple_.size() == 1) & ) { + // xla = builder()->Build(root_tuple_.at(0)); } else if (!root_tuple_.empty()) { xla::XlaOp root = xla::Tuple(builder(), root_tuple_); xla = builder()->Build(root); From 68199fb8e219fe7ea8da757dad7c67084786b81c Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 3 Apr 2024 23:52:59 +0000 Subject: [PATCH 036/323] test --- torch_xla/csrc/init_python_bindings.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index 42e1205f95b..958149b677b 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -702,7 +702,7 @@ runtime::ComputationClient::ComputationPtr CreateComputation( xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, "WeightTensor"); parameters_number_i = parameters_number_i + 1; - xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {10}); + xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {10}); xla::XlaOp x3 = xla::Parameter(local_builder, parameters_number_i, shape3, "FinalOneTensor"); xla::XlaComputation computation = ConsumeValue(root.builder()->Build(root)); @@ -926,7 +926,7 @@ class PyLoweringContext { xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, "WeightTensor"); parameters_number_i = parameters_number_i + 1; - xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {10}); + xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {10}); xla::XlaOp x3 = xla::Parameter(local_builder, parameters_number_i, shape3, "FinalOneTensor"); } From f69403838133703e92f06855244fc0c6fa3f9be6 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Thu, 4 Apr 2024 00:23:44 +0000 Subject: [PATCH 037/323] test --- torch_xla/csrc/init_python_bindings.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index 958149b677b..5f4241e603d 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -915,7 +915,7 @@ class PyLoweringContext { "UnusedArgumentsPlaceholder"); parameters_number_i = parameters_number_i + 1; } - // hard-code to meet requirement + // hard-code to meet requirement by change cond xlacomputation // f32[20], /*index=5*/f32[20,10], s32[10] // parameters_number_i = parameters_number_i + 1; xla::Shape shape1 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); @@ -926,7 +926,7 @@ class PyLoweringContext { xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, "WeightTensor"); parameters_number_i = parameters_number_i + 1; - xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {10}); + xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {10}); xla::XlaOp x3 = xla::Parameter(local_builder, parameters_number_i, shape3, "FinalOneTensor"); } From f8b4cb1103b90603dd52857a067057b3881d06d6 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Thu, 4 Apr 2024 00:28:14 +0000 Subject: [PATCH 038/323] test --- torch_xla/csrc/init_python_bindings.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index 5f4241e603d..a83824e856b 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -693,18 +693,18 @@ std::vector XlaUserComputation( runtime::ComputationClient::ComputationPtr CreateComputation( const std::string& name, xla::XlaOp root) { xla::XlaBuilder* local_builder = root.builder(); - int64_t parameters_number_i = 4; - xla::Shape shape1 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); - xla::XlaOp x1 = xla::Parameter(local_builder, parameters_number_i, shape1, - "OutPutTensor"); - parameters_number_i = parameters_number_i + 1; - xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20, 10}); - xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, - "WeightTensor"); - parameters_number_i = parameters_number_i + 1; - xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {10}); - xla::XlaOp x3 = xla::Parameter(local_builder, parameters_number_i, shape3, - "FinalOneTensor"); + // int64_t parameters_number_i = 4; + // xla::Shape shape1 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); + // xla::XlaOp x1 = xla::Parameter(local_builder, parameters_number_i, shape1, + // "OutPutTensor"); + // parameters_number_i = parameters_number_i + 1; + // xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20, 10}); + // xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, + // "WeightTensor"); + // parameters_number_i = parameters_number_i + 1; + // xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {10}); + // xla::XlaOp x3 = xla::Parameter(local_builder, parameters_number_i, shape3, + // "FinalOneTensor"); xla::XlaComputation computation = ConsumeValue(root.builder()->Build(root)); return std::make_shared( name, std::move(computation)); From 0e16a6ed8355b7b4c817601e8d4b1c6cd7934b8f Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Thu, 4 Apr 2024 01:09:25 +0000 Subject: [PATCH 039/323] test --- torch_xla/experimental/fori_loop.py | 1 + 1 file changed, 1 insertion(+) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 715a94cd4be..9ec4d2923b8 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -61,6 +61,7 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): fake_carried_inputs = [] for carried_input in carried_inputs: device = carried_input.device + print("type carried_input: ", type(carried_input)) #TODO(@manfei) type = carried_input.type fake_carried_inputs.append( torch.randint(10, carried_input.size(), From ce49ba9d18315a7679fdeead6d62fbb5d4ed8cc3 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Thu, 4 Apr 2024 01:11:11 +0000 Subject: [PATCH 040/323] test --- torch_xla/experimental/fori_loop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 9ec4d2923b8..69c7871c052 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -61,7 +61,7 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): fake_carried_inputs = [] for carried_input in carried_inputs: device = carried_input.device - print("type carried_input: ", type(carried_input)) + print("type carried_input: ", carried_input.type) #TODO(@manfei) type = carried_input.type fake_carried_inputs.append( torch.randint(10, carried_input.size(), From 58967a88e710dac2ac9efb58a313906088573b9e Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Thu, 4 Apr 2024 01:13:15 +0000 Subject: [PATCH 041/323] test --- torch_xla/experimental/fori_loop.py | 1 + 1 file changed, 1 insertion(+) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 69c7871c052..f9cae9f73db 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -62,6 +62,7 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): for carried_input in carried_inputs: device = carried_input.device print("type carried_input: ", carried_input.type) + print("is torch.int32: ", carried_input.type==torch.int32) #TODO(@manfei) type = carried_input.type fake_carried_inputs.append( torch.randint(10, carried_input.size(), From 9b0d8e86863aa0a6063a082a5b133e9ae746f9dc Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Thu, 4 Apr 2024 01:14:58 +0000 Subject: [PATCH 042/323] test --- torch_xla/experimental/fori_loop.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index f9cae9f73db..e72b3791da4 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -61,8 +61,8 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): fake_carried_inputs = [] for carried_input in carried_inputs: device = carried_input.device - print("type carried_input: ", carried_input.type) - print("is torch.int32: ", carried_input.type==torch.int32) + print("type carried_input: ", carried_input.dtype) + print("is torch.int32: ", carried_input.dtype==torch.int32) #TODO(@manfei) type = carried_input.type fake_carried_inputs.append( torch.randint(10, carried_input.size(), From 79261794f9915cd3a73be18c3190583af6f80ce2 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Thu, 4 Apr 2024 01:15:59 +0000 Subject: [PATCH 043/323] test --- torch_xla/experimental/fori_loop.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index e72b3791da4..dc93999b5f1 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -61,8 +61,8 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): fake_carried_inputs = [] for carried_input in carried_inputs: device = carried_input.device - print("type carried_input: ", carried_input.dtype) - print("is torch.int32: ", carried_input.dtype==torch.int32) + # print("type carried_input: ", carried_input.dtype) + # print("is torch.int32: ", carried_input.dtype==torch.int32) #TODO(@manfei) type = carried_input.type fake_carried_inputs.append( torch.randint(10, carried_input.size(), From b9e2be1ee37528f7936bafe598606e3e6c8884c6 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Thu, 4 Apr 2024 01:18:34 +0000 Subject: [PATCH 044/323] test --- torch_xla/csrc/init_python_bindings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index a83824e856b..b84a6ecac78 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -926,7 +926,7 @@ class PyLoweringContext { xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, "WeightTensor"); parameters_number_i = parameters_number_i + 1; - xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {10}); + xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {10}); xla::XlaOp x3 = xla::Parameter(local_builder, parameters_number_i, shape3, "FinalOneTensor"); } From cb41d9b75374daafb1b53b840c7fc0e97d2743f0 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 5 Apr 2024 05:58:00 +0000 Subject: [PATCH 045/323] test --- torch_xla/csrc/init_python_bindings.cpp | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index b84a6ecac78..4d2f0e905dd 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -966,6 +966,32 @@ class PyLoweringContext { "UnusedArgumentsPlaceholder"); parameter_idx += 1; } + // hard-code to meet requirement by change cond xlacomputation + // f32[20], /*index=5*/f32[20,10], s32[10] + // parameters_number_i = parameters_number_i + 1; + xla::Shape shape1 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); + xla::XlaOp x1 = xla::Parameter(local_builder, parameters_number_i, shape1, + "BiasTensor"); + parameters_number_i = parameters_number_i + 1; + xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20, 10}); + xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, + "WeightTensor"); + parameters_number_i = parameters_number_i + 1; + xla::Shape shape4 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {10}); + xla::XlaOp x4 = xla::Parameter(local_builder, parameters_number_i, shape4, + "LInITensor"); + parameters_number_i = parameters_number_i + 1; + xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); + xla::XlaOp x3 = xla::Parameter(local_builder, parameters_number_i, shape3, + "LOutTensor"); + } + + if (GetNameString() == "bodyctx") { + xla::XlaBuilder* local_builder = lowering_ctx.builder(); + int64_t parameters_number_i = 7; + xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); + xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, + "WeightTensor"); } // Get the backing XLA tensors from the output torch tensor handles From 2695cfda8252561f338a9cf7647da10395a50b14 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 10 Apr 2024 19:57:28 +0000 Subject: [PATCH 046/323] test --- test/test_fori_loop_simple_linear_model_test_code.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_fori_loop_simple_linear_model_test_code.py b/test/test_fori_loop_simple_linear_model_test_code.py index 006b602f001..39ffffccf41 100644 --- a/test/test_fori_loop_simple_linear_model_test_code.py +++ b/test/test_fori_loop_simple_linear_model_test_code.py @@ -49,6 +49,8 @@ def body_fun(y, x, l_in_i): # TODO(@manfei), need to create new variable to seperate old/formal HLO/IR l_in_0 = torch.randn(10, device=xm.xla_device()) +print("body_fun.weight: ", body_fun.weight) +print("body_fun.weight_: ", body_fun.weight_) # def body_fun(x, y, l_in): # # l_in = torch.randn(10, device=xm.xla_device()) # linear = torch.nn.Linear(10, 20).to(xm.xla_device()) From 7dd5843241cef4c28c9a7abe5b2b79386fd7c772 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 10 Apr 2024 22:38:47 +0000 Subject: [PATCH 047/323] test --- test/test_fori_loop_simple_linear_model_test_code.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_simple_linear_model_test_code.py b/test/test_fori_loop_simple_linear_model_test_code.py index 39ffffccf41..ce03fccdbb8 100644 --- a/test/test_fori_loop_simple_linear_model_test_code.py +++ b/test/test_fori_loop_simple_linear_model_test_code.py @@ -24,8 +24,10 @@ # --- while test case --- -lower = torch.tensor([2], dtype=torch.int32, device=device) -upper = torch.tensor([52], dtype=torch.int32, device=device) +# lower = torch.tensor([2], dtype=torch.int32, device=device) +# upper = torch.tensor([52], dtype=torch.int32, device=device) +lower = torch.tensor([52], dtype=torch.int32, device=device) +upper = torch.tensor([2], dtype=torch.int32, device=device) one_value = torch.tensor([1], dtype=torch.int32, device=device) init_val = torch.tensor([1], dtype=torch.int32, device=device) # one_one = torch.one(1, dtype=torch.int32, device=device) From 535797e186f81161fce08415db1b198886e01b91 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Thu, 11 Apr 2024 04:33:51 +0000 Subject: [PATCH 048/323] test --- torch_xla/experimental/fori_loop.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index dc93999b5f1..4035e207f11 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -94,9 +94,9 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): body_hlo = body_ctx.hlo() body_computation = xb.computation_from_module_proto("bodycomputation", body_hlo) - body_hlo_print = xb.get_computation_hlo(body_computation) - print("body computation: !!!!!!!!!") - print(body_hlo_print) + # body_hlo_print = xb.get_computation_hlo(body_computation) + # print("body computation: !!!!!!!!!") + # print(body_hlo_print) # trans fake_carried_inputs from list(tensor) to list(xla::op), which part could change init of xla::while kwargs = {} From 99709006756c3d553bbe85b349d871dc32a57287 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Thu, 11 Apr 2024 05:10:37 +0000 Subject: [PATCH 049/323] test --- test/test_fori_loop_simple_linear_model_test_code.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/test_fori_loop_simple_linear_model_test_code.py b/test/test_fori_loop_simple_linear_model_test_code.py index ce03fccdbb8..066eb34e91e 100644 --- a/test/test_fori_loop_simple_linear_model_test_code.py +++ b/test/test_fori_loop_simple_linear_model_test_code.py @@ -20,7 +20,11 @@ # l_in = torch.randn(10, device=xm.xla_device()) # linear = torch.nn.Linear(10, 20).to(xm.xla_device()) # l_out = linear(l_in) +<<<<<<< HEAD # print("linear one: ", l_out) +======= +# print("$$$ linear one: ", l_out) +>>>>>>> test # --- while test case --- From f3a9df20e2d2034f2b67340144265fd626e2d5ba Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Thu, 11 Apr 2024 07:16:58 +0000 Subject: [PATCH 050/323] test --- torch_xla/experimental/fori_loop.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 4035e207f11..78afdb10802 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -72,7 +72,7 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): # generate cond_fn xlacomputation # TODO(@manfei): specify which element is for which argument like a,b,c - cond_result = cond_fn(*fake_carried_inputs[:-3], weight_0=fake_carried_inputs[-3], output_value=fake_carried_inputs[-2], bias_0=fake_carried_inputs[-1]) + cond_result = cond_fn(*fake_carried_inputs[:-3], weight_0=fake_carried_inputs[-3], bias_0=fake_carried_inputs[-2], output_value=fake_carried_inputs[-1]) cond_ctx = torch_xla._XLAC.lowering.LoweringContext() cond_ctx.set_name_string("condctx") additional_inputs_list = list(fake_carried_inputs[2:]) @@ -87,7 +87,7 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): print(cond_hlo_print) # generate body_fn xlacomputation - body_result = body_fn(*fake_carried_inputs[:-3], weight_0=fake_carried_inputs[-3], output_value=fake_carried_inputs[-2], bias_0=fake_carried_inputs[-1]) + body_result = body_fn(*fake_carried_inputs[:-3], weight_0=fake_carried_inputs[-3], bias_0=fake_carried_inputs[-2], output_value=fake_carried_inputs[-1]) body_ctx = torch_xla._XLAC.lowering.LoweringContext() body_ctx.set_name_string("bodyctx") body_ctx.buildforiloop(list(body_result), []) From a671982d582dfd9e8da5717e3e43a208f40435ef Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Thu, 11 Apr 2024 20:54:56 +0000 Subject: [PATCH 051/323] test --- torch_xla/csrc/init_python_bindings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index 4d2f0e905dd..8e1a800b316 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -988,7 +988,7 @@ class PyLoweringContext { if (GetNameString() == "bodyctx") { xla::XlaBuilder* local_builder = lowering_ctx.builder(); - int64_t parameters_number_i = 7; + int64_t parameters_number_i = 6; // 7; xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, "WeightTensor"); From d143181dd8df7c950a6545553f0fd0df92f11f3f Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Thu, 11 Apr 2024 21:12:56 +0000 Subject: [PATCH 052/323] test --- torch_xla/csrc/init_python_bindings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index 8e1a800b316..4d2f0e905dd 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -988,7 +988,7 @@ class PyLoweringContext { if (GetNameString() == "bodyctx") { xla::XlaBuilder* local_builder = lowering_ctx.builder(); - int64_t parameters_number_i = 6; // 7; + int64_t parameters_number_i = 7; xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, "WeightTensor"); From 7128f70fe0d49eb9a2b8f6fa29f3ffb90ab63f34 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Thu, 11 Apr 2024 21:42:25 +0000 Subject: [PATCH 053/323] test --- test/test_fori_loop_simple_linear_model_test_code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_simple_linear_model_test_code.py b/test/test_fori_loop_simple_linear_model_test_code.py index 066eb34e91e..58352e5c548 100644 --- a/test/test_fori_loop_simple_linear_model_test_code.py +++ b/test/test_fori_loop_simple_linear_model_test_code.py @@ -12,7 +12,7 @@ # import torch_xla.core.xla_builder as xb import torch_xla.utils.utils as xu -torch.set_grad_enabled(False) +# torch.set_grad_enabled(False) device = xm.xla_device() From b993c091ca9e6ff27f2512c39b83a77ed02d0f71 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Thu, 11 Apr 2024 21:52:29 +0000 Subject: [PATCH 054/323] test --- ...oop_with_while_loop_simple_add_dispatch_in_torch.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 55a02a55e48..5f8d7ec01b5 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -20,9 +20,13 @@ def _fake_while_loop(cond_fn, body_fn, operands): def _fake_fori_loop(lower, upper, body_fun, *init_val): - (a, b) = init_val - for i in range((upper - lower)[0]): - a = body_fun(a, b) + if len(init_val) > 1: + (a, b) = init_val + for i in range((upper - lower)[0]): + a = body_fun(a, b) + else: + for i in range((upper - lower)[0]): + a = body_fun(*init_val) return a def _fake_fori_loop(lower, upper, body_fun, *init_val): From 99d2d78fb7fd001498357b080cdb4e92e6dad591 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Thu, 11 Apr 2024 21:54:19 +0000 Subject: [PATCH 055/323] test --- ...est_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 5f8d7ec01b5..e1a06b05d7d 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -95,6 +95,7 @@ def test_fori_loop_tpu_addition(self): xm.mark_step() device = xm.xla_device() + torch.set_grad_enabled(False) lower = torch.tensor([2], dtype=torch.int32, device=device) upper = torch.tensor([52], dtype=torch.int32, device=device) From 812c072ae458fb8f4941dfa6917c47fe567d812a Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 00:28:39 +0000 Subject: [PATCH 056/323] rebase --- ...fori_loop_simple_linear_model_test_code.py | 187 ++---------------- ...while_loop_simple_add_dispatch_in_torch.py | 24 +-- torch_xla/experimental/fori_loop.py | 20 +- 3 files changed, 30 insertions(+), 201 deletions(-) diff --git a/test/test_fori_loop_simple_linear_model_test_code.py b/test/test_fori_loop_simple_linear_model_test_code.py index 58352e5c548..07a7636d880 100644 --- a/test/test_fori_loop_simple_linear_model_test_code.py +++ b/test/test_fori_loop_simple_linear_model_test_code.py @@ -1,15 +1,11 @@ import os -# import unittest -# from typing import Callable, Dict, List import torch import torch_xla # We need to import the underlying implementation function to register with the dispatcher import torch_xla.experimental.fori_loop from torch_xla.experimental.fori_loop import fori_loop -# from torch._higher_order_ops.while_loop import while_loop import torch_xla.core.xla_model as xm -# import torch_xla.core.xla_builder as xb import torch_xla.utils.utils as xu # torch.set_grad_enabled(False) @@ -17,181 +13,34 @@ device = xm.xla_device() # --- linear one --- -# l_in = torch.randn(10, device=xm.xla_device()) -# linear = torch.nn.Linear(10, 20).to(xm.xla_device()) -# l_out = linear(l_in) -<<<<<<< HEAD -# print("linear one: ", l_out) -======= -# print("$$$ linear one: ", l_out) ->>>>>>> test +l_in = torch.randn(10, device=xm.xla_device()) +linear = torch.nn.Linear(10, 20).to(xm.xla_device()) +l_out = linear(l_in) +print("$$$ different linear model with different weight/bias: ") +print(l_out) # --- while test case --- - -# lower = torch.tensor([2], dtype=torch.int32, device=device) -# upper = torch.tensor([52], dtype=torch.int32, device=device) -lower = torch.tensor([52], dtype=torch.int32, device=device) -upper = torch.tensor([2], dtype=torch.int32, device=device) -one_value = torch.tensor([1], dtype=torch.int32, device=device) +upper = torch.tensor([52], dtype=torch.int32, device=device) +lower = torch.tensor([0], dtype=torch.int32, device=device) init_val = torch.tensor([1], dtype=torch.int32, device=device) -# one_one = torch.one(1, dtype=torch.int32, device=device) - -# def body_fun(l_in): -# # l_in = torch.randn(10, device=xm.xla_device()) -# linear = torch.nn.Linear(10, 20).to(xm.xla_device()) -# # l_out = linear(l_in) -# return linear(l_in) # torch.add(a, b) # [0]) linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) -def body_fun(y, x, l_in_i): - # l_in = torch.randn(10, device=xm.xla_device()) - # linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) - l_out = linear_0(l_in_i) - # placeholder_func = torch.rand(size = l_out.size(), device = device) - # placeholder_input = torch.rand(size = l_in_i.size(), device = device) - # return torch.add(y, x), l_out, placeholder_func, placeholder_input # linear_0(l_in_i), linear_0, l_in_i # additional return: body and input-placeholder # linear(l_in) # torch.add(a, b) # [0]) - return torch.add(y, x), l_out +# def body_fun(l_in_i): +# l_out = linear_0(l_in_i) +# return l_out -# TODO(@manfei), need to create new variable to seperate old/formal HLO/IR l_in_0 = torch.randn(10, device=xm.xla_device()) -print("body_fun.weight: ", body_fun.weight) -print("body_fun.weight_: ", body_fun.weight_) -# def body_fun(x, y, l_in): -# # l_in = torch.randn(10, device=xm.xla_device()) -# linear = torch.nn.Linear(10, 20).to(xm.xla_device()) -# # l_out = linear(l_in) -# return torch.add(x, y), linear(l_in) # linear(l_in) # torch.add(a, b) # [0]) - -# placeholder_func = torch.rand(size = l_out.size(), device = device) -# placeholder_input = torch.rand(size = l_in_i.size(), device = device) -print("test code, body_fun: ", body_fun) - -lower_, upper_, res_ = fori_loop(upper, lower, body_fun, one_value, init_val, l_in_0) # , placeholder_func, placeholder_input) # , linear_0, l_in_0) - -print("lower_: ", lower_) -print("upper_: ", upper_) -print("res_: ", res_) - -# --- linear two --- -# l_in_2 = torch.randn(10, device=xm.xla_device()) -# linear_2 = torch.nn.Linear(10, 20).to(xm.xla_device()) -# l_out_2 = linear(l_in_2) -# print("linear two: ", l_out_2) - -# ================================================================================= - -# import numpy as np -# # create dummy data for training -# # x_values = [i for i in range(11)] -# # x_train = np.array(x_values, dtype=np.float32) -# # x_train = x_train.reshape(-1, 1) - -# # y_values = [2*i + 1 for i in x_values] -# # y_train = np.array(y_values, dtype=np.float32) -# # y_train = y_train.reshape(-1, 1) - -# batch_size = 2 - -# train_loader = xu.SampleGenerator( -# data=(torch.zeros(batch_size, 1), torch.zeros(batch_size, dtype=torch.float32)), -# sample_count=64 // batch_size // xm.xrt_world_size()) -# test_loader = xu.SampleGenerator( -# data=(torch.zeros(batch_size, 1, torch.zeros(batch_size, dtype=torch.float32)), -# sample_count=32 // batch_size // xm.xrt_world_size()) - -# # import torch -# from torch.autograd import Variable - -# class linearRegression(torch.nn.Module): -# def __init__(self, inputSize, outputSize): -# super(linearRegression, self).__init__() -# self.linear = torch.nn.Linear(inputSize, outputSize).to(device) - -# def forward(self, x): -# out = self.linear(x) -# return out - -# # --- training --- -# inputDim = 1 # takes variable 'x' -# outputDim = 1 # takes variable 'y' -# learningRate = 0.01 * xm.xrt_world_size() -# epochs = 10 # 100 - -# model = linearRegression(inputDim, outputDim).to(device) -# # model = MNIST().to(device) -# ##### For GPU ####### -# # if torch.cuda.is_available(): -# # model.cuda() - -# if xr.using_pjrt(): -# xm.broadcast_master_param(model) - -# criterion = torch.nn.MSELoss() -# optimizer = torch.optim.SGD(model.parameters(), lr=learningRate) - -# for epoch in range(epochs): -# # Converting inputs and labels to Variable -# # if torch.cuda.is_available(): -# # inputs = Variable(torch.from_numpy(x_train).cuda()) -# # labels = Variable(torch.from_numpy(y_train).cuda()) -# # else: -# inputs = Variable(torch.from_numpy(x_train)).to(device) -# labels = Variable(torch.from_numpy(y_train)).to(device) - -# # Clear gradient buffers because we don't want any gradient from previous epoch to carry forward, dont want to cummulate gradients -# optimizer.zero_grad() - -# # get output from the model, given the inputs -# outputs = model(inputs) - -# # get loss for the predicted output -# loss = criterion(outputs, labels) -# print(loss) -# # get gradients w.r.t to parameters -# loss.backward() - -# # update parameters -# # optimizer.step() -# xm.optimizer_step(optimizer) - -# print('epoch {}, loss {}'.format(epoch, loss.item())) - -# # --- while simple test case --- - -# # device = xm.xla_device() - -# lower = torch.tensor([2], dtype=torch.int32, device=device) -# upper = torch.tensor([52], dtype=torch.int32, device=device) -# one_value = torch.tensor([1], dtype=torch.int32, device=device) -# init_val = torch.tensor([1], dtype=torch.int32, device=device) - -# def body_fun(a, b): -# return torch.add(a, b) # [0]) - -# lower_, upper_, res_ = fori_loop(upper, lower, body_fun, one_value, init_val) - -# print("lower_: ", lower_) -# print("upper_: ", upper_) -# print("res_: ", res_) +upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_= fori_loop(upper, lower, linear_0, init_val, l_in_0) -# # --- test --- -# for epoch in range(epochs): -# with torch.no_grad(): # we don't need gradients in the testing phase -# if torch.cuda.is_available(): -# predicted = model(Variable(torch.from_numpy(x_train).cuda())).cpu().data.numpy() -# else: -# predicted = model(Variable(torch.from_numpy(x_train))).data.numpy() -# print(epoch, "-th prediction finised") # ed result: ", predicted) +print("$$$ fori_loop l_out_: ") +print(l_out_) -# print("do one more prediction") -# with torch.no_grad(): # we don't need gradients in the testing phase -# if torch.cuda.is_available(): -# predicted = model(Variable(torch.from_numpy(x_train).cuda())).cpu().data.numpy() -# else: -# predicted = model(Variable(torch.from_numpy(x_train))).data.numpy() -# print(predicted) -# print("finished one more prediction") +range_num = upper - lower +for i in range(range_num[0]): + l_out_expected = linear_0(l_in_0) +print("$$$ without-fori_loop l_out_: ") +print(l_out_expected) # # --- draw --- # # plt.clf() diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index e1a06b05d7d..0bc5013438d 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -29,11 +29,6 @@ def _fake_fori_loop(lower, upper, body_fun, *init_val): a = body_fun(*init_val) return a -def _fake_fori_loop(lower, upper, body_fun, *init_val): - (plus_value, init_val) = init_val - for i in range((upper - lower)[0]): - plus_value, init_val = body_fun(plus_value, init_val) - return init_val class WhileLoopTest(unittest.TestCase): @@ -91,25 +86,24 @@ def body_fun(a, b): expected = _fake_fori_loop(lower, upper, body_fun, init_val, one_value) self.assertEqual(expected, res_) - def test_fori_loop_tpu_addition(self): + def test_fori_loop_tpu_simple_linear(self): xm.mark_step() device = xm.xla_device() torch.set_grad_enabled(False) - lower = torch.tensor([2], dtype=torch.int32, device=device) upper = torch.tensor([52], dtype=torch.int32, device=device) - plus_value = torch.tensor([1], dtype=torch.int32, device=device) + lower = torch.tensor([0], dtype=torch.int32, device=device) init_val = torch.tensor([1], dtype=torch.int32, device=device) + l_in_0 = torch.randn(10, device=xm.xla_device()) + + linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) - def body_fun(*argus): - plus_value, init_val = argus - return plus_value, torch.add(plus_value, init_val) - - _, _, _, actual = fori_loop(upper, lower, body_fun, plus_value, init_val) - expected = _fake_fori_loop(lower, upper, body_fun, plus_value, init_val) - self.assertEqual(expected, actual) + upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_= fori_loop(upper, lower, linear_0, init_val, l_in_0) + + expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) + self.assertTrue(torch.all(torch.eq(expected, l_out_))) if __name__ == '__main__': test = unittest.main() diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 78afdb10802..57f7162bf3f 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -52,27 +52,22 @@ def while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): return _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=additional_inputs) # a=a, b=b, c=c, -def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): - print("carried_inputs: ", carried_inputs) - print("additional_inputs: ", additional_inputs) +def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs): # untuple carried_inputs from while_loop carried_inputs = carried_inputs[0] # fake carried_inputs to split formal code fake_carried_inputs = [] for carried_input in carried_inputs: device = carried_input.device - # print("type carried_input: ", carried_input.dtype) - # print("is torch.int32: ", carried_input.dtype==torch.int32) #TODO(@manfei) type = carried_input.type fake_carried_inputs.append( torch.randint(10, carried_input.size(), dtype=carried_input.dtype).to(device)) fake_carried_inputs = tuple(fake_carried_inputs) - print("fake_carried_inputs: ", fake_carried_inputs) # generate cond_fn xlacomputation # TODO(@manfei): specify which element is for which argument like a,b,c - cond_result = cond_fn(*fake_carried_inputs[:-3], weight_0=fake_carried_inputs[-3], bias_0=fake_carried_inputs[-2], output_value=fake_carried_inputs[-1]) + cond_result = cond_fn(*fake_carried_inputs[:-3], weight_0=fake_carried_inputs[-3], output_value=fake_carried_inputs[-2], bias_0=fake_carried_inputs[-1]) cond_ctx = torch_xla._XLAC.lowering.LoweringContext() cond_ctx.set_name_string("condctx") additional_inputs_list = list(fake_carried_inputs[2:]) @@ -82,21 +77,15 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): cond_hlo = cond_ctx.hlo() cond_computation = xb.computation_from_module_proto("condcomputation", cond_hlo) - cond_hlo_print = xb.get_computation_hlo(cond_computation) - print("cond computation: !!!!!!!!!") - print(cond_hlo_print) # generate body_fn xlacomputation - body_result = body_fn(*fake_carried_inputs[:-3], weight_0=fake_carried_inputs[-3], bias_0=fake_carried_inputs[-2], output_value=fake_carried_inputs[-1]) + body_result = body_fn(*fake_carried_inputs[:-3], weight_0=fake_carried_inputs[-3], output_value=fake_carried_inputs[-2], bias_0=fake_carried_inputs[-1]) body_ctx = torch_xla._XLAC.lowering.LoweringContext() body_ctx.set_name_string("bodyctx") body_ctx.buildforiloop(list(body_result), []) body_hlo = body_ctx.hlo() body_computation = xb.computation_from_module_proto("bodycomputation", body_hlo) - # body_hlo_print = xb.get_computation_hlo(body_computation) - # print("body computation: !!!!!!!!!") - # print(body_hlo_print) # trans fake_carried_inputs from list(tensor) to list(xla::op), which part could change init of xla::while kwargs = {} @@ -118,9 +107,6 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): body_computation=body_computation) name = 'fori_loop_ed_torch_func' computation = w.build(name) - hlo_print = xb.get_computation_hlo(computation) - print("while computation: !!!!!!!!!") - print(hlo_print) # gain final result with generated while xlacomputation result = torch_xla._XLAC._xla_user_computation('xla::_op_test_while', From 89dd1e8d05fd4882615c64bc52e76498c49f7d47 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 00:32:45 +0000 Subject: [PATCH 057/323] update --- torch_xla/csrc/init_python_bindings.cpp | 115 ++++++++++-------------- 1 file changed, 46 insertions(+), 69 deletions(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index 4d2f0e905dd..94c84213fe6 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -120,8 +120,6 @@ void PrepareToExit() { runtime::ComputationClient* client = runtime::GetComputationClientIfInitialized(); if (client != nullptr) { - auto xla_device = GetDeviceOrCurrent(""); - SetAllReduceToken(xla_device, nullptr); XLAGraphExecutor::Get()->WaitDeviceOps({}); } } @@ -464,13 +462,12 @@ void SyncLiveTensors(const std::string& device_str, } void StepMarker(const std::string& device_str, - const std::vector& devices, bool wait, - bool reset_scope) { + const std::vector& devices, bool wait) { tsl::profiler::TraceMe activity("StepMarker", tsl::profiler::TraceMeLevel::kInfo); torch::lazy::BackendDevice device = GetDeviceOrCurrent(device_str); XLAGraphExecutor::Get()->SyncLiveTensorsGraph(&device, devices, wait); - XLAGraphExecutor::Get()->MarkStep(device, reset_scope); + XLAGraphExecutor::Get()->MarkStep(device); bool debug_mode = runtime::sys_util::GetEnvBool("PT_XLA_DEBUG", false); if (TF_PREDICT_FALSE(debug_mode)) { std::string report = runtime::metrics::CreatePerformanceReport( @@ -902,35 +899,7 @@ class PyLoweringContext { : lowering_ctx("PyLoweringContext", device) {} // Builds a HLO graph given a set of output tensors. - void Build(std::vector tensors, - std::vector input_arguments = {}) { - if (GetNameString() == "condctx") { - xla::XlaBuilder* local_builder = lowering_ctx.builder(); - int64_t parameters_number_i = 2; - // for (at::Tensor input_argument : input_arguments) { - for (int i = 0; i < 2; i++) { - xla::Shape shape = - xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {1}); - xla::XlaOp x = xla::Parameter(local_builder, parameters_number_i, shape, - "UnusedArgumentsPlaceholder"); - parameters_number_i = parameters_number_i + 1; - } - // hard-code to meet requirement by change cond xlacomputation - // f32[20], /*index=5*/f32[20,10], s32[10] - // parameters_number_i = parameters_number_i + 1; - xla::Shape shape1 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); - xla::XlaOp x1 = xla::Parameter(local_builder, parameters_number_i, shape1, - "OutPutTensor"); - parameters_number_i = parameters_number_i + 1; - xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20, 10}); - xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, - "WeightTensor"); - parameters_number_i = parameters_number_i + 1; - xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {10}); - xla::XlaOp x3 = xla::Parameter(local_builder, parameters_number_i, shape3, - "FinalOneTensor"); - } - + void Build(std::vector tensors) { // Get the backing XLA tensors from the output torch tensor handles std::vector xtensors = GetXlaTensors(tensors, /*want_all=*/true); @@ -957,42 +926,60 @@ class PyLoweringContext { std::vector input_arguments = {}) { if (GetNameString() == "condctx") { xla::XlaBuilder* local_builder = lowering_ctx.builder(); - // hard-code parameter_idx to 2 to skip existing upper/lower arguments - int64_t parameter_idx = 2; - for (at::Tensor input_argument : input_arguments) { + int64_t parameters_number_i = 2; + // for (at::Tensor input_argument : input_arguments) { + for (int i = 0; i < 2; i++) { xla::Shape shape = xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {1}); - xla::XlaOp x = xla::Parameter(local_builder, parameter_idx, shape, + xla::XlaOp x = xla::Parameter(local_builder, parameters_number_i, shape, "UnusedArgumentsPlaceholder"); - parameter_idx += 1; + parameters_number_i = parameters_number_i + 1; } // hard-code to meet requirement by change cond xlacomputation // f32[20], /*index=5*/f32[20,10], s32[10] // parameters_number_i = parameters_number_i + 1; - xla::Shape shape1 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); + + xla::Shape shape1 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {10}); xla::XlaOp x1 = xla::Parameter(local_builder, parameters_number_i, shape1, - "BiasTensor"); + "LInITensor"); + // xla::Shape shape1 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); + // xla::XlaOp x1 = xla::Parameter(local_builder, parameters_number_i, shape1, + // "BiasTensor"); parameters_number_i = parameters_number_i + 1; xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20, 10}); xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, "WeightTensor"); + // parameters_number_i = parameters_number_i + 1; + // xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); + // xla::XlaOp x3 = xla::Parameter(local_builder, parameters_number_i, shape3, + // "LOutTensor"); + // parameters_number_i = parameters_number_i + 1; + // xla::Shape shape4 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {10}); + // xla::XlaOp x4 = xla::Parameter(local_builder, parameters_number_i, shape4, + // "LInITensor"); + // parameters_number_i = parameters_number_i + 1; + // xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); + // xla::XlaOp x3 = xla::Parameter(local_builder, parameters_number_i, shape3, + // "LOutTensor"); parameters_number_i = parameters_number_i + 1; - xla::Shape shape4 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {10}); + xla::Shape shape4 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); xla::XlaOp x4 = xla::Parameter(local_builder, parameters_number_i, shape4, - "LInITensor"); + "BiasTensor"); parameters_number_i = parameters_number_i + 1; xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); xla::XlaOp x3 = xla::Parameter(local_builder, parameters_number_i, shape3, "LOutTensor"); + // // input_value!!!, weight_0, output_value, bias!!! } - if (GetNameString() == "bodyctx") { - xla::XlaBuilder* local_builder = lowering_ctx.builder(); - int64_t parameters_number_i = 7; - xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); - xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, - "WeightTensor"); - } + // // hard-code modify body xlacomputation input arguments + // if (GetNameString() == "bodyctx") { + // xla::XlaBuilder* local_builder = lowering_ctx.builder(); + // int64_t parameters_number_i = 7; + // xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); + // xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, + // "WeightTensor"); + // } // Get the backing XLA tensors from the output torch tensor handles std::vector xtensors = @@ -1761,12 +1748,11 @@ void InitXlaModuleBindings(py::module m) { m.def( "_xla_step_marker", [](const std::string& device, const std::vector& devices, - bool wait, bool reset_scope) { + bool wait) { NoGilSection nogil; - StepMarker(device, devices, wait, reset_scope); + StepMarker(device, devices, wait); }, - py::arg("device") = "", py::arg("devices"), py::arg("wait") = true, - py::arg("reset_scope") = true); + py::arg("device") = "", py::arg("devices"), py::arg("wait") = true); m.def("_get_stablehlo", [](const std::vector& tensors, const std::string& device, const std::vector& devices, @@ -2389,21 +2375,12 @@ void InitXlaModuleBindings(py::module m) { [](at::Tensor& self, const at::Tensor& source) -> at::Tensor& { return XLANativeFunctions::set_(self, source); }); - m.def("_xla_tpu_custom_call", - [](const std::vector& inputs, const std::string& payload, - const std::vector>& output_shapes, - const std::vector& output_dtypes) - -> std::vector { - std::vector dtypes; - dtypes.reserve(output_dtypes.size()); - for (auto& dtype : output_dtypes) { - dtypes.push_back( - reinterpret_cast(dtype.ptr())->scalar_type); - } - - auto xtensors = tensor_methods::tpu_custom_call( - bridge::GetXlaTensors(inputs), payload, output_shapes, dtypes); - return bridge::AtenFromXlaTensors(xtensors); + m.def("_xla_tpu_custom_call_", + [](const std::vector& outputs, + const std::vector& inputs, const std::string& payload) { + auto x_outputs = bridge::GetXlaTensors(outputs); + return tensor_methods::tpu_custom_call_( + x_outputs, bridge::GetXlaTensors(inputs), payload); }); m.def("_set_xla_custom_op_name_prefix", [](const at::Tensor& input, const std::string& op_name_prefix, From cfbe3a6a2ae9d50eb99e66bd4f14ad745a133a12 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 00:34:02 +0000 Subject: [PATCH 058/323] update --- test/cpp/test_xla_sharding.cpp | 16 ------ ...fori_loop_simple_linear_model_test_code.py | 50 ------------------- 2 files changed, 66 deletions(-) delete mode 100644 test/test_fori_loop_simple_linear_model_test_code.py diff --git a/test/cpp/test_xla_sharding.cpp b/test/cpp/test_xla_sharding.cpp index 167ffd753e7..e1f908b5c80 100644 --- a/test/cpp/test_xla_sharding.cpp +++ b/test/cpp/test_xla_sharding.cpp @@ -435,21 +435,5 @@ TEST_F(XLAShardingTest, PrepareOutputShardingPropagation) { ->HasValue()); } -TEST_F(XLAShardingTest, TestForiLoopAddUnusedParameterInXlaComputation) { - xla::Shape shape = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {}); - // Build simple addition. - xla::XlaBuilder b("builder"); - auto x = xla::Parameter(&b, /*parameter_number=*/0, shape, "p0"); - // Add unused parameter before create xlacomputation - xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {}); - auto zzz = xla::Parameter(&b, /*parameter_number=*/1, shape2, "p1"); - auto y = xla::Add(x, xla::ConstantR0(&b, 3)); - xla::XlaComputation xla_computation = - ConsumeValue(b.Build(/*remove_dynamic_dimensions=*/false)); - - // Check whether the unused parameter has been included into xlacomputation - EXPECT_EQ(xla_computation.GetProgramShape()->parameters_size(), 2); -} - } // namespace cpp_test } // namespace torch_xla diff --git a/test/test_fori_loop_simple_linear_model_test_code.py b/test/test_fori_loop_simple_linear_model_test_code.py deleted file mode 100644 index 07a7636d880..00000000000 --- a/test/test_fori_loop_simple_linear_model_test_code.py +++ /dev/null @@ -1,50 +0,0 @@ -import os - -import torch -import torch_xla -# We need to import the underlying implementation function to register with the dispatcher -import torch_xla.experimental.fori_loop -from torch_xla.experimental.fori_loop import fori_loop -import torch_xla.core.xla_model as xm -import torch_xla.utils.utils as xu - -# torch.set_grad_enabled(False) - -device = xm.xla_device() - -# --- linear one --- -l_in = torch.randn(10, device=xm.xla_device()) -linear = torch.nn.Linear(10, 20).to(xm.xla_device()) -l_out = linear(l_in) -print("$$$ different linear model with different weight/bias: ") -print(l_out) - -# --- while test case --- -upper = torch.tensor([52], dtype=torch.int32, device=device) -lower = torch.tensor([0], dtype=torch.int32, device=device) -init_val = torch.tensor([1], dtype=torch.int32, device=device) -linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) - -# def body_fun(l_in_i): -# l_out = linear_0(l_in_i) -# return l_out - -l_in_0 = torch.randn(10, device=xm.xla_device()) - -upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_= fori_loop(upper, lower, linear_0, init_val, l_in_0) - -print("$$$ fori_loop l_out_: ") -print(l_out_) - -range_num = upper - lower -for i in range(range_num[0]): - l_out_expected = linear_0(l_in_0) -print("$$$ without-fori_loop l_out_: ") -print(l_out_expected) - -# # --- draw --- -# # plt.clf() -# # plt.plot(x_train, y_train, 'go', label='True data', alpha=0.5) -# # plt.plot(x_train, predicted, '--', label='Predictions', alpha=0.5) -# # plt.legend(loc='best') -# # plt.show() \ No newline at end of file From 4bcfa5089c5d61b29183d081ac96c43a61143b83 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 00:40:04 +0000 Subject: [PATCH 059/323] update --- ...while_loop_simple_add_dispatch_in_torch.py | 3 +- torch_xla/csrc/init_python_bindings.cpp | 94 ++++++++----------- 2 files changed, 39 insertions(+), 58 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 0bc5013438d..830b3ff7df7 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -23,7 +23,8 @@ def _fake_fori_loop(lower, upper, body_fun, *init_val): if len(init_val) > 1: (a, b) = init_val for i in range((upper - lower)[0]): - a = body_fun(a, b) + # a = body_fun(a, b) + a = body_fun(*init_val) else: for i in range((upper - lower)[0]): a = body_fun(*init_val) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index 94c84213fe6..9fa9e89b191 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -120,6 +120,8 @@ void PrepareToExit() { runtime::ComputationClient* client = runtime::GetComputationClientIfInitialized(); if (client != nullptr) { + auto xla_device = GetDeviceOrCurrent(""); + SetAllReduceToken(xla_device, nullptr); XLAGraphExecutor::Get()->WaitDeviceOps({}); } } @@ -462,12 +464,13 @@ void SyncLiveTensors(const std::string& device_str, } void StepMarker(const std::string& device_str, - const std::vector& devices, bool wait) { + const std::vector& devices, bool wait, + bool reset_scope) { tsl::profiler::TraceMe activity("StepMarker", tsl::profiler::TraceMeLevel::kInfo); torch::lazy::BackendDevice device = GetDeviceOrCurrent(device_str); XLAGraphExecutor::Get()->SyncLiveTensorsGraph(&device, devices, wait); - XLAGraphExecutor::Get()->MarkStep(device); + XLAGraphExecutor::Get()->MarkStep(device, reset_scope); bool debug_mode = runtime::sys_util::GetEnvBool("PT_XLA_DEBUG", false); if (TF_PREDICT_FALSE(debug_mode)) { std::string report = runtime::metrics::CreatePerformanceReport( @@ -689,19 +692,6 @@ std::vector XlaUserComputation( runtime::ComputationClient::ComputationPtr CreateComputation( const std::string& name, xla::XlaOp root) { - xla::XlaBuilder* local_builder = root.builder(); - // int64_t parameters_number_i = 4; - // xla::Shape shape1 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); - // xla::XlaOp x1 = xla::Parameter(local_builder, parameters_number_i, shape1, - // "OutPutTensor"); - // parameters_number_i = parameters_number_i + 1; - // xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20, 10}); - // xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, - // "WeightTensor"); - // parameters_number_i = parameters_number_i + 1; - // xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {10}); - // xla::XlaOp x3 = xla::Parameter(local_builder, parameters_number_i, shape3, - // "FinalOneTensor"); xla::XlaComputation computation = ConsumeValue(root.builder()->Build(root)); return std::make_shared( name, std::move(computation)); @@ -926,41 +916,22 @@ class PyLoweringContext { std::vector input_arguments = {}) { if (GetNameString() == "condctx") { xla::XlaBuilder* local_builder = lowering_ctx.builder(); - int64_t parameters_number_i = 2; - // for (at::Tensor input_argument : input_arguments) { + // hard-code parameter_idx to 2 to skip existing upper/lower arguments + int64_t parameter_idx = 2; for (int i = 0; i < 2; i++) { xla::Shape shape = xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {1}); - xla::XlaOp x = xla::Parameter(local_builder, parameters_number_i, shape, + xla::XlaOp x = xla::Parameter(local_builder, parameter_idx, shape, "UnusedArgumentsPlaceholder"); - parameters_number_i = parameters_number_i + 1; + parameter_idx += 1; } - // hard-code to meet requirement by change cond xlacomputation - // f32[20], /*index=5*/f32[20,10], s32[10] - // parameters_number_i = parameters_number_i + 1; - xla::Shape shape1 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {10}); xla::XlaOp x1 = xla::Parameter(local_builder, parameters_number_i, shape1, "LInITensor"); - // xla::Shape shape1 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); - // xla::XlaOp x1 = xla::Parameter(local_builder, parameters_number_i, shape1, - // "BiasTensor"); parameters_number_i = parameters_number_i + 1; xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20, 10}); xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, "WeightTensor"); - // parameters_number_i = parameters_number_i + 1; - // xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); - // xla::XlaOp x3 = xla::Parameter(local_builder, parameters_number_i, shape3, - // "LOutTensor"); - // parameters_number_i = parameters_number_i + 1; - // xla::Shape shape4 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {10}); - // xla::XlaOp x4 = xla::Parameter(local_builder, parameters_number_i, shape4, - // "LInITensor"); - // parameters_number_i = parameters_number_i + 1; - // xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); - // xla::XlaOp x3 = xla::Parameter(local_builder, parameters_number_i, shape3, - // "LOutTensor"); parameters_number_i = parameters_number_i + 1; xla::Shape shape4 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); xla::XlaOp x4 = xla::Parameter(local_builder, parameters_number_i, shape4, @@ -969,17 +940,16 @@ class PyLoweringContext { xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); xla::XlaOp x3 = xla::Parameter(local_builder, parameters_number_i, shape3, "LOutTensor"); - // // input_value!!!, weight_0, output_value, bias!!! } - // // hard-code modify body xlacomputation input arguments - // if (GetNameString() == "bodyctx") { - // xla::XlaBuilder* local_builder = lowering_ctx.builder(); - // int64_t parameters_number_i = 7; - // xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); - // xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, - // "WeightTensor"); - // } + // hard-code modify body xlacomputation input arguments + if (GetNameString() == "bodyctx") { + xla::XlaBuilder* local_builder = lowering_ctx.builder(); + int64_t parameters_number_i = 7; + xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); + xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, + "WeightTensor"); + } // Get the backing XLA tensors from the output torch tensor handles std::vector xtensors = @@ -1748,11 +1718,12 @@ void InitXlaModuleBindings(py::module m) { m.def( "_xla_step_marker", [](const std::string& device, const std::vector& devices, - bool wait) { + bool wait, bool reset_scope) { NoGilSection nogil; - StepMarker(device, devices, wait); + StepMarker(device, devices, wait, reset_scope); }, - py::arg("device") = "", py::arg("devices"), py::arg("wait") = true); + py::arg("device") = "", py::arg("devices"), py::arg("wait") = true, + py::arg("reset_scope") = true); m.def("_get_stablehlo", [](const std::vector& tensors, const std::string& device, const std::vector& devices, @@ -2375,12 +2346,21 @@ void InitXlaModuleBindings(py::module m) { [](at::Tensor& self, const at::Tensor& source) -> at::Tensor& { return XLANativeFunctions::set_(self, source); }); - m.def("_xla_tpu_custom_call_", - [](const std::vector& outputs, - const std::vector& inputs, const std::string& payload) { - auto x_outputs = bridge::GetXlaTensors(outputs); - return tensor_methods::tpu_custom_call_( - x_outputs, bridge::GetXlaTensors(inputs), payload); + m.def("_xla_tpu_custom_call", + [](const std::vector& inputs, const std::string& payload, + const std::vector>& output_shapes, + const std::vector& output_dtypes) + -> std::vector { + std::vector dtypes; + dtypes.reserve(output_dtypes.size()); + for (auto& dtype : output_dtypes) { + dtypes.push_back( + reinterpret_cast(dtype.ptr())->scalar_type); + } + + auto xtensors = tensor_methods::tpu_custom_call( + bridge::GetXlaTensors(inputs), payload, output_shapes, dtypes); + return bridge::AtenFromXlaTensors(xtensors); }); m.def("_set_xla_custom_op_name_prefix", [](const at::Tensor& input, const std::string& op_name_prefix, @@ -2651,4 +2631,4 @@ void InitXlaBindings(py::module m) { InitXlaModuleBindings(m); } } // namespace torch_xla -PYBIND11_MODULE(_XLAC, m) { torch_xla::InitXlaBindings(m); } +PYBIND11_MODULE(_XLAC, m) { torch_xla::InitXlaBindings(m); } \ No newline at end of file From 09eaa3786a743bc068f8d582dd5ae13279d81ffa Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 00:41:51 +0000 Subject: [PATCH 060/323] update --- torch_xla/csrc/init_python_bindings.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index 9fa9e89b191..1fc9ac3ccdb 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -926,28 +926,28 @@ class PyLoweringContext { parameter_idx += 1; } xla::Shape shape1 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {10}); - xla::XlaOp x1 = xla::Parameter(local_builder, parameters_number_i, shape1, + xla::XlaOp x1 = xla::Parameter(local_builder, parameter_idx, shape1, "LInITensor"); - parameters_number_i = parameters_number_i + 1; + parameter_idx = parameter_idx + 1; xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20, 10}); - xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, + xla::XlaOp x2 = xla::Parameter(local_builder, parameter_idx, shape2, "WeightTensor"); - parameters_number_i = parameters_number_i + 1; + parameter_idx = parameter_idx + 1; xla::Shape shape4 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); - xla::XlaOp x4 = xla::Parameter(local_builder, parameters_number_i, shape4, + xla::XlaOp x4 = xla::Parameter(local_builder, parameter_idx, shape4, "BiasTensor"); - parameters_number_i = parameters_number_i + 1; + parameter_idx = parameter_idx + 1; xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); - xla::XlaOp x3 = xla::Parameter(local_builder, parameters_number_i, shape3, + xla::XlaOp x3 = xla::Parameter(local_builder, parameter_idx, shape3, "LOutTensor"); } // hard-code modify body xlacomputation input arguments if (GetNameString() == "bodyctx") { xla::XlaBuilder* local_builder = lowering_ctx.builder(); - int64_t parameters_number_i = 7; + int64_t parameter_idx = 7; xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); - xla::XlaOp x2 = xla::Parameter(local_builder, parameters_number_i, shape2, + xla::XlaOp x2 = xla::Parameter(local_builder, parameter_idx, shape2, "WeightTensor"); } From 88bdb4a6241759dbdcd15341e43b496a690c3206 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 00:51:38 +0000 Subject: [PATCH 061/323] update --- ..._while_loop_simple_add_dispatch_in_torch.py | 18 ++++++++++++++++++ torch_xla/experimental/fori_loop.py | 3 --- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 830b3ff7df7..e84adbaa194 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -69,6 +69,24 @@ def body_fn(init, limit_value): expected = _fake_while_loop(cond_fn, body_fn, (init, limit_value)) self.assertEqual(expected, res) + def test_while_loop_tpu_subtraction_nested(self): + + device = xm.xla_device() + + def cond_fn(init, limit_value): + return limit_value[0] <= init[0] + + def body_fn(init, limit_value): + one_value = torch.ones(1, dtype=torch.int32, device=device) + two_value = limit_value.clone() + return (torch.sub(torch.sub(init, one_value), one_value), two_value) + + init = torch.tensor([10], dtype=torch.int32, device=device) + limit_value = torch.tensor([0], dtype=torch.int32, device=device) + res = while_loop(cond_fn, body_fn, (init, limit_value)) + expected = _fake_while_loop(cond_fn, body_fn, (init, limit_value)) + self.assertEqual(expected, res) + def test_fori_loop_tpu_addition(self): xm.mark_step() diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 57f7162bf3f..8141d777a4e 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -16,9 +16,6 @@ def fori_loop(upper, lower, body_fun, init_val, *input_value): device = xm.xla_device() - # weight_0 = body_fun.weight - # bias_0 = body_fun.bias - # one_value = torch.tensor([1], dtype=torch.int32, device=device) def cond_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bias_0): # , bias_0): # , output_value): return lower[0] < upper[0] From ec5e999fe4689a7cad750c1473e15a92c898333a Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 06:00:18 +0000 Subject: [PATCH 062/323] update --- torch_xla/csrc/init_python_bindings.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index 1fc9ac3ccdb..9a7cd811cb3 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -913,11 +913,29 @@ class PyLoweringContext { // Builds a HLO graph given a set of output tensors, and add unused parameters // needed in xlacomputation. void BuildForiLoop(std::vector tensors, - std::vector input_arguments = {}) { + std::vector additional_inputs_list = {}) { if (GetNameString() == "condctx") { xla::XlaBuilder* local_builder = lowering_ctx.builder(); // hard-code parameter_idx to 2 to skip existing upper/lower arguments - int64_t parameter_idx = 2; + // !!! since cond_fn only compare upper and lower, so it would only use two arguments, due to PyTorch/XLA + // !!! trace xlacomputation from result tensor, so all the other arguments would not be included or generated; + // !!! but to meet xla::while requirement, we would skip first two arguments, + // !!! then add all other arguments like body_fn/init + // !!! --- additional_inputs_list: this list include all other arguments like body_fn/init except upper and lower + // !!! --- next step: we add dump paras according to additional_inputs_list + // ??? --- could we get IRvalue of `additional_inputs_list` in this function to complete xlacomputation? + int64_t parameter_idx = 2; // parameter_idx start from 2 after upper and lower + // ? type, ? shape, + // for (int i = 0; i < additional_inputs_list.size(); i++) { + for (auto& additional_input_tensor : additional_inputs_list) { + XLATensorPtr xtensor = bridge::GetXlaTensor(additional_input_tensor); + xla::Shape shape = xtensor->shape().get().ToString(); + xla::XlaOp x = xla::Parameter(local_builder, parameter_idx, shape, + "UnusedArgumentsPlaceholder"); + parameter_idx += 1; + // xtensor->shape().get().ToString() + // xla_tensor->shaped_buffer().on_device_shape(); + } for (int i = 0; i < 2; i++) { xla::Shape shape = xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {1}); From e870e70ad8d4ce055e3c8d2ec77333e736d3c09e Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 06:04:23 +0000 Subject: [PATCH 063/323] update --- torch_xla/csrc/init_python_bindings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index 9a7cd811cb3..53b55e04601 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -929,7 +929,7 @@ class PyLoweringContext { // for (int i = 0; i < additional_inputs_list.size(); i++) { for (auto& additional_input_tensor : additional_inputs_list) { XLATensorPtr xtensor = bridge::GetXlaTensor(additional_input_tensor); - xla::Shape shape = xtensor->shape().get().ToString(); + xla::Shape shape = xtensor->shape().get(); // .ToString(); xla::XlaOp x = xla::Parameter(local_builder, parameter_idx, shape, "UnusedArgumentsPlaceholder"); parameter_idx += 1; From 349ed260f87d14b6199fd732fde90797701ce0b3 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 06:07:34 +0000 Subject: [PATCH 064/323] update --- torch_xla/csrc/init_python_bindings.cpp | 44 ++++++++++++------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index 53b55e04601..e1df6657574 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -936,28 +936,28 @@ class PyLoweringContext { // xtensor->shape().get().ToString() // xla_tensor->shaped_buffer().on_device_shape(); } - for (int i = 0; i < 2; i++) { - xla::Shape shape = - xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {1}); - xla::XlaOp x = xla::Parameter(local_builder, parameter_idx, shape, - "UnusedArgumentsPlaceholder"); - parameter_idx += 1; - } - xla::Shape shape1 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {10}); - xla::XlaOp x1 = xla::Parameter(local_builder, parameter_idx, shape1, - "LInITensor"); - parameter_idx = parameter_idx + 1; - xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20, 10}); - xla::XlaOp x2 = xla::Parameter(local_builder, parameter_idx, shape2, - "WeightTensor"); - parameter_idx = parameter_idx + 1; - xla::Shape shape4 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); - xla::XlaOp x4 = xla::Parameter(local_builder, parameter_idx, shape4, - "BiasTensor"); - parameter_idx = parameter_idx + 1; - xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); - xla::XlaOp x3 = xla::Parameter(local_builder, parameter_idx, shape3, - "LOutTensor"); + // for (int i = 0; i < 2; i++) { + // xla::Shape shape = + // xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {1}); + // xla::XlaOp x = xla::Parameter(local_builder, parameter_idx, shape, + // "UnusedArgumentsPlaceholder"); + // parameter_idx += 1; + // } + // xla::Shape shape1 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {10}); + // xla::XlaOp x1 = xla::Parameter(local_builder, parameter_idx, shape1, + // "LInITensor"); + // parameter_idx = parameter_idx + 1; + // xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20, 10}); + // xla::XlaOp x2 = xla::Parameter(local_builder, parameter_idx, shape2, + // "WeightTensor"); + // parameter_idx = parameter_idx + 1; + // xla::Shape shape4 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); + // xla::XlaOp x4 = xla::Parameter(local_builder, parameter_idx, shape4, + // "BiasTensor"); + // parameter_idx = parameter_idx + 1; + // xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); + // xla::XlaOp x3 = xla::Parameter(local_builder, parameter_idx, shape3, + // "LOutTensor"); } // hard-code modify body xlacomputation input arguments From 876298a657554dbb76c2f38ade7ad6426db6b932 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 08:22:56 +0000 Subject: [PATCH 065/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- torch_xla/experimental/fori_loop.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index e84adbaa194..c2ed1669e64 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -126,4 +126,4 @@ def test_fori_loop_tpu_simple_linear(self): if __name__ == '__main__': test = unittest.main() - sys.exit(0 if test.result.wasSuccessful() else 1) \ No newline at end of file + sys.exit(0 if test.result.wasSuccessful() else 1) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 8141d777a4e..753c68ba455 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -69,7 +69,7 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs): cond_ctx.set_name_string("condctx") additional_inputs_list = list(fake_carried_inputs[2:]) for i in range(len(additional_inputs)): - additional_inputs_list.append(additional_inputs[0]) + additional_inputs_list.append(additional_inputs[i]) cond_ctx.buildforiloop([cond_result], additional_inputs_list) cond_hlo = cond_ctx.hlo() cond_computation = xb.computation_from_module_proto("condcomputation", From b73dc9629bfc4fcee805eff96ec3c014a1b7501e Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 08:30:33 +0000 Subject: [PATCH 066/323] update --- torch_xla/csrc/init_python_bindings.cpp | 40 ++++++------------------- torch_xla/experimental/fori_loop.py | 9 ++++-- 2 files changed, 16 insertions(+), 33 deletions(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index e1df6657574..27dd7ac3bdf 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -925,48 +925,26 @@ class PyLoweringContext { // !!! --- next step: we add dump paras according to additional_inputs_list // ??? --- could we get IRvalue of `additional_inputs_list` in this function to complete xlacomputation? int64_t parameter_idx = 2; // parameter_idx start from 2 after upper and lower - // ? type, ? shape, - // for (int i = 0; i < additional_inputs_list.size(); i++) { for (auto& additional_input_tensor : additional_inputs_list) { XLATensorPtr xtensor = bridge::GetXlaTensor(additional_input_tensor); - xla::Shape shape = xtensor->shape().get(); // .ToString(); + xla::Shape shape = xtensor->shape().get(); xla::XlaOp x = xla::Parameter(local_builder, parameter_idx, shape, "UnusedArgumentsPlaceholder"); parameter_idx += 1; - // xtensor->shape().get().ToString() - // xla_tensor->shaped_buffer().on_device_shape(); } - // for (int i = 0; i < 2; i++) { - // xla::Shape shape = - // xla::ShapeUtil::MakeShape(xla::PrimitiveType::S32, {1}); - // xla::XlaOp x = xla::Parameter(local_builder, parameter_idx, shape, - // "UnusedArgumentsPlaceholder"); - // parameter_idx += 1; - // } - // xla::Shape shape1 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {10}); - // xla::XlaOp x1 = xla::Parameter(local_builder, parameter_idx, shape1, - // "LInITensor"); - // parameter_idx = parameter_idx + 1; - // xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20, 10}); - // xla::XlaOp x2 = xla::Parameter(local_builder, parameter_idx, shape2, - // "WeightTensor"); - // parameter_idx = parameter_idx + 1; - // xla::Shape shape4 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); - // xla::XlaOp x4 = xla::Parameter(local_builder, parameter_idx, shape4, - // "BiasTensor"); - // parameter_idx = parameter_idx + 1; - // xla::Shape shape3 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); - // xla::XlaOp x3 = xla::Parameter(local_builder, parameter_idx, shape3, - // "LOutTensor"); } // hard-code modify body xlacomputation input arguments if (GetNameString() == "bodyctx") { xla::XlaBuilder* local_builder = lowering_ctx.builder(); - int64_t parameter_idx = 7; - xla::Shape shape2 = xla::ShapeUtil::MakeShape(xla::PrimitiveType::F32, {20}); - xla::XlaOp x2 = xla::Parameter(local_builder, parameter_idx, shape2, - "WeightTensor"); + int64_t parameter_idx = tensors.size(); + for (auto& additional_input_tensor : additional_inputs_list) { + XLATensorPtr xtensor = bridge::GetXlaTensor(additional_input_tensor); + xla::Shape shape = xtensor->shape().get(); + xla::XlaOp x = xla::Parameter(local_builder, parameter_idx, shape, + "UnusedArgumentsPlaceholder"); + parameter_idx += 1; + } } // Get the backing XLA tensors from the output torch tensor handles diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 753c68ba455..88fa371a799 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -67,7 +67,8 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs): cond_result = cond_fn(*fake_carried_inputs[:-3], weight_0=fake_carried_inputs[-3], output_value=fake_carried_inputs[-2], bias_0=fake_carried_inputs[-1]) cond_ctx = torch_xla._XLAC.lowering.LoweringContext() cond_ctx.set_name_string("condctx") - additional_inputs_list = list(fake_carried_inputs[2:]) + additional_inputs_list = list(fake_carried_inputs[2:]) # all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor + # treat and pass additional_inputs to cond_fn for i in range(len(additional_inputs)): additional_inputs_list.append(additional_inputs[i]) cond_ctx.buildforiloop([cond_result], additional_inputs_list) @@ -79,7 +80,11 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs): body_result = body_fn(*fake_carried_inputs[:-3], weight_0=fake_carried_inputs[-3], output_value=fake_carried_inputs[-2], bias_0=fake_carried_inputs[-1]) body_ctx = torch_xla._XLAC.lowering.LoweringContext() body_ctx.set_name_string("bodyctx") - body_ctx.buildforiloop(list(body_result), []) + additional_inputs_list = list(fake_carried_inputs[-2]) # missed arguments due to given output_value was not used and PyTorch/XLA trace xlacomputation from output tensor + # TODO(@manfei): treat and pass additional_inputs to body_fn too + for i in range(len(additional_inputs)): + additional_inputs_list.append(additional_inputs[i]) + body_ctx.buildforiloop(list(body_result), additional_inputs_list) body_hlo = body_ctx.hlo() body_computation = xb.computation_from_module_proto("bodycomputation", body_hlo) From b5accda1bbe8e741e0334a5fa8e650848aa87e9e Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 08:39:07 +0000 Subject: [PATCH 067/323] update --- torch_xla/csrc/init_python_bindings.cpp | 36 ++++++++++++++++--------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index 27dd7ac3bdf..f90a5c11b1e 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -934,18 +934,18 @@ class PyLoweringContext { } } - // hard-code modify body xlacomputation input arguments - if (GetNameString() == "bodyctx") { - xla::XlaBuilder* local_builder = lowering_ctx.builder(); - int64_t parameter_idx = tensors.size(); - for (auto& additional_input_tensor : additional_inputs_list) { - XLATensorPtr xtensor = bridge::GetXlaTensor(additional_input_tensor); - xla::Shape shape = xtensor->shape().get(); - xla::XlaOp x = xla::Parameter(local_builder, parameter_idx, shape, - "UnusedArgumentsPlaceholder"); - parameter_idx += 1; - } - } + // // hard-code modify body xlacomputation input arguments + // if (GetNameString() == "bodyctx") { + // xla::XlaBuilder* local_builder = lowering_ctx.builder(); + // int64_t parameter_idx = tensors.size(); + // for (auto& additional_input_tensor : additional_inputs_list) { + // XLATensorPtr xtensor = bridge::GetXlaTensor(additional_input_tensor); + // xla::Shape shape = xtensor->shape().get(); + // xla::XlaOp x = xla::Parameter(local_builder, parameter_idx, shape, + // "UnusedArgumentsPlaceholder"); + // parameter_idx += 1; + // } + // } // Get the backing XLA tensors from the output torch tensor handles std::vector xtensors = @@ -972,6 +972,18 @@ class PyLoweringContext { std::vector buffer_donor_indices; xla::ProgramShape program_shape = ConsumeValue(computation.GetProgramShape()); + // hard-code modify body xlacomputation input arguments + if (GetNameString() == "bodyctx") { + xla::XlaBuilder* local_builder = lowering_ctx.builder(); + int64_t parameter_idx = program_shape.parameters_size(); // tensors.size(); + for (auto& additional_input_tensor : additional_inputs_list) { + XLATensorPtr xtensor = bridge::GetXlaTensor(additional_input_tensor); + xla::Shape shape = xtensor->shape().get(); + xla::XlaOp x = xla::Parameter(local_builder, parameter_idx, shape, + "UnusedArgumentsPlaceholder"); + parameter_idx += 1; + } + } // TODO(@manfei): please confirm whether we check for more than two or use // default value true bool should_wrap_parameter = (program_shape.parameters_size() >= 2); From 8a1f6ad506a41fadd244786bfbbc57aaad37f82c Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 08:42:25 +0000 Subject: [PATCH 068/323] update --- torch_xla/csrc/init_python_bindings.cpp | 48 ++++++++++++------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index f90a5c11b1e..7ce1ed45075 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -934,18 +934,18 @@ class PyLoweringContext { } } - // // hard-code modify body xlacomputation input arguments - // if (GetNameString() == "bodyctx") { - // xla::XlaBuilder* local_builder = lowering_ctx.builder(); - // int64_t parameter_idx = tensors.size(); - // for (auto& additional_input_tensor : additional_inputs_list) { - // XLATensorPtr xtensor = bridge::GetXlaTensor(additional_input_tensor); - // xla::Shape shape = xtensor->shape().get(); - // xla::XlaOp x = xla::Parameter(local_builder, parameter_idx, shape, - // "UnusedArgumentsPlaceholder"); - // parameter_idx += 1; - // } - // } + // hard-code modify body xlacomputation input arguments + if (GetNameString() == "bodyctx") { + xla::XlaBuilder* local_builder = lowering_ctx.builder(); + int64_t parameter_idx = 7; // tensors.size(); + for (auto& additional_input_tensor : additional_inputs_list) { + XLATensorPtr xtensor = bridge::GetXlaTensor(additional_input_tensor); + xla::Shape shape = xtensor->shape().get(); + xla::XlaOp x = xla::Parameter(local_builder, parameter_idx, shape, + "UnusedArgumentsPlaceholder"); + parameter_idx += 1; + } + } // Get the backing XLA tensors from the output torch tensor handles std::vector xtensors = @@ -972,18 +972,18 @@ class PyLoweringContext { std::vector buffer_donor_indices; xla::ProgramShape program_shape = ConsumeValue(computation.GetProgramShape()); - // hard-code modify body xlacomputation input arguments - if (GetNameString() == "bodyctx") { - xla::XlaBuilder* local_builder = lowering_ctx.builder(); - int64_t parameter_idx = program_shape.parameters_size(); // tensors.size(); - for (auto& additional_input_tensor : additional_inputs_list) { - XLATensorPtr xtensor = bridge::GetXlaTensor(additional_input_tensor); - xla::Shape shape = xtensor->shape().get(); - xla::XlaOp x = xla::Parameter(local_builder, parameter_idx, shape, - "UnusedArgumentsPlaceholder"); - parameter_idx += 1; - } - } + // // hard-code modify body xlacomputation input arguments + // if (GetNameString() == "bodyctx") { + // xla::XlaBuilder* local_builder = lowering_ctx.builder(); + // int64_t parameter_idx = program_shape.parameters_size(); // tensors.size(); + // for (auto& additional_input_tensor : additional_inputs_list) { + // XLATensorPtr xtensor = bridge::GetXlaTensor(additional_input_tensor); + // xla::Shape shape = xtensor->shape().get(); + // xla::XlaOp x = xla::Parameter(local_builder, parameter_idx, shape, + // "UnusedArgumentsPlaceholder"); + // parameter_idx += 1; + // } + // } // TODO(@manfei): please confirm whether we check for more than two or use // default value true bool should_wrap_parameter = (program_shape.parameters_size() >= 2); From 7914abf109fe9399f59d58290f6277c88de24e06 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 08:43:25 +0000 Subject: [PATCH 069/323] update --- torch_xla/csrc/init_python_bindings.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index 7ce1ed45075..145739e1d1a 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -973,6 +973,8 @@ class PyLoweringContext { xla::ProgramShape program_shape = ConsumeValue(computation.GetProgramShape()); // // hard-code modify body xlacomputation input arguments + // // xxx: failed due to not change body_xlacomputation, might becase has been traced + // // xxx: after `computation = ConsumeValue(lowering_ctx.BuildXla());` // if (GetNameString() == "bodyctx") { // xla::XlaBuilder* local_builder = lowering_ctx.builder(); // int64_t parameter_idx = program_shape.parameters_size(); // tensors.size(); From 3da0e431daf640f22c69dd17bf26c217febbef14 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 08:46:08 +0000 Subject: [PATCH 070/323] update --- torch_xla/experimental/fori_loop.py | 1 + 1 file changed, 1 insertion(+) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 88fa371a799..ca1e1e67f08 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -84,6 +84,7 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs): # TODO(@manfei): treat and pass additional_inputs to body_fn too for i in range(len(additional_inputs)): additional_inputs_list.append(additional_inputs[i]) + print("len!!!: ", len(additional_inputs_list)) body_ctx.buildforiloop(list(body_result), additional_inputs_list) body_hlo = body_ctx.hlo() body_computation = xb.computation_from_module_proto("bodycomputation", From 5c5ca2c083d847ef0e7b9f1c9a551294dae7e1a1 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 08:47:05 +0000 Subject: [PATCH 071/323] update --- torch_xla/experimental/fori_loop.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index ca1e1e67f08..5eeb88121f0 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -82,9 +82,11 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs): body_ctx.set_name_string("bodyctx") additional_inputs_list = list(fake_carried_inputs[-2]) # missed arguments due to given output_value was not used and PyTorch/XLA trace xlacomputation from output tensor # TODO(@manfei): treat and pass additional_inputs to body_fn too + print("len0!!!: ", len(additional_inputs_list)) for i in range(len(additional_inputs)): additional_inputs_list.append(additional_inputs[i]) print("len!!!: ", len(additional_inputs_list)) + print("additional_inputs_list: ", additional_inputs_list) body_ctx.buildforiloop(list(body_result), additional_inputs_list) body_hlo = body_ctx.hlo() body_computation = xb.computation_from_module_proto("bodycomputation", From 1c9e92fb47e9ef615ac8f907af1e6035e51a89b4 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 08:51:05 +0000 Subject: [PATCH 072/323] update --- torch_xla/experimental/fori_loop.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 5eeb88121f0..3237ae58a44 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -67,11 +67,11 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs): cond_result = cond_fn(*fake_carried_inputs[:-3], weight_0=fake_carried_inputs[-3], output_value=fake_carried_inputs[-2], bias_0=fake_carried_inputs[-1]) cond_ctx = torch_xla._XLAC.lowering.LoweringContext() cond_ctx.set_name_string("condctx") - additional_inputs_list = list(fake_carried_inputs[2:]) # all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor + additional_inputs_list_cond = list(fake_carried_inputs[2:]) # all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor # treat and pass additional_inputs to cond_fn for i in range(len(additional_inputs)): - additional_inputs_list.append(additional_inputs[i]) - cond_ctx.buildforiloop([cond_result], additional_inputs_list) + additional_inputs_list_cond.append(additional_inputs[i]) + cond_ctx.buildforiloop([cond_result], additional_inputs_list_cond) cond_hlo = cond_ctx.hlo() cond_computation = xb.computation_from_module_proto("condcomputation", cond_hlo) @@ -80,14 +80,14 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs): body_result = body_fn(*fake_carried_inputs[:-3], weight_0=fake_carried_inputs[-3], output_value=fake_carried_inputs[-2], bias_0=fake_carried_inputs[-1]) body_ctx = torch_xla._XLAC.lowering.LoweringContext() body_ctx.set_name_string("bodyctx") - additional_inputs_list = list(fake_carried_inputs[-2]) # missed arguments due to given output_value was not used and PyTorch/XLA trace xlacomputation from output tensor + additional_inputs_list_body = list(fake_carried_inputs[-2]) # missed arguments due to given output_value was not used and PyTorch/XLA trace xlacomputation from output tensor # TODO(@manfei): treat and pass additional_inputs to body_fn too - print("len0!!!: ", len(additional_inputs_list)) + print("len0!!!: ", len(additional_inputs_list_body)) for i in range(len(additional_inputs)): - additional_inputs_list.append(additional_inputs[i]) - print("len!!!: ", len(additional_inputs_list)) - print("additional_inputs_list: ", additional_inputs_list) - body_ctx.buildforiloop(list(body_result), additional_inputs_list) + additional_inputs_list_body.append(additional_inputs[i]) + print("len!!!: ", len(additional_inputs_list_body)) + print("additional_inputs_list_body: ", additional_inputs_list_body) + body_ctx.buildforiloop(list(body_result), additional_inputs_list_body) body_hlo = body_ctx.hlo() body_computation = xb.computation_from_module_proto("bodycomputation", body_hlo) From 52d1c177bd4b5e104002314dd75d99f42aa81c3c Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 08:51:56 +0000 Subject: [PATCH 073/323] update --- torch_xla/experimental/fori_loop.py | 1 + 1 file changed, 1 insertion(+) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 3237ae58a44..d8328176607 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -82,6 +82,7 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs): body_ctx.set_name_string("bodyctx") additional_inputs_list_body = list(fake_carried_inputs[-2]) # missed arguments due to given output_value was not used and PyTorch/XLA trace xlacomputation from output tensor # TODO(@manfei): treat and pass additional_inputs to body_fn too + print("list(fake_carried_inputs[-2]: ", list(fake_carried_inputs[-2]) print("len0!!!: ", len(additional_inputs_list_body)) for i in range(len(additional_inputs)): additional_inputs_list_body.append(additional_inputs[i]) From c4fe1222a8f5d11f90cfa169d04a07def03e94d4 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 08:52:30 +0000 Subject: [PATCH 074/323] update --- torch_xla/experimental/fori_loop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index d8328176607..13a4dbf51ee 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -82,7 +82,7 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs): body_ctx.set_name_string("bodyctx") additional_inputs_list_body = list(fake_carried_inputs[-2]) # missed arguments due to given output_value was not used and PyTorch/XLA trace xlacomputation from output tensor # TODO(@manfei): treat and pass additional_inputs to body_fn too - print("list(fake_carried_inputs[-2]: ", list(fake_carried_inputs[-2]) + print("list(fake_carried_inputs[-2]: ", list(fake_carried_inputs[-2])) print("len0!!!: ", len(additional_inputs_list_body)) for i in range(len(additional_inputs)): additional_inputs_list_body.append(additional_inputs[i]) From 80d20034dd8e19b53c7659971d45b5a9144a29df Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 08:54:44 +0000 Subject: [PATCH 075/323] update --- torch_xla/experimental/fori_loop.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 13a4dbf51ee..bb18c1b65cf 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -80,9 +80,9 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs): body_result = body_fn(*fake_carried_inputs[:-3], weight_0=fake_carried_inputs[-3], output_value=fake_carried_inputs[-2], bias_0=fake_carried_inputs[-1]) body_ctx = torch_xla._XLAC.lowering.LoweringContext() body_ctx.set_name_string("bodyctx") - additional_inputs_list_body = list(fake_carried_inputs[-2]) # missed arguments due to given output_value was not used and PyTorch/XLA trace xlacomputation from output tensor + additional_inputs_list_body = fake_carried_inputs[-2] # missed arguments due to given output_value was not used and PyTorch/XLA trace xlacomputation from output tensor # TODO(@manfei): treat and pass additional_inputs to body_fn too - print("list(fake_carried_inputs[-2]: ", list(fake_carried_inputs[-2])) + print("list(fake_carried_inputs[-2]: ", fake_carried_inputs[-2]) print("len0!!!: ", len(additional_inputs_list_body)) for i in range(len(additional_inputs)): additional_inputs_list_body.append(additional_inputs[i]) From 71718e15f0670e273bb5d8022d94aef6d7c77be5 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 08:56:26 +0000 Subject: [PATCH 076/323] update --- torch_xla/experimental/fori_loop.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index bb18c1b65cf..fa50a422008 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -80,14 +80,14 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs): body_result = body_fn(*fake_carried_inputs[:-3], weight_0=fake_carried_inputs[-3], output_value=fake_carried_inputs[-2], bias_0=fake_carried_inputs[-1]) body_ctx = torch_xla._XLAC.lowering.LoweringContext() body_ctx.set_name_string("bodyctx") - additional_inputs_list_body = fake_carried_inputs[-2] # missed arguments due to given output_value was not used and PyTorch/XLA trace xlacomputation from output tensor + additional_inputs_list_body = [fake_carried_inputs[-2]] # missed arguments due to given output_value was not used and PyTorch/XLA trace xlacomputation from output tensor # TODO(@manfei): treat and pass additional_inputs to body_fn too - print("list(fake_carried_inputs[-2]: ", fake_carried_inputs[-2]) - print("len0!!!: ", len(additional_inputs_list_body)) + # print("list(fake_carried_inputs[-2]: ", fake_carried_inputs[-2]) + # print("len0!!!: ", len(additional_inputs_list_body)) for i in range(len(additional_inputs)): additional_inputs_list_body.append(additional_inputs[i]) - print("len!!!: ", len(additional_inputs_list_body)) - print("additional_inputs_list_body: ", additional_inputs_list_body) + # print("len!!!: ", len(additional_inputs_list_body)) + # print("additional_inputs_list_body: ", additional_inputs_list_body) body_ctx.buildforiloop(list(body_result), additional_inputs_list_body) body_hlo = body_ctx.hlo() body_computation = xb.computation_from_module_proto("bodycomputation", From e8e18f764d20a19d99eb102b72590e8c79426e75 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 20:17:49 +0000 Subject: [PATCH 077/323] update --- ...while_loop_simple_add_dispatch_in_torch.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index c2ed1669e64..3db6d4e93c1 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -87,6 +87,40 @@ def body_fn(init, limit_value): expected = _fake_while_loop(cond_fn, body_fn, (init, limit_value)) self.assertEqual(expected, res) + def test_while_loop_tpu_simple_linear(self): + + xm.mark_step() + device = xm.xla_device() + torch.set_grad_enabled(False) + + upper = torch.tensor([52], dtype=torch.int32, device=device) + lower = torch.tensor([0], dtype=torch.int32, device=device) + init_val = torch.tensor([1], dtype=torch.int32, device=device) + l_in_0 = torch.randn(10, device=xm.xla_device()) + output_value = torch.zeros([20], dtype=torch.float32, device=device) + one_value = torch.tensor([1], dtype=torch.int32, device=device) + + linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) + weight_0 = linear_0.weight + bias_0 = linear_0.bias + + def cond_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bias_0): + return lower[0] < upper[0] + + def body_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bias_0): + new_lower = torch.add(one_value, lower) + output_value = body_fun(*input_value) + weight = body_fun.weight + bias = body_fun.bias + return upper, new_lower, one_value, torch.add(one_value, x), *input_value, weight, bias, output_value + + upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_= = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, *input_value, weight_0, bias_0, output_value)) + + expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) + + self.assertTrue(torch.all(torch.eq(expected, l_out_))) + + def test_fori_loop_tpu_addition(self): xm.mark_step() From 9741e8d1f106a54ba82a0cf7f6d20b04bed1ea96 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 20:20:45 +0000 Subject: [PATCH 078/323] update --- ...i_loop_with_while_loop_simple_add_dispatch_in_torch.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 3db6d4e93c1..1be3ccdd3b4 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -95,10 +95,10 @@ def test_while_loop_tpu_simple_linear(self): upper = torch.tensor([52], dtype=torch.int32, device=device) lower = torch.tensor([0], dtype=torch.int32, device=device) - init_val = torch.tensor([1], dtype=torch.int32, device=device) - l_in_0 = torch.randn(10, device=xm.xla_device()) - output_value = torch.zeros([20], dtype=torch.float32, device=device) one_value = torch.tensor([1], dtype=torch.int32, device=device) + init_val = torch.tensor([1], dtype=torch.int32, device=device) # x + l_in_0 = torch.randn(10, device=xm.xla_device()) # input_value + output_value = torch.zeros([20], dtype=torch.float32, device=device) linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) weight_0 = linear_0.weight @@ -114,7 +114,7 @@ def body_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bi bias = body_fun.bias return upper, new_lower, one_value, torch.add(one_value, x), *input_value, weight, bias, output_value - upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_= = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, *input_value, weight_0, bias_0, output_value)) + upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, weight_0, bias_0, output_value)) expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) From 26e30a399cbcbc3ba5ecc3db6f1828f81f2a8703 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 20:22:11 +0000 Subject: [PATCH 079/323] update --- ...t_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 1be3ccdd3b4..0b5d79383af 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -114,7 +114,8 @@ def body_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bi bias = body_fun.bias return upper, new_lower, one_value, torch.add(one_value, x), *input_value, weight, bias, output_value - upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, weight_0, bias_0, output_value)) + upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = + while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, weight_0, bias_0, output_value)) expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) From c6f82592acc58dd87c9ec4546d903e32effbe11f Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 20:24:06 +0000 Subject: [PATCH 080/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 1 + torch_xla/experimental/fori_loop.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 0b5d79383af..83a345f3760 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -114,6 +114,7 @@ def body_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bi bias = body_fun.bias return upper, new_lower, one_value, torch.add(one_value, x), *input_value, weight, bias, output_value + print("!!! arrive here !!!") upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, weight_0, bias_0, output_value)) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index fa50a422008..20f0f108035 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -44,12 +44,14 @@ def while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): # TODO(@manfei): PyTorch require carried_inputs to be list/tuple, PyTorch/XLA _xla_while_loop only accept *operands, *operands would tuple items again: (a, '') # cond_fn&body_fn: callable # carried_inputs: (Tuple of possibly nested dict/list/tuple of tensors) + print("!!! arrive here too !!!") if additional_inputs is None: additional_inputs = tuple() return _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=additional_inputs) # a=a, b=b, c=c, def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs): + print("!!! arrive here too too !!!") # untuple carried_inputs from while_loop carried_inputs = carried_inputs[0] # fake carried_inputs to split formal code From 5b9378c437a4be7bdf5bba417cec81d69d099e6c Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 20:24:29 +0000 Subject: [PATCH 081/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 83a345f3760..f0674e6b994 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -115,8 +115,8 @@ def body_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bi return upper, new_lower, one_value, torch.add(one_value, x), *input_value, weight, bias, output_value print("!!! arrive here !!!") - upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = - while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, weight_0, bias_0, output_value)) + upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = while_loop( + cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, weight_0, bias_0, output_value)) expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) From 64088798e4f5032b21a7fd2dbcdf300d3c2d1efa Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 20:26:05 +0000 Subject: [PATCH 082/323] update --- ...i_loop_with_while_loop_simple_add_dispatch_in_torch.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index f0674e6b994..bd41135199e 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -104,15 +104,15 @@ def test_while_loop_tpu_simple_linear(self): weight_0 = linear_0.weight bias_0 = linear_0.bias - def cond_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bias_0): + def cond_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bias_0): return lower[0] < upper[0] - def body_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bias_0): + def body_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bias_0): new_lower = torch.add(one_value, lower) - output_value = body_fun(*input_value) + output_value = body_fun(input_value) weight = body_fun.weight bias = body_fun.bias - return upper, new_lower, one_value, torch.add(one_value, x), *input_value, weight, bias, output_value + return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value print("!!! arrive here !!!") upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = while_loop( From 7c408a93358a2c834e14fe5ac62c42184308dcab Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 20:27:48 +0000 Subject: [PATCH 083/323] update --- ...ori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index bd41135199e..3c103deddbd 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -109,9 +109,9 @@ def cond_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bia def body_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bias_0): new_lower = torch.add(one_value, lower) - output_value = body_fun(input_value) - weight = body_fun.weight - bias = body_fun.bias + output_value = linear_0(input_value) + weight = linear_0.weight + bias = linear_0.bias return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value print("!!! arrive here !!!") From 9c6852877ba8511a6c3d2a1e592b66fbb5122b05 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 20:29:42 +0000 Subject: [PATCH 084/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 3c103deddbd..88ff7148a97 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -116,7 +116,7 @@ def body_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bia print("!!! arrive here !!!") upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = while_loop( - cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, weight_0, bias_0, output_value)) + cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, weight_0, output_value, bias_0)) expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) From 141c7043ddbbc53715f4ed54ad1f5b7347c0169e Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 20:41:27 +0000 Subject: [PATCH 085/323] update --- ...fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 88ff7148a97..3d5945cdb00 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -114,9 +114,8 @@ def body_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bia bias = linear_0.bias return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value - print("!!! arrive here !!!") - upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = while_loop( - cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, weight_0, output_value, bias_0)) + # print("!!! arrive here !!!") + upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, weight_0, output_value, bias_0)) expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) From d5e5537c7a12d9698c4ade31564ac085bed03725 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 20:43:09 +0000 Subject: [PATCH 086/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 3d5945cdb00..dd8d0701a7e 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -115,7 +115,7 @@ def body_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bia return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value # print("!!! arrive here !!!") - upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, weight_0, output_value, bias_0)) + upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, weight_0, output_value, bias_0), additional_inputs=None) expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) From cfbe475113a9cde532fabf61da86052ea4aa40a0 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 20:47:31 +0000 Subject: [PATCH 087/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index dd8d0701a7e..3d5945cdb00 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -115,7 +115,7 @@ def body_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bia return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value # print("!!! arrive here !!!") - upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, weight_0, output_value, bias_0), additional_inputs=None) + upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, weight_0, output_value, bias_0)) expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) From b11f015586b13119dbc75d99662599c40ed6256c Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 20:58:28 +0000 Subject: [PATCH 088/323] update --- ...while_loop_simple_add_dispatch_in_torch.py | 38 ++++++++++++++++++- torch_xla/experimental/fori_loop.py | 13 +++++-- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 3d5945cdb00..e28d4cbd605 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -87,6 +87,39 @@ def body_fn(init, limit_value): expected = _fake_while_loop(cond_fn, body_fn, (init, limit_value)) self.assertEqual(expected, res) +# ////// +# class SimpleWithLinear(torch.nn.Module): +# def __init__(self): +# super().__init__() +# self.linear = torch.nn.Linear(2, 2) +# self.register_buffer("dec", torch.tensor(1)) + +# def forward(self, iter, x): +# def cond_fn(it, x): +# return it - self.dec > 0 + +# def body_fn(it, x): +# return it - 1, self.linear(x) +# return while_loop(cond_fn, body_fn, (iter, x)) + +# class NestedWithLinear(torch.nn.Module): +# return while_loop(cond_fn, body_fn, (iter, x)) + +# nested2 = Nested() +# simple_with_linear = SimpleWithLinear() +# nested_with_linear = NestedWithLinear() + +# x = torch.zeros(1) +# y = torch.zeros(1) +# z = torch.zeros(1) +# return {"simple": (simple, (x,)), +# "nested": (nested, (x, y, z)), +# "nested2": (nested2, (torch.tensor(2), torch.tensor(2), torch.ones(2, 2), torch.ones(2, 2))), +# "simple_with_mutation": (simple_with_mutation, (x,)), +# "simple_with_linear": (simple_with_linear, (torch.tensor(3), torch.randn(2, 2))), +# "nested_with_linear": (nested_with_linear, (torch.tensor(3), torch.randn(2, 2)))} +# ////// + def test_while_loop_tpu_simple_linear(self): xm.mark_step() @@ -104,10 +137,11 @@ def test_while_loop_tpu_simple_linear(self): weight_0 = linear_0.weight bias_0 = linear_0.bias - def cond_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bias_0): + # def cond_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bias_0): + def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] - def body_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bias_0): + def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) output_value = linear_0(input_value) weight = linear_0.weight diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 20f0f108035..2bbecd42f64 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -50,7 +50,7 @@ def while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): return _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=additional_inputs) # a=a, b=b, c=c, -def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs): +def _xla_while_loop(cond_fn, body_fn, *carried_inputs, *additional_inputs): print("!!! arrive here too too !!!") # untuple carried_inputs from while_loop carried_inputs = carried_inputs[0] @@ -62,11 +62,18 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs): fake_carried_inputs.append( torch.randint(10, carried_input.size(), dtype=carried_input.dtype).to(device)) + # fake_carried_inputs = tuple(fake_carried_inputs) + for additional_input in additional_inputs: + device = additional_input.device + #TODO(@manfei) type = carried_input.type + fake_carried_inputs.append( + torch.randint(10, additional_input.size(), + dtype=additional_input.dtype).to(device)) fake_carried_inputs = tuple(fake_carried_inputs) # generate cond_fn xlacomputation # TODO(@manfei): specify which element is for which argument like a,b,c - cond_result = cond_fn(*fake_carried_inputs[:-3], weight_0=fake_carried_inputs[-3], output_value=fake_carried_inputs[-2], bias_0=fake_carried_inputs[-1]) + cond_result = cond_fn(*fake_carried_inputs[:-3], weight_0=fake_carried_inputs[-2], output_value=fake_carried_inputs[-3], bias_0=fake_carried_inputs[-1]) cond_ctx = torch_xla._XLAC.lowering.LoweringContext() cond_ctx.set_name_string("condctx") additional_inputs_list_cond = list(fake_carried_inputs[2:]) # all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor @@ -79,7 +86,7 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs): cond_hlo) # generate body_fn xlacomputation - body_result = body_fn(*fake_carried_inputs[:-3], weight_0=fake_carried_inputs[-3], output_value=fake_carried_inputs[-2], bias_0=fake_carried_inputs[-1]) + body_result = body_fn(*fake_carried_inputs[:-3], weight_0=fake_carried_inputs[-2], output_value=fake_carried_inputs[-3], bias_0=fake_carried_inputs[-1]) body_ctx = torch_xla._XLAC.lowering.LoweringContext() body_ctx.set_name_string("bodyctx") additional_inputs_list_body = [fake_carried_inputs[-2]] # missed arguments due to given output_value was not used and PyTorch/XLA trace xlacomputation from output tensor From 9cd8ca054c191ca0d7334e25d80ed8e868291ed1 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 21:00:29 +0000 Subject: [PATCH 089/323] update --- torch_xla/experimental/fori_loop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 2bbecd42f64..d9b399d2dfb 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -50,7 +50,7 @@ def while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): return _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=additional_inputs) # a=a, b=b, c=c, -def _xla_while_loop(cond_fn, body_fn, *carried_inputs, *additional_inputs): +def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs): print("!!! arrive here too too !!!") # untuple carried_inputs from while_loop carried_inputs = carried_inputs[0] From 89a2b34f9eb42539ddb4c046315c4bd4f9de8f3e Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 21:01:58 +0000 Subject: [PATCH 090/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index e28d4cbd605..307a2377bb7 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -149,7 +149,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value # print("!!! arrive here !!!") - upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, weight_0, output_value, bias_0)) + upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) From 9e420ad35a059cf3ceea3eec2a63c79fc79a2eaf Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 21:05:19 +0000 Subject: [PATCH 091/323] update --- ...while_loop_simple_add_dispatch_in_torch.py | 71 ++++++++++++------- 1 file changed, 47 insertions(+), 24 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 307a2377bb7..9264b43ba6a 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -126,30 +126,53 @@ def test_while_loop_tpu_simple_linear(self): device = xm.xla_device() torch.set_grad_enabled(False) - upper = torch.tensor([52], dtype=torch.int32, device=device) - lower = torch.tensor([0], dtype=torch.int32, device=device) - one_value = torch.tensor([1], dtype=torch.int32, device=device) - init_val = torch.tensor([1], dtype=torch.int32, device=device) # x - l_in_0 = torch.randn(10, device=xm.xla_device()) # input_value - output_value = torch.zeros([20], dtype=torch.float32, device=device) - - linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) - weight_0 = linear_0.weight - bias_0 = linear_0.bias - - # def cond_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bias_0): - def cond_fn(upper, lower, one_value, x, input_value, output_value): - return lower[0] < upper[0] - - def body_fn(upper, lower, one_value, x, input_value, output_value): - new_lower = torch.add(one_value, lower) - output_value = linear_0(input_value) - weight = linear_0.weight - bias = linear_0.bias - return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value - - # print("!!! arrive here !!!") - upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) + class SimpleWithLinear(torch.nn.Module): + def __init__(self): + super().__init__() + self.linear = torch.nn.Linear(10, 20).to(xm.xla_device()) + # self.register_buffer("dec", torch.tensor(1)) + + def forward(self, upper, lower, one_value, x, input_value, output_value): + def cond_fn(upper, lower, one_value, x, input_value, output_value): + return lower[0] < upper[0] + + def body_fn(upper, lower, one_value, x, input_value, output_value): + new_lower = torch.add(one_value, lower) + output_value = linear_0(input_value) + weight = linear_0.weight + bias = linear_0.bias + return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value + # return while_loop(cond_fn, body_fn, (iter, x)) + return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) + + # xm.mark_step() + # device = xm.xla_device() + # torch.set_grad_enabled(False) + + # upper = torch.tensor([52], dtype=torch.int32, device=device) + # lower = torch.tensor([0], dtype=torch.int32, device=device) + # one_value = torch.tensor([1], dtype=torch.int32, device=device) + # init_val = torch.tensor([1], dtype=torch.int32, device=device) # x + # l_in_0 = torch.randn(10, device=xm.xla_device()) # input_value + # output_value = torch.zeros([20], dtype=torch.float32, device=device) + + # linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) + # weight_0 = linear_0.weight + # bias_0 = linear_0.bias + + # # def cond_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bias_0): + # def cond_fn(upper, lower, one_value, x, input_value, output_value): + # return lower[0] < upper[0] + + # def body_fn(upper, lower, one_value, x, input_value, output_value): + # new_lower = torch.add(one_value, lower) + # output_value = linear_0(input_value) + # weight = linear_0.weight + # bias = linear_0.bias + # return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value + + # # print("!!! arrive here !!!") + # upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) From a536a3eec0ff6fdedc02de789cf0baeac93df54c Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 21:05:41 +0000 Subject: [PATCH 092/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 9264b43ba6a..8c78ee4a8e1 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -174,9 +174,9 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # # print("!!! arrive here !!!") # upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) - expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) + # expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) - self.assertTrue(torch.all(torch.eq(expected, l_out_))) + # self.assertTrue(torch.all(torch.eq(expected, l_out_))) def test_fori_loop_tpu_addition(self): From b2b246f3804c435ae98962118a8909c9d70a7bd8 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 21:09:39 +0000 Subject: [PATCH 093/323] update --- ...while_loop_simple_add_dispatch_in_torch.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 8c78ee4a8e1..762f6960e58 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -145,6 +145,25 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # return while_loop(cond_fn, body_fn, (iter, x)) return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) + simple_with_linear = SimpleWithLinear() + upper = torch.tensor([52], dtype=torch.int32, device=device) + lower = torch.tensor([0], dtype=torch.int32, device=device) + one_value = torch.tensor([1], dtype=torch.int32, device=device) + init_val = torch.tensor([1], dtype=torch.int32, device=device) # x + l_in_0 = torch.randn(10, device=xm.xla_device()) # input_value + output_value = torch.zeros([20], dtype=torch.float32, device=device) + + linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) + weight_0 = linear_0.weight + bias_0 = linear_0.bias + + return {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} + +# x = torch.zeros(1) +# y = torch.zeros(1) +# z = torch.zeros(1) +# return {"simple_with_linear": (simple_with_linear, (torch.tensor(3), torch.randn(2, 2)))} + # xm.mark_step() # device = xm.xla_device() # torch.set_grad_enabled(False) From 2664e23a2f5053c34cea48eb9b217f4ca1b24a79 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 21:12:58 +0000 Subject: [PATCH 094/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 762f6960e58..9ef4132acd1 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -157,7 +157,9 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): weight_0 = linear_0.weight bias_0 = linear_0.bias + # return {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} return {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} + simple_with_linear.apply(upper, lower, one_value, init_val, l_in_0, output_value) # x = torch.zeros(1) # y = torch.zeros(1) From 4f28a541e421aa4fa4ffade31b4c44e4f8a190ca Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 21:13:31 +0000 Subject: [PATCH 095/323] update --- ...t_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 9ef4132acd1..f79c801f8e7 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -159,7 +159,8 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # return {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} return {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} - simple_with_linear.apply(upper, lower, one_value, init_val, l_in_0, output_value) + res = simple_with_linear.apply(upper, lower, one_value, init_val, l_in_0, output_value) + print("res: ", res) # x = torch.zeros(1) # y = torch.zeros(1) From 5c993afa7292577a77baf9b73af80ee24428633c Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 21:14:35 +0000 Subject: [PATCH 096/323] update --- ...est_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index f79c801f8e7..37248be031a 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -161,6 +161,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): return {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} res = simple_with_linear.apply(upper, lower, one_value, init_val, l_in_0, output_value) print("res: ", res) + import pdb; pdb.set_trace() # x = torch.zeros(1) # y = torch.zeros(1) From 8298841bf8455c8cd58ed2a102e3879a86695326 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 21:15:44 +0000 Subject: [PATCH 097/323] update --- ...while_loop_simple_add_dispatch_in_torch.py | 113 +++++++----------- 1 file changed, 41 insertions(+), 72 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 37248be031a..bec06748415 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -87,39 +87,6 @@ def body_fn(init, limit_value): expected = _fake_while_loop(cond_fn, body_fn, (init, limit_value)) self.assertEqual(expected, res) -# ////// -# class SimpleWithLinear(torch.nn.Module): -# def __init__(self): -# super().__init__() -# self.linear = torch.nn.Linear(2, 2) -# self.register_buffer("dec", torch.tensor(1)) - -# def forward(self, iter, x): -# def cond_fn(it, x): -# return it - self.dec > 0 - -# def body_fn(it, x): -# return it - 1, self.linear(x) -# return while_loop(cond_fn, body_fn, (iter, x)) - -# class NestedWithLinear(torch.nn.Module): -# return while_loop(cond_fn, body_fn, (iter, x)) - -# nested2 = Nested() -# simple_with_linear = SimpleWithLinear() -# nested_with_linear = NestedWithLinear() - -# x = torch.zeros(1) -# y = torch.zeros(1) -# z = torch.zeros(1) -# return {"simple": (simple, (x,)), -# "nested": (nested, (x, y, z)), -# "nested2": (nested2, (torch.tensor(2), torch.tensor(2), torch.ones(2, 2), torch.ones(2, 2))), -# "simple_with_mutation": (simple_with_mutation, (x,)), -# "simple_with_linear": (simple_with_linear, (torch.tensor(3), torch.randn(2, 2))), -# "nested_with_linear": (nested_with_linear, (torch.tensor(3), torch.randn(2, 2)))} -# ////// - def test_while_loop_tpu_simple_linear(self): xm.mark_step() @@ -163,45 +130,6 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): print("res: ", res) import pdb; pdb.set_trace() -# x = torch.zeros(1) -# y = torch.zeros(1) -# z = torch.zeros(1) -# return {"simple_with_linear": (simple_with_linear, (torch.tensor(3), torch.randn(2, 2)))} - - # xm.mark_step() - # device = xm.xla_device() - # torch.set_grad_enabled(False) - - # upper = torch.tensor([52], dtype=torch.int32, device=device) - # lower = torch.tensor([0], dtype=torch.int32, device=device) - # one_value = torch.tensor([1], dtype=torch.int32, device=device) - # init_val = torch.tensor([1], dtype=torch.int32, device=device) # x - # l_in_0 = torch.randn(10, device=xm.xla_device()) # input_value - # output_value = torch.zeros([20], dtype=torch.float32, device=device) - - # linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) - # weight_0 = linear_0.weight - # bias_0 = linear_0.bias - - # # def cond_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bias_0): - # def cond_fn(upper, lower, one_value, x, input_value, output_value): - # return lower[0] < upper[0] - - # def body_fn(upper, lower, one_value, x, input_value, output_value): - # new_lower = torch.add(one_value, lower) - # output_value = linear_0(input_value) - # weight = linear_0.weight - # bias = linear_0.bias - # return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value - - # # print("!!! arrive here !!!") - # upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) - - # expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) - - # self.assertTrue(torch.all(torch.eq(expected, l_out_))) - - def test_fori_loop_tpu_addition(self): xm.mark_step() @@ -242,3 +170,44 @@ def test_fori_loop_tpu_simple_linear(self): if __name__ == '__main__': test = unittest.main() sys.exit(0 if test.result.wasSuccessful() else 1) + + +######## --------------------------------------------------------- + +# x = torch.zeros(1) +# y = torch.zeros(1) +# z = torch.zeros(1) +# return {"simple_with_linear": (simple_with_linear, (torch.tensor(3), torch.randn(2, 2)))} + + # xm.mark_step() + # device = xm.xla_device() + # torch.set_grad_enabled(False) + + # upper = torch.tensor([52], dtype=torch.int32, device=device) + # lower = torch.tensor([0], dtype=torch.int32, device=device) + # one_value = torch.tensor([1], dtype=torch.int32, device=device) + # init_val = torch.tensor([1], dtype=torch.int32, device=device) # x + # l_in_0 = torch.randn(10, device=xm.xla_device()) # input_value + # output_value = torch.zeros([20], dtype=torch.float32, device=device) + + # linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) + # weight_0 = linear_0.weight + # bias_0 = linear_0.bias + + # # def cond_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bias_0): + # def cond_fn(upper, lower, one_value, x, input_value, output_value): + # return lower[0] < upper[0] + + # def body_fn(upper, lower, one_value, x, input_value, output_value): + # new_lower = torch.add(one_value, lower) + # output_value = linear_0(input_value) + # weight = linear_0.weight + # bias = linear_0.bias + # return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value + + # # print("!!! arrive here !!!") + # upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) + + # expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) + + # self.assertTrue(torch.all(torch.eq(expected, l_out_))) From 32af47b623529f7e0c6021cf92aeb818a8716b18 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 21:16:23 +0000 Subject: [PATCH 098/323] update --- ...est_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index bec06748415..beb31887e5c 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -92,6 +92,7 @@ def test_while_loop_tpu_simple_linear(self): xm.mark_step() device = xm.xla_device() torch.set_grad_enabled(False) + print("start test !!!") class SimpleWithLinear(torch.nn.Module): def __init__(self): From 448de12d7a5ec519bf9474fbc5dc1dc57e30ee10 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 21:16:49 +0000 Subject: [PATCH 099/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index beb31887e5c..26438e6bf1e 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -92,7 +92,6 @@ def test_while_loop_tpu_simple_linear(self): xm.mark_step() device = xm.xla_device() torch.set_grad_enabled(False) - print("start test !!!") class SimpleWithLinear(torch.nn.Module): def __init__(self): @@ -113,6 +112,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # return while_loop(cond_fn, body_fn, (iter, x)) return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) + print("start test !!!") simple_with_linear = SimpleWithLinear() upper = torch.tensor([52], dtype=torch.int32, device=device) lower = torch.tensor([0], dtype=torch.int32, device=device) From abe4c788d7ce7ca396f0a77ce2e8b0116143e2d7 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 21:19:36 +0000 Subject: [PATCH 100/323] update --- ...t_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 26438e6bf1e..5bd827626cb 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -92,6 +92,7 @@ def test_while_loop_tpu_simple_linear(self): xm.mark_step() device = xm.xla_device() torch.set_grad_enabled(False) + print("start test 1 !!!") class SimpleWithLinear(torch.nn.Module): def __init__(self): @@ -112,7 +113,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # return while_loop(cond_fn, body_fn, (iter, x)) return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) - print("start test !!!") + print("start test 2 !!!") simple_with_linear = SimpleWithLinear() upper = torch.tensor([52], dtype=torch.int32, device=device) lower = torch.tensor([0], dtype=torch.int32, device=device) From 1bf37d8322fa8aa19d5a635e3fa656dd574f5479 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 21:19:57 +0000 Subject: [PATCH 101/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 5bd827626cb..d2ad777b869 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -122,6 +122,8 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): l_in_0 = torch.randn(10, device=xm.xla_device()) # input_value output_value = torch.zeros([20], dtype=torch.float32, device=device) + print("start test 3 !!!") + linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) weight_0 = linear_0.weight bias_0 = linear_0.bias From 20215378510d3c65dd04d2679b088517cc0ebeba Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 21:20:27 +0000 Subject: [PATCH 102/323] update --- ...fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index d2ad777b869..12abf30392f 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -128,8 +128,11 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): weight_0 = linear_0.weight bias_0 = linear_0.bias + print("start test 4 !!!") + + # return {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} # return {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} - return {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} + print("start test 5 !!!") res = simple_with_linear.apply(upper, lower, one_value, init_val, l_in_0, output_value) print("res: ", res) import pdb; pdb.set_trace() From 83c2f97b2712f9c2d7009afd98246f56e6386456 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 21:20:57 +0000 Subject: [PATCH 103/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 12abf30392f..596a488cf60 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -135,7 +135,9 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): print("start test 5 !!!") res = simple_with_linear.apply(upper, lower, one_value, init_val, l_in_0, output_value) print("res: ", res) + print("start test 6 !!!") import pdb; pdb.set_trace() + return {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} def test_fori_loop_tpu_addition(self): From 1945952aee79ac87e783cd2a805135741ecfc11e Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 21:22:55 +0000 Subject: [PATCH 104/323] update --- ...t_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 596a488cf60..ab480592e76 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -129,11 +129,10 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): bias_0 = linear_0.bias print("start test 4 !!!") - # return {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} # return {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} print("start test 5 !!!") - res = simple_with_linear.apply(upper, lower, one_value, init_val, l_in_0, output_value) + res = simple_with_linear.apply((upper, lower, one_value, init_val, l_in_0, output_value)) print("res: ", res) print("start test 6 !!!") import pdb; pdb.set_trace() From 6ee5400dd8f7c3c8256ff2045534406f0a2b4cc7 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 21:25:05 +0000 Subject: [PATCH 105/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index ab480592e76..cb148b60346 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -132,9 +132,11 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # return {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} # return {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} print("start test 5 !!!") + aaa = {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} + print("aaa: ", aaa) + print("start test 6 !!!") res = simple_with_linear.apply((upper, lower, one_value, init_val, l_in_0, output_value)) print("res: ", res) - print("start test 6 !!!") import pdb; pdb.set_trace() return {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} From 3db127e8bb9b2ce33bf280c87549b1d51870812c Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 21:25:54 +0000 Subject: [PATCH 106/323] update --- ..._loop_with_while_loop_simple_add_dispatch_in_torch.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index cb148b60346..be1310f914d 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -135,10 +135,11 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): aaa = {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} print("aaa: ", aaa) print("start test 6 !!!") - res = simple_with_linear.apply((upper, lower, one_value, init_val, l_in_0, output_value)) - print("res: ", res) - import pdb; pdb.set_trace() - return {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} + return aaa + # res = simple_with_linear.apply((upper, lower, one_value, init_val, l_in_0, output_value)) + # print("res: ", res) + # import pdb; pdb.set_trace() + # return {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} def test_fori_loop_tpu_addition(self): From dc1837d999b2a61cb1156d8b4171aa0c4c5f6362 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 21:30:03 +0000 Subject: [PATCH 107/323] update --- ...ith_while_loop_simple_add_dispatch_in_torch.py | 15 ++++++--------- torch_xla/experimental/fori_loop.py | 1 + 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index be1310f914d..3c33a118a75 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -92,7 +92,6 @@ def test_while_loop_tpu_simple_linear(self): xm.mark_step() device = xm.xla_device() torch.set_grad_enabled(False) - print("start test 1 !!!") class SimpleWithLinear(torch.nn.Module): def __init__(self): @@ -113,7 +112,6 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # return while_loop(cond_fn, body_fn, (iter, x)) return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) - print("start test 2 !!!") simple_with_linear = SimpleWithLinear() upper = torch.tensor([52], dtype=torch.int32, device=device) lower = torch.tensor([0], dtype=torch.int32, device=device) @@ -122,20 +120,19 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): l_in_0 = torch.randn(10, device=xm.xla_device()) # input_value output_value = torch.zeros([20], dtype=torch.float32, device=device) - print("start test 3 !!!") - linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) weight_0 = linear_0.weight bias_0 = linear_0.bias - print("start test 4 !!!") - # return {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} - # return {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} - print("start test 5 !!!") aaa = {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} + upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = aaa print("aaa: ", aaa) - print("start test 6 !!!") + # print("start test 6 !!!") return aaa + + expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) + + self.assertTrue(torch.all(torch.eq(expected, l_out_))) # res = simple_with_linear.apply((upper, lower, one_value, init_val, l_in_0, output_value)) # print("res: ", res) # import pdb; pdb.set_trace() diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index d9b399d2dfb..70b4388ab9c 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -52,6 +52,7 @@ def while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs): print("!!! arrive here too too !!!") + import pdb; pdb.set_trace() # untuple carried_inputs from while_loop carried_inputs = carried_inputs[0] # fake carried_inputs to split formal code From ea9bf565ad47e9d7014e3c8660573de5d90f77a4 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 21:30:34 +0000 Subject: [PATCH 108/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 3c33a118a75..563cfd39adf 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -125,7 +125,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): bias_0 = linear_0.bias aaa = {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} - upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = aaa + # upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = aaa print("aaa: ", aaa) # print("start test 6 !!!") return aaa From ee05a67db6108568ea831a89f5cb84fcc3dadc1d Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 21:31:40 +0000 Subject: [PATCH 109/323] update --- ...t_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 563cfd39adf..138e1b18b46 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -117,7 +117,8 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): lower = torch.tensor([0], dtype=torch.int32, device=device) one_value = torch.tensor([1], dtype=torch.int32, device=device) init_val = torch.tensor([1], dtype=torch.int32, device=device) # x - l_in_0 = torch.randn(10, device=xm.xla_device()) # input_value + # l_in_0 = torch.randn(10, device=xm.xla_device()) # input_value + l_in_0 = torch.ones(10, device=xm.xla_device()) # input_value output_value = torch.zeros([20], dtype=torch.float32, device=device) linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) From 67f26521d10af7f4229cfb531689e821ff709327 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 22:43:46 +0000 Subject: [PATCH 110/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 138e1b18b46..44948605d9c 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -128,6 +128,8 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): aaa = {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} # upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = aaa print("aaa: ", aaa) + bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, output_value) + print("bbb: ", bbb) # print("start test 6 !!!") return aaa From 3bba9fd7dfff560b07df023788f427f31a775286 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 22:45:40 +0000 Subject: [PATCH 111/323] update --- torch_xla/experimental/fori_loop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 70b4388ab9c..1e6d2dd732a 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -87,7 +87,7 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs): cond_hlo) # generate body_fn xlacomputation - body_result = body_fn(*fake_carried_inputs[:-3], weight_0=fake_carried_inputs[-2], output_value=fake_carried_inputs[-3], bias_0=fake_carried_inputs[-1]) + body_result = body_fn(*fake_carried_inputs[:-3], weight_0=fake_carried_inputs[-1], output_value=fake_carried_inputs[-3], bias_0=fake_carried_inputs[-2]) body_ctx = torch_xla._XLAC.lowering.LoweringContext() body_ctx.set_name_string("bodyctx") additional_inputs_list_body = [fake_carried_inputs[-2]] # missed arguments due to given output_value was not used and PyTorch/XLA trace xlacomputation from output tensor From 2e349a601de3dbc1bba418dc5a95e9242df98080 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 22:52:23 +0000 Subject: [PATCH 112/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 44948605d9c..b04d9dd3ef6 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -105,10 +105,10 @@ def cond_fn(upper, lower, one_value, x, input_value, output_value): def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) - output_value = linear_0(input_value) + output_value_real = linear_0(input_value) weight = linear_0.weight bias = linear_0.bias - return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value + return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value_real # return while_loop(cond_fn, body_fn, (iter, x)) return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) From 7b63eb845b858d45651eeff1334b3db32f4f8a0c Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 22:53:48 +0000 Subject: [PATCH 113/323] update --- ...est_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index b04d9dd3ef6..8b4804d5e31 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -105,6 +105,7 @@ def cond_fn(upper, lower, one_value, x, input_value, output_value): def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) + output_value_real = output_value.copy() output_value_real = linear_0(input_value) weight = linear_0.weight bias = linear_0.bias From 62855cc33940a6ba8df45cce62e12f27592ccc00 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 22:54:25 +0000 Subject: [PATCH 114/323] update --- ...est_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 8b4804d5e31..b04d9dd3ef6 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -105,7 +105,6 @@ def cond_fn(upper, lower, one_value, x, input_value, output_value): def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) - output_value_real = output_value.copy() output_value_real = linear_0(input_value) weight = linear_0.weight bias = linear_0.bias From 70a29c4f7a3064155b30516dd780f8f0a40b839b Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:02:23 +0000 Subject: [PATCH 115/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index b04d9dd3ef6..b1ad2095c3d 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -7,6 +7,7 @@ # We need to import the underlying implementation function to register with the dispatcher import torch_xla.experimental.fori_loop from torch_xla.experimental.fori_loop import fori_loop +from torch_xla.experimental.fori_loop import _xla_while_loop from torch._higher_order_ops.while_loop import while_loop import torch_xla.core.xla_model as xm import torch_xla.core.xla_builder as xb @@ -110,7 +111,8 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): bias = linear_0.bias return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value_real # return while_loop(cond_fn, body_fn, (iter, x)) - return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) + # return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) + return _xla_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) simple_with_linear = SimpleWithLinear() upper = torch.tensor([52], dtype=torch.int32, device=device) From 863ba37a872db3f70beabefb97f9f1f42236bae8 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:03:04 +0000 Subject: [PATCH 116/323] update --- torch_xla/experimental/fori_loop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 1e6d2dd732a..979be6c254d 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -50,7 +50,7 @@ def while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): return _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=additional_inputs) # a=a, b=b, c=c, -def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs): +def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): print("!!! arrive here too too !!!") import pdb; pdb.set_trace() # untuple carried_inputs from while_loop From 4da7ede1c84c9d2c2e6fcb64d2a71599146e6d90 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:04:17 +0000 Subject: [PATCH 117/323] update --- torch_xla/experimental/fori_loop.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 979be6c254d..2de46cdd938 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -50,9 +50,9 @@ def while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): return _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=additional_inputs) # a=a, b=b, c=c, -def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): +def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): print("!!! arrive here too too !!!") - import pdb; pdb.set_trace() + # import pdb; pdb.set_trace() # untuple carried_inputs from while_loop carried_inputs = carried_inputs[0] # fake carried_inputs to split formal code From 261ec24bab6a0e6e954eecc42d3bbc423931132f Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:06:06 +0000 Subject: [PATCH 118/323] update --- torch_xla/experimental/fori_loop.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 2de46cdd938..a11af64db3a 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -64,6 +64,7 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): torch.randint(10, carried_input.size(), dtype=carried_input.dtype).to(device)) # fake_carried_inputs = tuple(fake_carried_inputs) + print("fake_carried_inputs first: ", fake_carried_inputs) for additional_input in additional_inputs: device = additional_input.device #TODO(@manfei) type = carried_input.type @@ -71,10 +72,11 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): torch.randint(10, additional_input.size(), dtype=additional_input.dtype).to(device)) fake_carried_inputs = tuple(fake_carried_inputs) + print("fake_carried_inputs second: ", fake_carried_inputs) # generate cond_fn xlacomputation # TODO(@manfei): specify which element is for which argument like a,b,c - cond_result = cond_fn(*fake_carried_inputs[:-3], weight_0=fake_carried_inputs[-2], output_value=fake_carried_inputs[-3], bias_0=fake_carried_inputs[-1]) + cond_result = cond_fn(*fake_carried_inputs) # [:-3], weight_0=fake_carried_inputs[-2], output_value=fake_carried_inputs[-3], bias_0=fake_carried_inputs[-1]) cond_ctx = torch_xla._XLAC.lowering.LoweringContext() cond_ctx.set_name_string("condctx") additional_inputs_list_cond = list(fake_carried_inputs[2:]) # all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor @@ -87,7 +89,7 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): cond_hlo) # generate body_fn xlacomputation - body_result = body_fn(*fake_carried_inputs[:-3], weight_0=fake_carried_inputs[-1], output_value=fake_carried_inputs[-3], bias_0=fake_carried_inputs[-2]) + body_result = body_fn(*fake_carried_inputs) # [:-3], weight_0=fake_carried_inputs[-1], output_value=fake_carried_inputs[-3], bias_0=fake_carried_inputs[-2]) body_ctx = torch_xla._XLAC.lowering.LoweringContext() body_ctx.set_name_string("bodyctx") additional_inputs_list_body = [fake_carried_inputs[-2]] # missed arguments due to given output_value was not used and PyTorch/XLA trace xlacomputation from output tensor From 334036ed6778841935683c208a29ad7559507add Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:09:01 +0000 Subject: [PATCH 119/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- torch_xla/experimental/fori_loop.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index b1ad2095c3d..4e6f9585dd3 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -129,7 +129,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): aaa = {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} # upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = aaa - print("aaa: ", aaa) + # print("aaa: ", aaa) bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, output_value) print("bbb: ", bbb) # print("start test 6 !!!") diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index a11af64db3a..4396d25f184 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -52,6 +52,8 @@ def while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): print("!!! arrive here too too !!!") + print("carried_inputs: ", carried_inputs) + print("additional_inputs: ", additional_inputs) # import pdb; pdb.set_trace() # untuple carried_inputs from while_loop carried_inputs = carried_inputs[0] From acc2e205f131fc6b6e7392cbb0c0f470fe2780c0 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:10:54 +0000 Subject: [PATCH 120/323] update --- ...t_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 4e6f9585dd3..c3a8a05bd3b 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -112,7 +112,8 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value_real # return while_loop(cond_fn, body_fn, (iter, x)) # return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) - return _xla_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) + return 1 + # return _xla_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) simple_with_linear = SimpleWithLinear() upper = torch.tensor([52], dtype=torch.int32, device=device) From 3e7172c80b1b992a31e5f02378433b7cd9f1df34 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:11:44 +0000 Subject: [PATCH 121/323] update --- ...fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index c3a8a05bd3b..cc72cfa995c 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -7,7 +7,7 @@ # We need to import the underlying implementation function to register with the dispatcher import torch_xla.experimental.fori_loop from torch_xla.experimental.fori_loop import fori_loop -from torch_xla.experimental.fori_loop import _xla_while_loop +# from torch_xla.experimental.fori_loop import _xla_while_loop from torch._higher_order_ops.while_loop import while_loop import torch_xla.core.xla_model as xm import torch_xla.core.xla_builder as xb @@ -112,7 +112,8 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value_real # return while_loop(cond_fn, body_fn, (iter, x)) # return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) - return 1 + # return 1 + return upper, lower, one_value, x, input_value, output_value # return _xla_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) simple_with_linear = SimpleWithLinear() From ead598174e2180a28a4bebab7e6180195bfbdd35 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:12:54 +0000 Subject: [PATCH 122/323] update --- ...t_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index cc72cfa995c..c12bcb48120 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -113,7 +113,8 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # return while_loop(cond_fn, body_fn, (iter, x)) # return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) # return 1 - return upper, lower, one_value, x, input_value, output_value + # return upper, lower, one_value, x, input_value, output_value + return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, output_value)) # return _xla_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) simple_with_linear = SimpleWithLinear() From 4762c554542215060c0729a3dfbb714e5f02fdda Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:13:55 +0000 Subject: [PATCH 123/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index c12bcb48120..0041e2f8d0a 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -113,8 +113,8 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # return while_loop(cond_fn, body_fn, (iter, x)) # return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) # return 1 - # return upper, lower, one_value, x, input_value, output_value - return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, output_value)) + return upper, lower, one_value, x, input_value, output_value + # return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, output_value)) # return _xla_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) simple_with_linear = SimpleWithLinear() From e4ff32fadbdf067d4734a0e92abad51ddd5b9038 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:14:41 +0000 Subject: [PATCH 124/323] update --- ...t_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 0041e2f8d0a..5f56aaa7a9f 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -109,7 +109,8 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): output_value_real = linear_0(input_value) weight = linear_0.weight bias = linear_0.bias - return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value_real + # return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value_real + return upper, new_lower, one_value, torch.add(one_value, x), input_value, output_value_real # return while_loop(cond_fn, body_fn, (iter, x)) # return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) # return 1 From 7215162b92e088a584c31800646329c5baf9182a Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:15:37 +0000 Subject: [PATCH 125/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 5f56aaa7a9f..46b3d8aa25f 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -114,8 +114,8 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # return while_loop(cond_fn, body_fn, (iter, x)) # return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) # return 1 - return upper, lower, one_value, x, input_value, output_value - # return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, output_value)) + # return upper, lower, one_value, x, input_value, output_value + return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, output_value)) # return _xla_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) simple_with_linear = SimpleWithLinear() From f275c0ee26805bb19ec2bb941d2b2f612668e200 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:16:07 +0000 Subject: [PATCH 126/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 46b3d8aa25f..5f56aaa7a9f 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -114,8 +114,8 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # return while_loop(cond_fn, body_fn, (iter, x)) # return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) # return 1 - # return upper, lower, one_value, x, input_value, output_value - return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, output_value)) + return upper, lower, one_value, x, input_value, output_value + # return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, output_value)) # return _xla_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) simple_with_linear = SimpleWithLinear() From 2958d830163c113afcd53da8a1f14278355f9faa Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:16:53 +0000 Subject: [PATCH 127/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 5f56aaa7a9f..46b3d8aa25f 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -114,8 +114,8 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # return while_loop(cond_fn, body_fn, (iter, x)) # return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) # return 1 - return upper, lower, one_value, x, input_value, output_value - # return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, output_value)) + # return upper, lower, one_value, x, input_value, output_value + return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, output_value)) # return _xla_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) simple_with_linear = SimpleWithLinear() From 9db53a3cb8ea4b4120f6ceddbadbdcf4435bc594 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:35:04 +0000 Subject: [PATCH 128/323] update --- ...fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 46b3d8aa25f..db2230ad85f 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -109,8 +109,11 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): output_value_real = linear_0(input_value) weight = linear_0.weight bias = linear_0.bias + new_upper = upper + new_one_value = one_value + new_input_value = input_value # return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value_real - return upper, new_lower, one_value, torch.add(one_value, x), input_value, output_value_real + return new_upper, new_lower, new_one_value, torch.add(one_value, x), new_input_value, output_value_real # return while_loop(cond_fn, body_fn, (iter, x)) # return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) # return 1 From d35e48ef4fbf85d03ec86e31e4b855a371ee229f Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:36:11 +0000 Subject: [PATCH 129/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index db2230ad85f..666ee191109 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -113,7 +113,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): new_one_value = one_value new_input_value = input_value # return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value_real - return new_upper, new_lower, new_one_value, torch.add(one_value, x), new_input_value, output_value_real + return upper.copy(), lower.copy(), one_value.copy(), torch.add(one_value, x), input_value.copy(), output_value_real # return while_loop(cond_fn, body_fn, (iter, x)) # return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) # return 1 From 25ac04ed98217144733c3bc4ab3ac23b6f974f3f Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:37:47 +0000 Subject: [PATCH 130/323] update --- ...i_loop_with_while_loop_simple_add_dispatch_in_torch.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 666ee191109..19961d30e90 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -109,11 +109,11 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): output_value_real = linear_0(input_value) weight = linear_0.weight bias = linear_0.bias - new_upper = upper - new_one_value = one_value - new_input_value = input_value + # new_upper = upper + # new_one_value = one_value + # new_input_value = input_value # return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value_real - return upper.copy(), lower.copy(), one_value.copy(), torch.add(one_value, x), input_value.copy(), output_value_real + return upper.clone(), lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value_real # return while_loop(cond_fn, body_fn, (iter, x)) # return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) # return 1 From 3f473ad15ad38ebd05dcf8aff1656a03c5afbf30 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:42:21 +0000 Subject: [PATCH 131/323] update --- torch_xla/experimental/fori_loop.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 4396d25f184..cc15991f7a6 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -52,11 +52,13 @@ def while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): print("!!! arrive here too too !!!") - print("carried_inputs: ", carried_inputs) - print("additional_inputs: ", additional_inputs) + # print("carried_inputs: ", carried_inputs) + # print("additional_inputs: ", additional_inputs) # import pdb; pdb.set_trace() # untuple carried_inputs from while_loop carried_inputs = carried_inputs[0] + # TODO(@manfei): please clear pass additional_inputs in `while_loop`'s defination in this file + additional_inputs = carried_inputs[0] # fake carried_inputs to split formal code fake_carried_inputs = [] for carried_input in carried_inputs: From b31e28062a05094110d824be21de677ccab89a39 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:44:07 +0000 Subject: [PATCH 132/323] update --- torch_xla/experimental/fori_loop.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index cc15991f7a6..af014058009 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -52,8 +52,8 @@ def while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): print("!!! arrive here too too !!!") - # print("carried_inputs: ", carried_inputs) - # print("additional_inputs: ", additional_inputs) + print("carried_inputs: ", carried_inputs) + print("additional_inputs: ", additional_inputs) # import pdb; pdb.set_trace() # untuple carried_inputs from while_loop carried_inputs = carried_inputs[0] From 845d903893ecb04385e17652117ef0fd7795ca20 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:45:32 +0000 Subject: [PATCH 133/323] update --- torch_xla/experimental/fori_loop.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index af014058009..0da353ba660 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -50,15 +50,15 @@ def while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): return _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=additional_inputs) # a=a, b=b, c=c, -def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): +def _xla_while_loop(cond_fn, body_fn, *original_carried_inputs, additional_inputs=()): print("!!! arrive here too too !!!") print("carried_inputs: ", carried_inputs) print("additional_inputs: ", additional_inputs) # import pdb; pdb.set_trace() # untuple carried_inputs from while_loop - carried_inputs = carried_inputs[0] + carried_inputs = original_carried_inputs[0] # TODO(@manfei): please clear pass additional_inputs in `while_loop`'s defination in this file - additional_inputs = carried_inputs[0] + additional_inputs = original_carried_inputs[1] # fake carried_inputs to split formal code fake_carried_inputs = [] for carried_input in carried_inputs: From 13157d9b1158a7dcfb67d8e3df638ae1745cffdd Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:46:11 +0000 Subject: [PATCH 134/323] update --- torch_xla/experimental/fori_loop.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 0da353ba660..def0a5a0e38 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -52,8 +52,8 @@ def while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): def _xla_while_loop(cond_fn, body_fn, *original_carried_inputs, additional_inputs=()): print("!!! arrive here too too !!!") - print("carried_inputs: ", carried_inputs) - print("additional_inputs: ", additional_inputs) + # print("carried_inputs: ", carried_inputs) + # print("additional_inputs: ", additional_inputs) # import pdb; pdb.set_trace() # untuple carried_inputs from while_loop carried_inputs = original_carried_inputs[0] From 41d3ba6d11491e9bd09377880d84014ccab0b536 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:48:12 +0000 Subject: [PATCH 135/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- torch_xla/experimental/fori_loop.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 19961d30e90..d5a190279b1 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -113,7 +113,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # new_one_value = one_value # new_input_value = input_value # return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value_real - return upper.clone(), lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value_real + return upper.clone(), lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), weight, bias, output_value_real # return while_loop(cond_fn, body_fn, (iter, x)) # return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) # return 1 diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index def0a5a0e38..cff55d207bb 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -68,7 +68,7 @@ def _xla_while_loop(cond_fn, body_fn, *original_carried_inputs, additional_input torch.randint(10, carried_input.size(), dtype=carried_input.dtype).to(device)) # fake_carried_inputs = tuple(fake_carried_inputs) - print("fake_carried_inputs first: ", fake_carried_inputs) + # print("fake_carried_inputs first: ", fake_carried_inputs) for additional_input in additional_inputs: device = additional_input.device #TODO(@manfei) type = carried_input.type @@ -76,7 +76,7 @@ def _xla_while_loop(cond_fn, body_fn, *original_carried_inputs, additional_input torch.randint(10, additional_input.size(), dtype=additional_input.dtype).to(device)) fake_carried_inputs = tuple(fake_carried_inputs) - print("fake_carried_inputs second: ", fake_carried_inputs) + # print("fake_carried_inputs second: ", fake_carried_inputs) # generate cond_fn xlacomputation # TODO(@manfei): specify which element is for which argument like a,b,c From 52cd5bc9a6a7cc1bfae412b674c60561a9cf3887 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:49:08 +0000 Subject: [PATCH 136/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index d5a190279b1..ecfe7cd16f9 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -113,7 +113,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # new_one_value = one_value # new_input_value = input_value # return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value_real - return upper.clone(), lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), weight, bias, output_value_real + return upper.clone(), lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), weight.clone(), bias.clone(), output_value_real # return while_loop(cond_fn, body_fn, (iter, x)) # return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) # return 1 From a3756e6ef21ef12773bcfc331016b1fdf80226d8 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:50:48 +0000 Subject: [PATCH 137/323] update --- ...t_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index ecfe7cd16f9..bf015598af4 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -137,7 +137,8 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): aaa = {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} # upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = aaa # print("aaa: ", aaa) - bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, output_value) + # bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, output_value) + bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, weight_0, bias_0, output_value) print("bbb: ", bbb) # print("start test 6 !!!") return aaa From 21ba83dbff3d6987c91e624523cf895da80abca9 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:52:54 +0000 Subject: [PATCH 138/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index bf015598af4..3119a992ac3 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -100,7 +100,7 @@ def __init__(self): self.linear = torch.nn.Linear(10, 20).to(xm.xla_device()) # self.register_buffer("dec", torch.tensor(1)) - def forward(self, upper, lower, one_value, x, input_value, output_value): + def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] From 24f2fe3a3c89faa5ebfa86efc878d348a323c027 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:54:19 +0000 Subject: [PATCH 139/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 3119a992ac3..439c79b3393 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -118,7 +118,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) # return 1 # return upper, lower, one_value, x, input_value, output_value - return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, output_value)) + return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, weight_0, bias_0, output_value)) # return _xla_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) simple_with_linear = SimpleWithLinear() From 4687bbeee679def69b6790fe3f6c49b2d827f9a2 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:55:47 +0000 Subject: [PATCH 140/323] update --- torch_xla/experimental/fori_loop.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index cff55d207bb..59c925c83ed 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -69,14 +69,14 @@ def _xla_while_loop(cond_fn, body_fn, *original_carried_inputs, additional_input dtype=carried_input.dtype).to(device)) # fake_carried_inputs = tuple(fake_carried_inputs) # print("fake_carried_inputs first: ", fake_carried_inputs) - for additional_input in additional_inputs: - device = additional_input.device - #TODO(@manfei) type = carried_input.type - fake_carried_inputs.append( - torch.randint(10, additional_input.size(), - dtype=additional_input.dtype).to(device)) - fake_carried_inputs = tuple(fake_carried_inputs) - # print("fake_carried_inputs second: ", fake_carried_inputs) + # for additional_input in additional_inputs: + # device = additional_input.device + # #TODO(@manfei) type = carried_input.type + # fake_carried_inputs.append( + # torch.randint(10, additional_input.size(), + # dtype=additional_input.dtype).to(device)) + # fake_carried_inputs = tuple(fake_carried_inputs) + # # print("fake_carried_inputs second: ", fake_carried_inputs) # generate cond_fn xlacomputation # TODO(@manfei): specify which element is for which argument like a,b,c From 8713b1c4ba79e889e00fb56eee51445f73cae70b Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:56:36 +0000 Subject: [PATCH 141/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 439c79b3393..3ae1e5847ed 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -101,10 +101,10 @@ def __init__(self): # self.register_buffer("dec", torch.tensor(1)) def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): - def cond_fn(upper, lower, one_value, x, input_value, output_value): + def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): return lower[0] < upper[0] - def body_fn(upper, lower, one_value, x, input_value, output_value): + def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): new_lower = torch.add(one_value, lower) output_value_real = linear_0(input_value) weight = linear_0.weight From 05f1c33034020b678e8fb3056773ba12ed5331bb Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Fri, 12 Apr 2024 23:57:49 +0000 Subject: [PATCH 142/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 3ae1e5847ed..439c79b3393 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -101,10 +101,10 @@ def __init__(self): # self.register_buffer("dec", torch.tensor(1)) def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): - def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] - def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) output_value_real = linear_0(input_value) weight = linear_0.weight From d96d7355bcf681b5a2ecb137dbad700f7d08a6c0 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Sat, 13 Apr 2024 00:02:52 +0000 Subject: [PATCH 143/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 439c79b3393..3ae1e5847ed 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -101,10 +101,10 @@ def __init__(self): # self.register_buffer("dec", torch.tensor(1)) def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): - def cond_fn(upper, lower, one_value, x, input_value, output_value): + def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): return lower[0] < upper[0] - def body_fn(upper, lower, one_value, x, input_value, output_value): + def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): new_lower = torch.add(one_value, lower) output_value_real = linear_0(input_value) weight = linear_0.weight From e12bda67c7f8447ec259e5b6494418c05e946348 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Sat, 13 Apr 2024 00:04:29 +0000 Subject: [PATCH 144/323] update --- ...fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 3ae1e5847ed..608460153a4 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -100,7 +100,10 @@ def __init__(self): self.linear = torch.nn.Linear(10, 20).to(xm.xla_device()) # self.register_buffer("dec", torch.tensor(1)) - def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + def forward(self, upper, lower, one_value, x, input_value, output_value): + weight_0 = linear_0.weight + bias_0 = linear_0.bias + def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): return lower[0] < upper[0] From 8ed8f12ec102a3d61d0d6ab8914bcc9486fd2181 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Sat, 13 Apr 2024 00:05:18 +0000 Subject: [PATCH 145/323] update --- ...t_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 608460153a4..88cec10543d 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -100,10 +100,9 @@ def __init__(self): self.linear = torch.nn.Linear(10, 20).to(xm.xla_device()) # self.register_buffer("dec", torch.tensor(1)) - def forward(self, upper, lower, one_value, x, input_value, output_value): + def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): weight_0 = linear_0.weight bias_0 = linear_0.bias - def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): return lower[0] < upper[0] From 094a4cafc2f597652106a2098e55abee9c0f5e39 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Sat, 13 Apr 2024 00:05:43 +0000 Subject: [PATCH 146/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 88cec10543d..51a2cae47b2 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -101,8 +101,8 @@ def __init__(self): # self.register_buffer("dec", torch.tensor(1)) def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): - weight_0 = linear_0.weight - bias_0 = linear_0.bias + weight_0 = self.linear.weight + bias_0 = self.linear.bias def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): return lower[0] < upper[0] From 529a8c824f43a72c9f5e035cae512cff88b9c0ca Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Sat, 13 Apr 2024 00:10:15 +0000 Subject: [PATCH 147/323] update --- ...ori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 51a2cae47b2..0e17da9d940 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -101,8 +101,8 @@ def __init__(self): # self.register_buffer("dec", torch.tensor(1)) def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): - weight_0 = self.linear.weight - bias_0 = self.linear.bias + weight_1 = self.linear.weight + bias_1 = self.linear.bias def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): return lower[0] < upper[0] @@ -120,7 +120,7 @@ def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_va # return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) # return 1 # return upper, lower, one_value, x, input_value, output_value - return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, weight_0, bias_0, output_value)) + return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, weight_0, bias_0, output_value), (weight_1, bias_1)) # return _xla_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) simple_with_linear = SimpleWithLinear() From 57083aef6460ddd81f771be54abeb2fde0b1d25a Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Sat, 13 Apr 2024 00:10:59 +0000 Subject: [PATCH 148/323] update --- ...i_loop_with_while_loop_simple_add_dispatch_in_torch.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 0e17da9d940..a579d109ed6 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -108,9 +108,9 @@ def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_va def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): new_lower = torch.add(one_value, lower) - output_value_real = linear_0(input_value) - weight = linear_0.weight - bias = linear_0.bias + output_value_real = self.linear(input_value) + weight = self.linear.weight + bias = self.linear.bias # new_upper = upper # new_one_value = one_value # new_input_value = input_value @@ -120,7 +120,7 @@ def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_va # return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) # return 1 # return upper, lower, one_value, x, input_value, output_value - return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, weight_0, bias_0, output_value), (weight_1, bias_1)) + return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, weight_0, bias_0, output_value)) # return _xla_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) simple_with_linear = SimpleWithLinear() From 630caa9b88a38e677cce523b332821817b999172 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Sat, 13 Apr 2024 00:12:54 +0000 Subject: [PATCH 149/323] update --- ...i_loop_with_while_loop_simple_add_dispatch_in_torch.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index a579d109ed6..182f5fd6985 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -132,15 +132,15 @@ def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_va l_in_0 = torch.ones(10, device=xm.xla_device()) # input_value output_value = torch.zeros([20], dtype=torch.float32, device=device) - linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) - weight_0 = linear_0.weight - bias_0 = linear_0.bias + # linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) + weight_0 = simple_with_linear.linear.weight + bias_0 = simple_with_linear.linear.bias aaa = {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} # upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = aaa # print("aaa: ", aaa) # bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, output_value) - bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, weight_0, bias_0, output_value) + bbb = simple_with_linear((upper, lower, one_value, init_val, l_in_0, weight_0, bias_0, output_value), (weight_0, bias_0)) print("bbb: ", bbb) # print("start test 6 !!!") return aaa From 406635b973fed0212d4dd1f851fca581a2613be3 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Sat, 13 Apr 2024 00:14:34 +0000 Subject: [PATCH 150/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 182f5fd6985..0fdcc385493 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -140,7 +140,7 @@ def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_va # upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = aaa # print("aaa: ", aaa) # bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, output_value) - bbb = simple_with_linear((upper, lower, one_value, init_val, l_in_0, weight_0, bias_0, output_value), (weight_0, bias_0)) + bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, weight_0, bias_0, output_value, weight_0, bias_0) print("bbb: ", bbb) # print("start test 6 !!!") return aaa From 992546501e3f896dcea1a07601b80241988d4858 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Sat, 13 Apr 2024 00:15:20 +0000 Subject: [PATCH 151/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 0fdcc385493..b19e0c80243 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -140,7 +140,7 @@ def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_va # upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = aaa # print("aaa: ", aaa) # bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, output_value) - bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, weight_0, bias_0, output_value, weight_0, bias_0) + bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, weight_0, bias_0, output_value) # , weight_0, bias_0) print("bbb: ", bbb) # print("start test 6 !!!") return aaa From 9b1b7a72ffeb26a1ebb0044e7efb724c55bc4209 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 18:28:47 +0000 Subject: [PATCH 152/323] update --- ...t_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index b19e0c80243..2d64dcf1bab 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -100,7 +100,8 @@ def __init__(self): self.linear = torch.nn.Linear(10, 20).to(xm.xla_device()) # self.register_buffer("dec", torch.tensor(1)) - def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + # def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + def forward(self, upper, lower, one_value, x, input_value, output_value): weight_1 = self.linear.weight bias_1 = self.linear.bias def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): From 3cf020071931568b7df7bc8ff249c977a64c10bd Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 18:31:32 +0000 Subject: [PATCH 153/323] update --- ...ri_loop_with_while_loop_simple_add_dispatch_in_torch.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 2d64dcf1bab..40c81de463c 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -100,8 +100,8 @@ def __init__(self): self.linear = torch.nn.Linear(10, 20).to(xm.xla_device()) # self.register_buffer("dec", torch.tensor(1)) - # def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): - def forward(self, upper, lower, one_value, x, input_value, output_value): + def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + # def forward(self, upper, lower, one_value, x, input_value, output_value): weight_1 = self.linear.weight bias_1 = self.linear.bias def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): @@ -141,7 +141,8 @@ def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_va # upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = aaa # print("aaa: ", aaa) # bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, output_value) - bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, weight_0, bias_0, output_value) # , weight_0, bias_0) + # bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, weight_0, bias_0, output_value) # , weight_0, bias_0) + bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, output_value) print("bbb: ", bbb) # print("start test 6 !!!") return aaa From 1b06687e1fb551725067aa729394fdfd3831fff7 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 18:32:15 +0000 Subject: [PATCH 154/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 40c81de463c..f663f5fde04 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -142,7 +142,7 @@ def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_va # print("aaa: ", aaa) # bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, output_value) # bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, weight_0, bias_0, output_value) # , weight_0, bias_0) - bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, output_value) + bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, weight_0, bias_0, output_value) print("bbb: ", bbb) # print("start test 6 !!!") return aaa From 13b77670d9e3df788ea01d561e4fcd9d864c973a Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 18:35:35 +0000 Subject: [PATCH 155/323] update --- ...th_while_loop_simple_add_dispatch_in_torch.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index f663f5fde04..63bf159f0c8 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -100,14 +100,16 @@ def __init__(self): self.linear = torch.nn.Linear(10, 20).to(xm.xla_device()) # self.register_buffer("dec", torch.tensor(1)) - def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): - # def forward(self, upper, lower, one_value, x, input_value, output_value): + # def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + def forward(self, upper, lower, one_value, x, input_value, output_value): weight_1 = self.linear.weight bias_1 = self.linear.bias - def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + # def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] - def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + # def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) output_value_real = self.linear(input_value) weight = self.linear.weight @@ -121,7 +123,8 @@ def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_va # return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) # return 1 # return upper, lower, one_value, x, input_value, output_value - return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, weight_0, bias_0, output_value)) + # return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, weight_0, bias_0, output_value)) + return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, weight_1, bias_1, output_value)) # return _xla_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) simple_with_linear = SimpleWithLinear() @@ -142,7 +145,8 @@ def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_va # print("aaa: ", aaa) # bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, output_value) # bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, weight_0, bias_0, output_value) # , weight_0, bias_0) - bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, weight_0, bias_0, output_value) + # bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, weight_0, bias_0, output_value) + bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, output_value) print("bbb: ", bbb) # print("start test 6 !!!") return aaa From 90f6df1db6c43025994bce2bf01356370736b65d Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 18:36:36 +0000 Subject: [PATCH 156/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 63bf159f0c8..fa69205cf75 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -124,8 +124,8 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # return 1 # return upper, lower, one_value, x, input_value, output_value # return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, weight_0, bias_0, output_value)) - return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, weight_1, bias_1, output_value)) - # return _xla_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) + # return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, weight_1, bias_1, output_value)) + return _xla_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) simple_with_linear = SimpleWithLinear() upper = torch.tensor([52], dtype=torch.int32, device=device) From 732876b7f78015781359dc148a6fef0c97734760 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 18:37:04 +0000 Subject: [PATCH 157/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index fa69205cf75..94a4e753f10 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -7,7 +7,7 @@ # We need to import the underlying implementation function to register with the dispatcher import torch_xla.experimental.fori_loop from torch_xla.experimental.fori_loop import fori_loop -# from torch_xla.experimental.fori_loop import _xla_while_loop +from torch_xla.experimental.fori_loop import _xla_while_loop from torch._higher_order_ops.while_loop import while_loop import torch_xla.core.xla_model as xm import torch_xla.core.xla_builder as xb From 1ec25fef85e3267f2530923e9ce9582a3d866947 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 18:38:11 +0000 Subject: [PATCH 158/323] update --- ...ori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 6 +++--- torch_xla/experimental/fori_loop.py | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 94a4e753f10..63bf159f0c8 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -7,7 +7,7 @@ # We need to import the underlying implementation function to register with the dispatcher import torch_xla.experimental.fori_loop from torch_xla.experimental.fori_loop import fori_loop -from torch_xla.experimental.fori_loop import _xla_while_loop +# from torch_xla.experimental.fori_loop import _xla_while_loop from torch._higher_order_ops.while_loop import while_loop import torch_xla.core.xla_model as xm import torch_xla.core.xla_builder as xb @@ -124,8 +124,8 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # return 1 # return upper, lower, one_value, x, input_value, output_value # return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, weight_0, bias_0, output_value)) - # return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, weight_1, bias_1, output_value)) - return _xla_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) + return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, weight_1, bias_1, output_value)) + # return _xla_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) simple_with_linear = SimpleWithLinear() upper = torch.tensor([52], dtype=torch.int32, device=device) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 59c925c83ed..7d53701a444 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -58,7 +58,8 @@ def _xla_while_loop(cond_fn, body_fn, *original_carried_inputs, additional_input # untuple carried_inputs from while_loop carried_inputs = original_carried_inputs[0] # TODO(@manfei): please clear pass additional_inputs in `while_loop`'s defination in this file - additional_inputs = original_carried_inputs[1] + if len(original_carried_inputs) == 2: + additional_inputs = original_carried_inputs[1] # fake carried_inputs to split formal code fake_carried_inputs = [] for carried_input in carried_inputs: From fdb7cabb2c77829c2b424dd4ec56215aac4ba4df Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 18:39:02 +0000 Subject: [PATCH 159/323] update --- ...i_loop_with_while_loop_simple_add_dispatch_in_torch.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 63bf159f0c8..1ca0d4aa8fb 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -104,12 +104,12 @@ def __init__(self): def forward(self, upper, lower, one_value, x, input_value, output_value): weight_1 = self.linear.weight bias_1 = self.linear.bias - # def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): - def cond_fn(upper, lower, one_value, x, input_value, output_value): + def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + # def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] - # def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): - def body_fn(upper, lower, one_value, x, input_value, output_value): + def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + # def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) output_value_real = self.linear(input_value) weight = self.linear.weight From 17d43eff82536499381458e7bcbea00440274fa9 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 18:41:07 +0000 Subject: [PATCH 160/323] update --- torch_xla/experimental/fori_loop.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 7d53701a444..a11697e33c5 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -79,6 +79,7 @@ def _xla_while_loop(cond_fn, body_fn, *original_carried_inputs, additional_input # fake_carried_inputs = tuple(fake_carried_inputs) # # print("fake_carried_inputs second: ", fake_carried_inputs) + print("!!! arrive here too before cond !!!") # generate cond_fn xlacomputation # TODO(@manfei): specify which element is for which argument like a,b,c cond_result = cond_fn(*fake_carried_inputs) # [:-3], weight_0=fake_carried_inputs[-2], output_value=fake_carried_inputs[-3], bias_0=fake_carried_inputs[-1]) @@ -92,7 +93,9 @@ def _xla_while_loop(cond_fn, body_fn, *original_carried_inputs, additional_input cond_hlo = cond_ctx.hlo() cond_computation = xb.computation_from_module_proto("condcomputation", cond_hlo) + print("!!! arrive here too after cond !!!") + print("!!! arrive here too before body !!!") # generate body_fn xlacomputation body_result = body_fn(*fake_carried_inputs) # [:-3], weight_0=fake_carried_inputs[-1], output_value=fake_carried_inputs[-3], bias_0=fake_carried_inputs[-2]) body_ctx = torch_xla._XLAC.lowering.LoweringContext() @@ -109,7 +112,9 @@ def _xla_while_loop(cond_fn, body_fn, *original_carried_inputs, additional_input body_hlo = body_ctx.hlo() body_computation = xb.computation_from_module_proto("bodycomputation", body_hlo) + print("!!! arrive here too after body !!!") + print("!!! arrive here too before args!!!") # trans fake_carried_inputs from list(tensor) to list(xla::op), which part could change init of xla::while kwargs = {} if type(carried_inputs) is tuple: @@ -130,10 +135,13 @@ def _xla_while_loop(cond_fn, body_fn, *original_carried_inputs, additional_input body_computation=body_computation) name = 'fori_loop_ed_torch_func' computation = w.build(name) + print("!!! arrive here too after args!!!") + print("!!! arrive here too before while!!!") # gain final result with generated while xlacomputation result = torch_xla._XLAC._xla_user_computation('xla::_op_test_while', (carried_inputs), computation) + print("!!! arrive here too after while!!!") return result \ No newline at end of file From 0016420a184ca374cb32ba96c568add2cf9a4df4 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 18:42:14 +0000 Subject: [PATCH 161/323] update --- torch_xla/experimental/fori_loop.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index a11697e33c5..c9decb56964 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -87,8 +87,10 @@ def _xla_while_loop(cond_fn, body_fn, *original_carried_inputs, additional_input cond_ctx.set_name_string("condctx") additional_inputs_list_cond = list(fake_carried_inputs[2:]) # all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor # treat and pass additional_inputs to cond_fn + print("additional_inputs_list_cond one: ", additional_inputs_list_cond) for i in range(len(additional_inputs)): additional_inputs_list_cond.append(additional_inputs[i]) + print("additional_inputs_list_cond two: ", additional_inputs_list_cond) cond_ctx.buildforiloop([cond_result], additional_inputs_list_cond) cond_hlo = cond_ctx.hlo() cond_computation = xb.computation_from_module_proto("condcomputation", From 42745757d6d08f90622e21f7f8f9012b0311eddf Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 18:43:01 +0000 Subject: [PATCH 162/323] update --- torch_xla/experimental/fori_loop.py | 1 + 1 file changed, 1 insertion(+) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index c9decb56964..048da5eb9a2 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -83,6 +83,7 @@ def _xla_while_loop(cond_fn, body_fn, *original_carried_inputs, additional_input # generate cond_fn xlacomputation # TODO(@manfei): specify which element is for which argument like a,b,c cond_result = cond_fn(*fake_carried_inputs) # [:-3], weight_0=fake_carried_inputs[-2], output_value=fake_carried_inputs[-3], bias_0=fake_carried_inputs[-1]) + print("nnn here ???") cond_ctx = torch_xla._XLAC.lowering.LoweringContext() cond_ctx.set_name_string("condctx") additional_inputs_list_cond = list(fake_carried_inputs[2:]) # all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor From 4fd2e4a0cb6b4edd3c89bd5a2d4223138154a763 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 18:43:44 +0000 Subject: [PATCH 163/323] update --- torch_xla/experimental/fori_loop.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 048da5eb9a2..0d89dfce829 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -81,9 +81,10 @@ def _xla_while_loop(cond_fn, body_fn, *original_carried_inputs, additional_input print("!!! arrive here too before cond !!!") # generate cond_fn xlacomputation + print("print fake_carried_inputs: ", fake_carried_inputs) # TODO(@manfei): specify which element is for which argument like a,b,c cond_result = cond_fn(*fake_carried_inputs) # [:-3], weight_0=fake_carried_inputs[-2], output_value=fake_carried_inputs[-3], bias_0=fake_carried_inputs[-1]) - print("nnn here ???") + # print("nnn here ???") cond_ctx = torch_xla._XLAC.lowering.LoweringContext() cond_ctx.set_name_string("condctx") additional_inputs_list_cond = list(fake_carried_inputs[2:]) # all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor From b06290031ed720bb41fe2ae8da1817faa27c45a6 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 18:45:29 +0000 Subject: [PATCH 164/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 1ca0d4aa8fb..93eab72bc9b 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -100,8 +100,8 @@ def __init__(self): self.linear = torch.nn.Linear(10, 20).to(xm.xla_device()) # self.register_buffer("dec", torch.tensor(1)) - # def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): - def forward(self, upper, lower, one_value, x, input_value, output_value): + def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + # def forward(self, upper, lower, one_value, x, input_value, output_value): weight_1 = self.linear.weight bias_1 = self.linear.bias def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): From c2f29737be0856f08302d13367ba8e49b68b2dc7 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 18:46:06 +0000 Subject: [PATCH 165/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 93eab72bc9b..1ca0d4aa8fb 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -100,8 +100,8 @@ def __init__(self): self.linear = torch.nn.Linear(10, 20).to(xm.xla_device()) # self.register_buffer("dec", torch.tensor(1)) - def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): - # def forward(self, upper, lower, one_value, x, input_value, output_value): + # def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + def forward(self, upper, lower, one_value, x, input_value, output_value): weight_1 = self.linear.weight bias_1 = self.linear.bias def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): From 8dbde24acbfcd0312728b8d02a1ba7be8be5a7b3 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 18:47:08 +0000 Subject: [PATCH 166/323] update --- ...ri_loop_with_while_loop_simple_add_dispatch_in_torch.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 1ca0d4aa8fb..4e93f32d48b 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -104,11 +104,14 @@ def __init__(self): def forward(self, upper, lower, one_value, x, input_value, output_value): weight_1 = self.linear.weight bias_1 = self.linear.bias - def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + + # def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + def cond_fn(upper, lower, one_value, x, input_value, weight_1, bias_1, output_value): # def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] - def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + # def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + def body_fn(upper, lower, one_value, x, input_value, weight_1, bias_1, output_value): # def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) output_value_real = self.linear(input_value) From 066047c56280cd1204a41c38377fa0eb3bd5ac7b Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 20:19:07 +0000 Subject: [PATCH 167/323] update --- ..._with_while_loop_simple_add_dispatch_in_torch.py | 13 +++++++------ torch_xla/experimental/fori_loop.py | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 4e93f32d48b..7d12ab6f517 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -102,16 +102,16 @@ def __init__(self): # def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): def forward(self, upper, lower, one_value, x, input_value, output_value): - weight_1 = self.linear.weight - bias_1 = self.linear.bias + # weight_1 = self.linear.weight + # bias_1 = self.linear.bias - # def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): - def cond_fn(upper, lower, one_value, x, input_value, weight_1, bias_1, output_value): + def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + # def cond_fn(upper, lower, one_value, x, input_value, weight_1, bias_1, output_value): # def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] - # def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): - def body_fn(upper, lower, one_value, x, input_value, weight_1, bias_1, output_value): + def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + # def body_fn(upper, lower, one_value, x, input_value, weight_1, bias_1, output_value): # def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) output_value_real = self.linear(input_value) @@ -128,6 +128,7 @@ def body_fn(upper, lower, one_value, x, input_value, weight_1, bias_1, output_va # return upper, lower, one_value, x, input_value, output_value # return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, weight_0, bias_0, output_value)) return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, weight_1, bias_1, output_value)) + # return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, output_value)) # return _xla_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) simple_with_linear = SimpleWithLinear() diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 0d89dfce829..600950f48ac 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -84,7 +84,7 @@ def _xla_while_loop(cond_fn, body_fn, *original_carried_inputs, additional_input print("print fake_carried_inputs: ", fake_carried_inputs) # TODO(@manfei): specify which element is for which argument like a,b,c cond_result = cond_fn(*fake_carried_inputs) # [:-3], weight_0=fake_carried_inputs[-2], output_value=fake_carried_inputs[-3], bias_0=fake_carried_inputs[-1]) - # print("nnn here ???") + print("nnn here ???") cond_ctx = torch_xla._XLAC.lowering.LoweringContext() cond_ctx.set_name_string("condctx") additional_inputs_list_cond = list(fake_carried_inputs[2:]) # all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor From 374d16d06cc541ff5f301764372d487aa74fa4ff Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 20:19:48 +0000 Subject: [PATCH 168/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 7d12ab6f517..6133d205242 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -127,8 +127,8 @@ def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_va # return 1 # return upper, lower, one_value, x, input_value, output_value # return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, weight_0, bias_0, output_value)) - return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, weight_1, bias_1, output_value)) - # return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, output_value)) + # return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, weight_1, bias_1, output_value)) + return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, output_value)) # return _xla_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) simple_with_linear = SimpleWithLinear() From 1f30e268996448e19935b8289cde2323633e3e03 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 20:21:34 +0000 Subject: [PATCH 169/323] update --- ...i_loop_with_while_loop_simple_add_dispatch_in_torch.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 6133d205242..6162c3b921f 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -105,14 +105,14 @@ def forward(self, upper, lower, one_value, x, input_value, output_value): # weight_1 = self.linear.weight # bias_1 = self.linear.bias - def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + # def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): # def cond_fn(upper, lower, one_value, x, input_value, weight_1, bias_1, output_value): - # def cond_fn(upper, lower, one_value, x, input_value, output_value): + def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] - def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + # def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): # def body_fn(upper, lower, one_value, x, input_value, weight_1, bias_1, output_value): - # def body_fn(upper, lower, one_value, x, input_value, output_value): + def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) output_value_real = self.linear(input_value) weight = self.linear.weight From fc85bc3e1dcf7cf80dea7714d359cf7503b2251a Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 20:23:17 +0000 Subject: [PATCH 170/323] update --- torch_xla/experimental/fori_loop.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 600950f48ac..fab9ba09c50 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -53,12 +53,13 @@ def while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): def _xla_while_loop(cond_fn, body_fn, *original_carried_inputs, additional_inputs=()): print("!!! arrive here too too !!!") # print("carried_inputs: ", carried_inputs) - # print("additional_inputs: ", additional_inputs) + print("additional_inputs: ", additional_inputs) # import pdb; pdb.set_trace() # untuple carried_inputs from while_loop carried_inputs = original_carried_inputs[0] # TODO(@manfei): please clear pass additional_inputs in `while_loop`'s defination in this file if len(original_carried_inputs) == 2: + print("use original_carried_inputs for additional_inputs") additional_inputs = original_carried_inputs[1] # fake carried_inputs to split formal code fake_carried_inputs = [] From 6ebda73b33bb1e61279b513f67bac44f20214c45 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 20:24:25 +0000 Subject: [PATCH 171/323] update --- torch_xla/experimental/fori_loop.py | 1 + 1 file changed, 1 insertion(+) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index fab9ba09c50..097f67687a3 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -45,6 +45,7 @@ def while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): # cond_fn&body_fn: callable # carried_inputs: (Tuple of possibly nested dict/list/tuple of tensors) print("!!! arrive here too !!!") + print("while_loop additional_inputs: ", additional_inputs) if additional_inputs is None: additional_inputs = tuple() return _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=additional_inputs) # a=a, b=b, c=c, From 55c2ea11432f9c0de4fcf2f6535a2abe072780e2 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 20:30:32 +0000 Subject: [PATCH 172/323] update --- torch_xla/experimental/fori_loop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 097f67687a3..31bc893f1d9 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -40,7 +40,7 @@ def body_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bi @while_loop_op.py_impl(DispatchKey.XLA) -def while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=None): +def while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs): # TODO(@manfei): PyTorch require carried_inputs to be list/tuple, PyTorch/XLA _xla_while_loop only accept *operands, *operands would tuple items again: (a, '') # cond_fn&body_fn: callable # carried_inputs: (Tuple of possibly nested dict/list/tuple of tensors) From 36d256525fc2bd140abaaec4794e154e3f0e1f81 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 20:38:12 +0000 Subject: [PATCH 173/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 6162c3b921f..c8276bfb16d 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -92,7 +92,7 @@ def test_while_loop_tpu_simple_linear(self): xm.mark_step() device = xm.xla_device() - torch.set_grad_enabled(False) + # torch.set_grad_enabled(False) class SimpleWithLinear(torch.nn.Module): def __init__(self): From 4a500c019914096ad1398b13b4403b34ab575c54 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 20:39:39 +0000 Subject: [PATCH 174/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index c8276bfb16d..6162c3b921f 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -92,7 +92,7 @@ def test_while_loop_tpu_simple_linear(self): xm.mark_step() device = xm.xla_device() - # torch.set_grad_enabled(False) + torch.set_grad_enabled(False) class SimpleWithLinear(torch.nn.Module): def __init__(self): From 3a2553e4b9335c2b74ca117cfd500d72dac9823d Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 20:50:00 +0000 Subject: [PATCH 175/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 6162c3b921f..152606a7d6a 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -128,7 +128,9 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # return upper, lower, one_value, x, input_value, output_value # return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, weight_0, bias_0, output_value)) # return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, weight_1, bias_1, output_value)) - return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, output_value)) + weight_1 = self.linear.weight + bias_1 = self.linear.bias + return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, output_value), (bias_1, weight_1)) # return _xla_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) simple_with_linear = SimpleWithLinear() From 0998b374e1344edb7d903be54e76ff9fb3ccb1a6 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 20:51:08 +0000 Subject: [PATCH 176/323] update --- ...ri_loop_with_while_loop_simple_add_dispatch_in_torch.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 152606a7d6a..7fd99631943 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -128,9 +128,10 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # return upper, lower, one_value, x, input_value, output_value # return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, weight_0, bias_0, output_value)) # return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, weight_1, bias_1, output_value)) - weight_1 = self.linear.weight - bias_1 = self.linear.bias - return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, output_value), (bias_1, weight_1)) + # weight_1 = self.linear.weight + # bias_1 = self.linear.bias + # return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, output_value), (bias_1, weight_1)) + return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, output_value)) # return _xla_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) simple_with_linear = SimpleWithLinear() From 267e8b3460fe4b2e9a3779383843ec8e19c33acc Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 20:54:12 +0000 Subject: [PATCH 177/323] update --- torch_xla/experimental/fori_loop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 31bc893f1d9..68db30dd6fa 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -40,7 +40,7 @@ def body_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bi @while_loop_op.py_impl(DispatchKey.XLA) -def while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs): +def while_loop(cond_fn, body_fn, carried_inputs, additional_inputs): # TODO(@manfei): PyTorch require carried_inputs to be list/tuple, PyTorch/XLA _xla_while_loop only accept *operands, *operands would tuple items again: (a, '') # cond_fn&body_fn: callable # carried_inputs: (Tuple of possibly nested dict/list/tuple of tensors) From a577859eff905e076e25a06a2b0d70101901f948 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 20:57:08 +0000 Subject: [PATCH 178/323] update --- torch_xla/experimental/fori_loop.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 68db30dd6fa..fb8f8234b16 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -45,7 +45,7 @@ def while_loop(cond_fn, body_fn, carried_inputs, additional_inputs): # cond_fn&body_fn: callable # carried_inputs: (Tuple of possibly nested dict/list/tuple of tensors) print("!!! arrive here too !!!") - print("while_loop additional_inputs: ", additional_inputs) + # print("while_loop additional_inputs: ", additional_inputs) if additional_inputs is None: additional_inputs = tuple() return _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=additional_inputs) # a=a, b=b, c=c, @@ -53,7 +53,7 @@ def while_loop(cond_fn, body_fn, carried_inputs, additional_inputs): def _xla_while_loop(cond_fn, body_fn, *original_carried_inputs, additional_inputs=()): print("!!! arrive here too too !!!") - # print("carried_inputs: ", carried_inputs) + print("carried_inputs: ", carried_inputs) print("additional_inputs: ", additional_inputs) # import pdb; pdb.set_trace() # untuple carried_inputs from while_loop From a3ee72aefe21c863b4cfc052ab82a9468cc85b9e Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 20:57:39 +0000 Subject: [PATCH 179/323] update --- torch_xla/experimental/fori_loop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index fb8f8234b16..8c8d47ca494 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -53,7 +53,7 @@ def while_loop(cond_fn, body_fn, carried_inputs, additional_inputs): def _xla_while_loop(cond_fn, body_fn, *original_carried_inputs, additional_inputs=()): print("!!! arrive here too too !!!") - print("carried_inputs: ", carried_inputs) + print("original_carried_inputs: ", original_carried_inputs) print("additional_inputs: ", additional_inputs) # import pdb; pdb.set_trace() # untuple carried_inputs from while_loop From 293b87aa9bf7729c995345e3964b3eb311c78a04 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 21:00:34 +0000 Subject: [PATCH 180/323] update --- torch_xla/experimental/fori_loop.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 8c8d47ca494..aceb585ab45 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -53,11 +53,11 @@ def while_loop(cond_fn, body_fn, carried_inputs, additional_inputs): def _xla_while_loop(cond_fn, body_fn, *original_carried_inputs, additional_inputs=()): print("!!! arrive here too too !!!") - print("original_carried_inputs: ", original_carried_inputs) - print("additional_inputs: ", additional_inputs) + # print("original_carried_inputs: ", original_carried_inputs) + # print("additional_inputs: ", additional_inputs) # import pdb; pdb.set_trace() # untuple carried_inputs from while_loop - carried_inputs = original_carried_inputs[0] + # carried_inputs = original_carried_inputs[0] # due to PyTorch has already treat them , so skip split here # TODO(@manfei): please clear pass additional_inputs in `while_loop`'s defination in this file if len(original_carried_inputs) == 2: print("use original_carried_inputs for additional_inputs") From 128a3dcf6a37dd959716777fcb8edb9447556cad Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 21:02:13 +0000 Subject: [PATCH 181/323] update --- ...op_with_while_loop_simple_add_dispatch_in_torch.py | 8 ++++---- torch_xla/experimental/fori_loop.py | 11 ++++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 7fd99631943..8e5eead8fc3 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -105,14 +105,14 @@ def forward(self, upper, lower, one_value, x, input_value, output_value): # weight_1 = self.linear.weight # bias_1 = self.linear.bias - # def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): # def cond_fn(upper, lower, one_value, x, input_value, weight_1, bias_1, output_value): - def cond_fn(upper, lower, one_value, x, input_value, output_value): + # def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] - # def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): # def body_fn(upper, lower, one_value, x, input_value, weight_1, bias_1, output_value): - def body_fn(upper, lower, one_value, x, input_value, output_value): + # def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) output_value_real = self.linear(input_value) weight = self.linear.weight diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index aceb585ab45..1b874ed9db2 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -51,17 +51,18 @@ def while_loop(cond_fn, body_fn, carried_inputs, additional_inputs): return _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=additional_inputs) # a=a, b=b, c=c, -def _xla_while_loop(cond_fn, body_fn, *original_carried_inputs, additional_inputs=()): +def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): print("!!! arrive here too too !!!") # print("original_carried_inputs: ", original_carried_inputs) # print("additional_inputs: ", additional_inputs) # import pdb; pdb.set_trace() # untuple carried_inputs from while_loop - # carried_inputs = original_carried_inputs[0] # due to PyTorch has already treat them , so skip split here + # carried_inputs = original_carried_inputs[0] ### due to PyTorch has already treat them , so skip split here # TODO(@manfei): please clear pass additional_inputs in `while_loop`'s defination in this file - if len(original_carried_inputs) == 2: - print("use original_carried_inputs for additional_inputs") - additional_inputs = original_carried_inputs[1] + ### due to PyTorch has already treat them , so skip split here + # if len(original_carried_inputs) == 2: + # print("use original_carried_inputs for additional_inputs") + # additional_inputs = original_carried_inputs[1] # fake carried_inputs to split formal code fake_carried_inputs = [] for carried_input in carried_inputs: From f5298a59da61247956280cc274f478d0edfc6c39 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 21:03:27 +0000 Subject: [PATCH 182/323] update --- ...i_loop_with_while_loop_simple_add_dispatch_in_torch.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 8e5eead8fc3..7fd99631943 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -105,14 +105,14 @@ def forward(self, upper, lower, one_value, x, input_value, output_value): # weight_1 = self.linear.weight # bias_1 = self.linear.bias - def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + # def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): # def cond_fn(upper, lower, one_value, x, input_value, weight_1, bias_1, output_value): - # def cond_fn(upper, lower, one_value, x, input_value, output_value): + def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] - def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + # def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): # def body_fn(upper, lower, one_value, x, input_value, weight_1, bias_1, output_value): - # def body_fn(upper, lower, one_value, x, input_value, output_value): + def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) output_value_real = self.linear(input_value) weight = self.linear.weight From e4104a4719837c6071ee2d1088af757f64ca0cf2 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 21:05:51 +0000 Subject: [PATCH 183/323] update --- ...t_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 7fd99631943..a4566395afe 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -101,7 +101,8 @@ def __init__(self): # self.register_buffer("dec", torch.tensor(1)) # def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): - def forward(self, upper, lower, one_value, x, input_value, output_value): + # def forward(self, upper, lower, one_value, x, input_value, output_value): + def forward(self, upper, lower, one_value, x, input_value, output_value, bias_0, weight_0): # weight_1 = self.linear.weight # bias_1 = self.linear.bias From 2ef7d32a0a3465de9f0bb4f8b59026df74f0b407 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 21:07:16 +0000 Subject: [PATCH 184/323] update --- ...p_with_while_loop_simple_add_dispatch_in_torch.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index a4566395afe..0bce0779c6b 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -100,20 +100,20 @@ def __init__(self): self.linear = torch.nn.Linear(10, 20).to(xm.xla_device()) # self.register_buffer("dec", torch.tensor(1)) - # def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): # def forward(self, upper, lower, one_value, x, input_value, output_value): - def forward(self, upper, lower, one_value, x, input_value, output_value, bias_0, weight_0): + # def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): # weight_1 = self.linear.weight # bias_1 = self.linear.bias - # def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): # def cond_fn(upper, lower, one_value, x, input_value, weight_1, bias_1, output_value): - def cond_fn(upper, lower, one_value, x, input_value, output_value): + # def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] - # def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): # def body_fn(upper, lower, one_value, x, input_value, weight_1, bias_1, output_value): - def body_fn(upper, lower, one_value, x, input_value, output_value): + # def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) output_value_real = self.linear(input_value) weight = self.linear.weight From 4affdd72b63047ab0c799bd6bcba595d11aaa158 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 21:09:27 +0000 Subject: [PATCH 185/323] update --- ...p_with_while_loop_simple_add_dispatch_in_torch.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 0bce0779c6b..eb108d59c46 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -100,20 +100,20 @@ def __init__(self): self.linear = torch.nn.Linear(10, 20).to(xm.xla_device()) # self.register_buffer("dec", torch.tensor(1)) - def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): - # def forward(self, upper, lower, one_value, x, input_value, output_value): + # def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + def forward(self, upper, lower, one_value, x, input_value, output_value): # def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): # weight_1 = self.linear.weight # bias_1 = self.linear.bias - def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + # def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): # def cond_fn(upper, lower, one_value, x, input_value, weight_1, bias_1, output_value): - # def cond_fn(upper, lower, one_value, x, input_value, output_value): + def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] - def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + # def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): # def body_fn(upper, lower, one_value, x, input_value, weight_1, bias_1, output_value): - # def body_fn(upper, lower, one_value, x, input_value, output_value): + def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) output_value_real = self.linear(input_value) weight = self.linear.weight From 325425388cdb06b62d56c13713ee6cc3b30d6238 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 21:10:58 +0000 Subject: [PATCH 186/323] update --- torch_xla/experimental/fori_loop.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 1b874ed9db2..29735ee1d38 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -72,15 +72,15 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): torch.randint(10, carried_input.size(), dtype=carried_input.dtype).to(device)) # fake_carried_inputs = tuple(fake_carried_inputs) - # print("fake_carried_inputs first: ", fake_carried_inputs) - # for additional_input in additional_inputs: - # device = additional_input.device - # #TODO(@manfei) type = carried_input.type - # fake_carried_inputs.append( - # torch.randint(10, additional_input.size(), - # dtype=additional_input.dtype).to(device)) + print("fake_carried_inputs first: ", fake_carried_inputs) + for additional_input in additional_inputs: + device = additional_input.device + #TODO(@manfei) type = carried_input.type + fake_carried_inputs.append( + torch.randint(10, additional_input.size(), + dtype=additional_input.dtype).to(device)) # fake_carried_inputs = tuple(fake_carried_inputs) - # # print("fake_carried_inputs second: ", fake_carried_inputs) + print("fake_carried_inputs second: ", fake_carried_inputs) print("!!! arrive here too before cond !!!") # generate cond_fn xlacomputation From 92887e70e25c00f9789fe8e567b9f4e1b97412ae Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 21:12:31 +0000 Subject: [PATCH 187/323] update --- torch_xla/csrc/init_python_bindings.cpp | 28 ++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index 145739e1d1a..fa29bfdd4c8 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -925,26 +925,26 @@ class PyLoweringContext { // !!! --- next step: we add dump paras according to additional_inputs_list // ??? --- could we get IRvalue of `additional_inputs_list` in this function to complete xlacomputation? int64_t parameter_idx = 2; // parameter_idx start from 2 after upper and lower - for (auto& additional_input_tensor : additional_inputs_list) { - XLATensorPtr xtensor = bridge::GetXlaTensor(additional_input_tensor); - xla::Shape shape = xtensor->shape().get(); - xla::XlaOp x = xla::Parameter(local_builder, parameter_idx, shape, - "UnusedArgumentsPlaceholder"); - parameter_idx += 1; - } + // for (auto& additional_input_tensor : additional_inputs_list) { + // XLATensorPtr xtensor = bridge::GetXlaTensor(additional_input_tensor); + // xla::Shape shape = xtensor->shape().get(); + // xla::XlaOp x = xla::Parameter(local_builder, parameter_idx, shape, + // "UnusedArgumentsPlaceholder"); + // parameter_idx += 1; + // } } // hard-code modify body xlacomputation input arguments if (GetNameString() == "bodyctx") { xla::XlaBuilder* local_builder = lowering_ctx.builder(); int64_t parameter_idx = 7; // tensors.size(); - for (auto& additional_input_tensor : additional_inputs_list) { - XLATensorPtr xtensor = bridge::GetXlaTensor(additional_input_tensor); - xla::Shape shape = xtensor->shape().get(); - xla::XlaOp x = xla::Parameter(local_builder, parameter_idx, shape, - "UnusedArgumentsPlaceholder"); - parameter_idx += 1; - } + // for (auto& additional_input_tensor : additional_inputs_list) { + // XLATensorPtr xtensor = bridge::GetXlaTensor(additional_input_tensor); + // xla::Shape shape = xtensor->shape().get(); + // xla::XlaOp x = xla::Parameter(local_builder, parameter_idx, shape, + // "UnusedArgumentsPlaceholder"); + // parameter_idx += 1; + // } } // Get the backing XLA tensors from the output torch tensor handles From 98425a88746da7d5d70a26ce02a70780252159c8 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 21:14:30 +0000 Subject: [PATCH 188/323] update --- torch_xla/experimental/fori_loop.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 29735ee1d38..d7f54af3ee4 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -133,7 +133,10 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): for shape in shapes: p = xb.mkparam(builder, len(params), shape) params.append(p) + print("args params: ", params) + print("!!! arrive here too after args!!!") + print("!!! arrive here too before while!!!") # generate while xlacomputation input_tuple = xb.Op.tuple(tuple(params)) w = xb.mkop( @@ -142,9 +145,7 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): body_computation=body_computation) name = 'fori_loop_ed_torch_func' computation = w.build(name) - print("!!! arrive here too after args!!!") - print("!!! arrive here too before while!!!") # gain final result with generated while xlacomputation result = torch_xla._XLAC._xla_user_computation('xla::_op_test_while', (carried_inputs), From 862e3f16f1259819ad7d3a322080de8ef30f5916 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 21:18:22 +0000 Subject: [PATCH 189/323] update --- torch_xla/experimental/fori_loop.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index d7f54af3ee4..94080b31979 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -122,6 +122,8 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): print("!!! arrive here too after body !!!") print("!!! arrive here too before args!!!") + total_inputs = carried_inputs + additional_inputs + print("total_inputs: ", total_inputs) # trans fake_carried_inputs from list(tensor) to list(xla::op), which part could change init of xla::while kwargs = {} if type(carried_inputs) is tuple: From 6b07e22d1d6eddaed524b89d79b4968c0a196815 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 21:20:13 +0000 Subject: [PATCH 190/323] update --- torch_xla/experimental/fori_loop.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 94080b31979..27d6c214980 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -126,10 +126,10 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): print("total_inputs: ", total_inputs) # trans fake_carried_inputs from list(tensor) to list(xla::op), which part could change init of xla::while kwargs = {} - if type(carried_inputs) is tuple: - shapes = xb.tensor_shape(carried_inputs) + if type(total_inputs) is tuple: + shapes = xb.tensor_shape(total_inputs) else: - shapes = xb.tensor_shape((carried_inputs)) + shapes = xb.tensor_shape((total_inputs)) builder = xb.create_builder('test_while') params = [] for shape in shapes: From 1edc7bd448559b440036620c2004b7272eeda7e8 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 22:10:38 +0000 Subject: [PATCH 191/323] update --- torch_xla/csrc/init_python_bindings.cpp | 28 ++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index fa29bfdd4c8..145739e1d1a 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -925,26 +925,26 @@ class PyLoweringContext { // !!! --- next step: we add dump paras according to additional_inputs_list // ??? --- could we get IRvalue of `additional_inputs_list` in this function to complete xlacomputation? int64_t parameter_idx = 2; // parameter_idx start from 2 after upper and lower - // for (auto& additional_input_tensor : additional_inputs_list) { - // XLATensorPtr xtensor = bridge::GetXlaTensor(additional_input_tensor); - // xla::Shape shape = xtensor->shape().get(); - // xla::XlaOp x = xla::Parameter(local_builder, parameter_idx, shape, - // "UnusedArgumentsPlaceholder"); - // parameter_idx += 1; - // } + for (auto& additional_input_tensor : additional_inputs_list) { + XLATensorPtr xtensor = bridge::GetXlaTensor(additional_input_tensor); + xla::Shape shape = xtensor->shape().get(); + xla::XlaOp x = xla::Parameter(local_builder, parameter_idx, shape, + "UnusedArgumentsPlaceholder"); + parameter_idx += 1; + } } // hard-code modify body xlacomputation input arguments if (GetNameString() == "bodyctx") { xla::XlaBuilder* local_builder = lowering_ctx.builder(); int64_t parameter_idx = 7; // tensors.size(); - // for (auto& additional_input_tensor : additional_inputs_list) { - // XLATensorPtr xtensor = bridge::GetXlaTensor(additional_input_tensor); - // xla::Shape shape = xtensor->shape().get(); - // xla::XlaOp x = xla::Parameter(local_builder, parameter_idx, shape, - // "UnusedArgumentsPlaceholder"); - // parameter_idx += 1; - // } + for (auto& additional_input_tensor : additional_inputs_list) { + XLATensorPtr xtensor = bridge::GetXlaTensor(additional_input_tensor); + xla::Shape shape = xtensor->shape().get(); + xla::XlaOp x = xla::Parameter(local_builder, parameter_idx, shape, + "UnusedArgumentsPlaceholder"); + parameter_idx += 1; + } } // Get the backing XLA tensors from the output torch tensor handles From 4cfa52231c1fb933fa49802e08dfce1f704d1923 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 22:42:01 +0000 Subject: [PATCH 192/323] update --- torch_xla/experimental/fori_loop.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 27d6c214980..118358ff81b 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -44,7 +44,7 @@ def while_loop(cond_fn, body_fn, carried_inputs, additional_inputs): # TODO(@manfei): PyTorch require carried_inputs to be list/tuple, PyTorch/XLA _xla_while_loop only accept *operands, *operands would tuple items again: (a, '') # cond_fn&body_fn: callable # carried_inputs: (Tuple of possibly nested dict/list/tuple of tensors) - print("!!! arrive here too !!!") + print("!!! arrive here @while_loop_op.py_impl(DispatchKey.XLA) !!!") # print("while_loop additional_inputs: ", additional_inputs) if additional_inputs is None: additional_inputs = tuple() @@ -52,7 +52,7 @@ def while_loop(cond_fn, body_fn, carried_inputs, additional_inputs): def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): - print("!!! arrive here too too !!!") + print("!!! arrive here def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): !!!") # print("original_carried_inputs: ", original_carried_inputs) # print("additional_inputs: ", additional_inputs) # import pdb; pdb.set_trace() @@ -72,7 +72,7 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): torch.randint(10, carried_input.size(), dtype=carried_input.dtype).to(device)) # fake_carried_inputs = tuple(fake_carried_inputs) - print("fake_carried_inputs first: ", fake_carried_inputs) + # print("fake_carried_inputs first: ", fake_carried_inputs) for additional_input in additional_inputs: device = additional_input.device #TODO(@manfei) type = carried_input.type @@ -80,14 +80,14 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): torch.randint(10, additional_input.size(), dtype=additional_input.dtype).to(device)) # fake_carried_inputs = tuple(fake_carried_inputs) - print("fake_carried_inputs second: ", fake_carried_inputs) + # print("fake_carried_inputs second: ", fake_carried_inputs) print("!!! arrive here too before cond !!!") # generate cond_fn xlacomputation - print("print fake_carried_inputs: ", fake_carried_inputs) + # print("print fake_carried_inputs: ", fake_carried_inputs) # TODO(@manfei): specify which element is for which argument like a,b,c cond_result = cond_fn(*fake_carried_inputs) # [:-3], weight_0=fake_carried_inputs[-2], output_value=fake_carried_inputs[-3], bias_0=fake_carried_inputs[-1]) - print("nnn here ???") + # print("nnn here ???") cond_ctx = torch_xla._XLAC.lowering.LoweringContext() cond_ctx.set_name_string("condctx") additional_inputs_list_cond = list(fake_carried_inputs[2:]) # all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor @@ -135,6 +135,13 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): for shape in shapes: p = xb.mkparam(builder, len(params), shape) params.append(p) + tmp_bias = params[-2] + tmp_output_value = params[-3] + del params[-3] + del params[-2] + params.append(tmp_bias) + params.append(tmp_output_value) + print("args params: ", params) print("!!! arrive here too after args!!!") From edb6fc72624998ce5dafe747f6172dfbb7303a14 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 22:42:52 +0000 Subject: [PATCH 193/323] update --- torch_xla/experimental/fori_loop.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 118358ff81b..b44e79e090c 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -93,9 +93,9 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): additional_inputs_list_cond = list(fake_carried_inputs[2:]) # all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor # treat and pass additional_inputs to cond_fn print("additional_inputs_list_cond one: ", additional_inputs_list_cond) - for i in range(len(additional_inputs)): - additional_inputs_list_cond.append(additional_inputs[i]) - print("additional_inputs_list_cond two: ", additional_inputs_list_cond) + # for i in range(len(additional_inputs)): + # additional_inputs_list_cond.append(additional_inputs[i]) + # print("additional_inputs_list_cond two: ", additional_inputs_list_cond) cond_ctx.buildforiloop([cond_result], additional_inputs_list_cond) cond_hlo = cond_ctx.hlo() cond_computation = xb.computation_from_module_proto("condcomputation", @@ -111,8 +111,8 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): # TODO(@manfei): treat and pass additional_inputs to body_fn too # print("list(fake_carried_inputs[-2]: ", fake_carried_inputs[-2]) # print("len0!!!: ", len(additional_inputs_list_body)) - for i in range(len(additional_inputs)): - additional_inputs_list_body.append(additional_inputs[i]) + # for i in range(len(additional_inputs)): + # additional_inputs_list_body.append(additional_inputs[i]) # print("len!!!: ", len(additional_inputs_list_body)) # print("additional_inputs_list_body: ", additional_inputs_list_body) body_ctx.buildforiloop(list(body_result), additional_inputs_list_body) From 99a6589851b4acccd2bc0c279f3f4902e17e3173 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 22:50:09 +0000 Subject: [PATCH 194/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 ++-- torch_xla/experimental/fori_loop.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index eb108d59c46..2629b28a543 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -116,13 +116,13 @@ def cond_fn(upper, lower, one_value, x, input_value, output_value): def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) output_value_real = self.linear(input_value) - weight = self.linear.weight + weight = self.linear.weight # not be used actually, would be used as bias = self.linear.bias # new_upper = upper # new_one_value = one_value # new_input_value = input_value # return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value_real - return upper.clone(), lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), weight.clone(), bias.clone(), output_value_real + return upper.clone(), lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value_real, bias.clone(), weight.clone() # return while_loop(cond_fn, body_fn, (iter, x)) # return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) # return 1 diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index b44e79e090c..68e62d902ec 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -107,7 +107,7 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): body_result = body_fn(*fake_carried_inputs) # [:-3], weight_0=fake_carried_inputs[-1], output_value=fake_carried_inputs[-3], bias_0=fake_carried_inputs[-2]) body_ctx = torch_xla._XLAC.lowering.LoweringContext() body_ctx.set_name_string("bodyctx") - additional_inputs_list_body = [fake_carried_inputs[-2]] # missed arguments due to given output_value was not used and PyTorch/XLA trace xlacomputation from output tensor + additional_inputs_list_body = [fake_carried_inputs[-3]] # missed arguments due to given output_value was not used and PyTorch/XLA trace xlacomputation from output tensor # TODO(@manfei): treat and pass additional_inputs to body_fn too # print("list(fake_carried_inputs[-2]: ", fake_carried_inputs[-2]) # print("len0!!!: ", len(additional_inputs_list_body)) From a34cd6fe3390039a3e45ea10dbf737828df3d797 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 22:53:05 +0000 Subject: [PATCH 195/323] update --- torch_xla/experimental/fori_loop.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 68e62d902ec..25c3dc917a7 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -63,6 +63,11 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): # if len(original_carried_inputs) == 2: # print("use original_carried_inputs for additional_inputs") # additional_inputs = original_carried_inputs[1] + + # exchange order of bias and weight in additional_inputs + (bias_p, weight_p) = additional_inputs + additional_inputs = (weight_p, bias_p) + # fake carried_inputs to split formal code fake_carried_inputs = [] for carried_input in carried_inputs: From be562ad96416296b057317b0b69543a5324947ed Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 22:54:09 +0000 Subject: [PATCH 196/323] update --- torch_xla/experimental/fori_loop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 25c3dc917a7..337b05c75b3 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -85,7 +85,7 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): torch.randint(10, additional_input.size(), dtype=additional_input.dtype).to(device)) # fake_carried_inputs = tuple(fake_carried_inputs) - # print("fake_carried_inputs second: ", fake_carried_inputs) + print("fake_carried_inputs second: ", fake_carried_inputs) print("!!! arrive here too before cond !!!") # generate cond_fn xlacomputation From 11c1b546ea9490a7567093ece87c4344e9c880ca Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 22:56:14 +0000 Subject: [PATCH 197/323] update --- torch_xla/experimental/fori_loop.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 337b05c75b3..aa3730e7d7e 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -64,9 +64,9 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): # print("use original_carried_inputs for additional_inputs") # additional_inputs = original_carried_inputs[1] - # exchange order of bias and weight in additional_inputs - (bias_p, weight_p) = additional_inputs - additional_inputs = (weight_p, bias_p) + # # exchange order of bias and weight in additional_inputs + # (bias_p, weight_p) = additional_inputs + # additional_inputs = (weight_p, bias_p) # fake carried_inputs to split formal code fake_carried_inputs = [] From 2480b5b798dadacab4fc0d7da2e1ce329224879a Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 22:58:08 +0000 Subject: [PATCH 198/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 2629b28a543..c126636b59e 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -122,7 +122,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # new_one_value = one_value # new_input_value = input_value # return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value_real - return upper.clone(), lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value_real, bias.clone(), weight.clone() + return upper.clone(), lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value_real, weight.clone(), bias.clone() # return while_loop(cond_fn, body_fn, (iter, x)) # return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) # return 1 From cce486d4e9fdd967d2883d1a711e6693ef5be9d5 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:02:13 +0000 Subject: [PATCH 199/323] update --- torch_xla/experimental/fori_loop.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index aa3730e7d7e..0429b97cf3a 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -96,6 +96,14 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): cond_ctx = torch_xla._XLAC.lowering.LoweringContext() cond_ctx.set_name_string("condctx") additional_inputs_list_cond = list(fake_carried_inputs[2:]) # all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor + + tmp_bias = additional_inputs_list_cond[-2] + tmp_output_value = additional_inputs_list_cond[-3] + del additional_inputs_list_cond[-3] + del additional_inputs_list_cond[-2] + additional_inputs_list_cond.append(tmp_bias) + additional_inputs_list_cond.append(tmp_output_value) + # treat and pass additional_inputs to cond_fn print("additional_inputs_list_cond one: ", additional_inputs_list_cond) # for i in range(len(additional_inputs)): @@ -140,12 +148,12 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): for shape in shapes: p = xb.mkparam(builder, len(params), shape) params.append(p) - tmp_bias = params[-2] - tmp_output_value = params[-3] - del params[-3] - del params[-2] - params.append(tmp_bias) - params.append(tmp_output_value) + # tmp_bias = params[-2] + # tmp_output_value = params[-3] + # del params[-3] + # del params[-2] + # params.append(tmp_bias) + # params.append(tmp_output_value) print("args params: ", params) print("!!! arrive here too after args!!!") From 38d30b7aa47af946acbc3ef60412c51d40cf0c78 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:02:59 +0000 Subject: [PATCH 200/323] update --- torch_xla/experimental/fori_loop.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 0429b97cf3a..4d566b5e768 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -97,12 +97,12 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): cond_ctx.set_name_string("condctx") additional_inputs_list_cond = list(fake_carried_inputs[2:]) # all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor - tmp_bias = additional_inputs_list_cond[-2] - tmp_output_value = additional_inputs_list_cond[-3] - del additional_inputs_list_cond[-3] - del additional_inputs_list_cond[-2] - additional_inputs_list_cond.append(tmp_bias) - additional_inputs_list_cond.append(tmp_output_value) + tmp_bias = additional_inputs_list_cond[-2] # not used, change order doesn't affect logic + tmp_output_value = additional_inputs_list_cond[-3] # not used, change order doesn't affect logic + del additional_inputs_list_cond[-3] # not used, change order doesn't affect logic + del additional_inputs_list_cond[-2] # not used, change order doesn't affect logic + additional_inputs_list_cond.append(tmp_bias) # not used, change order doesn't affect logic + additional_inputs_list_cond.append(tmp_output_value) # not used, change order doesn't affect logic # treat and pass additional_inputs to cond_fn print("additional_inputs_list_cond one: ", additional_inputs_list_cond) From a85a8e30fb921b3cb577c935e7850332ace44757 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:04:54 +0000 Subject: [PATCH 201/323] update --- torch_xla/experimental/fori_loop.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 4d566b5e768..61d58043175 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -98,11 +98,11 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): additional_inputs_list_cond = list(fake_carried_inputs[2:]) # all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor tmp_bias = additional_inputs_list_cond[-2] # not used, change order doesn't affect logic - tmp_output_value = additional_inputs_list_cond[-3] # not used, change order doesn't affect logic - del additional_inputs_list_cond[-3] # not used, change order doesn't affect logic + # tmp_output_value = additional_inputs_list_cond[-3] # not used, change order doesn't affect logic + # del additional_inputs_list_cond[-3] # not used, change order doesn't affect logic del additional_inputs_list_cond[-2] # not used, change order doesn't affect logic additional_inputs_list_cond.append(tmp_bias) # not used, change order doesn't affect logic - additional_inputs_list_cond.append(tmp_output_value) # not used, change order doesn't affect logic + # additional_inputs_list_cond.append(tmp_output_value) # not used, change order doesn't affect logic # treat and pass additional_inputs to cond_fn print("additional_inputs_list_cond one: ", additional_inputs_list_cond) @@ -148,11 +148,12 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): for shape in shapes: p = xb.mkparam(builder, len(params), shape) params.append(p) - # tmp_bias = params[-2] + + tmp_bias = params[-2] # tmp_output_value = params[-3] # del params[-3] - # del params[-2] - # params.append(tmp_bias) + del params[-2] + params.append(tmp_bias) # params.append(tmp_output_value) print("args params: ", params) From 8b73e4322c9edc89557646ae40d1b4f4616d3653 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:06:20 +0000 Subject: [PATCH 202/323] update --- torch_xla/experimental/fori_loop.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 61d58043175..8def75a982d 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -169,6 +169,8 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): name = 'fori_loop_ed_torch_func' computation = w.build(name) + print("carried_inputs: ", carried_inputs) + # gain final result with generated while xlacomputation result = torch_xla._XLAC._xla_user_computation('xla::_op_test_while', (carried_inputs), From 839f5d1a1029290234dc2c31480b67a533132786 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:07:26 +0000 Subject: [PATCH 203/323] update --- torch_xla/experimental/fori_loop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 8def75a982d..828035591f4 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -173,7 +173,7 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): # gain final result with generated while xlacomputation result = torch_xla._XLAC._xla_user_computation('xla::_op_test_while', - (carried_inputs), + (total_inputs), # (carried_inputs), computation) print("!!! arrive here too after while!!!") From 4b96b9b6636ea415a5b791b7794dd8e210f8e227 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:10:21 +0000 Subject: [PATCH 204/323] update --- torch_xla/experimental/fori_loop.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 828035591f4..46ee2578cf0 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -44,7 +44,7 @@ def while_loop(cond_fn, body_fn, carried_inputs, additional_inputs): # TODO(@manfei): PyTorch require carried_inputs to be list/tuple, PyTorch/XLA _xla_while_loop only accept *operands, *operands would tuple items again: (a, '') # cond_fn&body_fn: callable # carried_inputs: (Tuple of possibly nested dict/list/tuple of tensors) - print("!!! arrive here @while_loop_op.py_impl(DispatchKey.XLA) !!!") + # print("!!! arrive here @while_loop_op.py_impl(DispatchKey.XLA) !!!") # print("while_loop additional_inputs: ", additional_inputs) if additional_inputs is None: additional_inputs = tuple() @@ -52,7 +52,7 @@ def while_loop(cond_fn, body_fn, carried_inputs, additional_inputs): def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): - print("!!! arrive here def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): !!!") + # print("!!! arrive here def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): !!!") # print("original_carried_inputs: ", original_carried_inputs) # print("additional_inputs: ", additional_inputs) # import pdb; pdb.set_trace() @@ -85,9 +85,9 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): torch.randint(10, additional_input.size(), dtype=additional_input.dtype).to(device)) # fake_carried_inputs = tuple(fake_carried_inputs) - print("fake_carried_inputs second: ", fake_carried_inputs) + # print("fake_carried_inputs second: ", fake_carried_inputs) - print("!!! arrive here too before cond !!!") + # print("!!! arrive here too before cond !!!") # generate cond_fn xlacomputation # print("print fake_carried_inputs: ", fake_carried_inputs) # TODO(@manfei): specify which element is for which argument like a,b,c @@ -105,7 +105,7 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): # additional_inputs_list_cond.append(tmp_output_value) # not used, change order doesn't affect logic # treat and pass additional_inputs to cond_fn - print("additional_inputs_list_cond one: ", additional_inputs_list_cond) + # print("additional_inputs_list_cond one: ", additional_inputs_list_cond) # for i in range(len(additional_inputs)): # additional_inputs_list_cond.append(additional_inputs[i]) # print("additional_inputs_list_cond two: ", additional_inputs_list_cond) @@ -113,9 +113,9 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): cond_hlo = cond_ctx.hlo() cond_computation = xb.computation_from_module_proto("condcomputation", cond_hlo) - print("!!! arrive here too after cond !!!") + # print("!!! arrive here too after cond !!!") - print("!!! arrive here too before body !!!") + # print("!!! arrive here too before body !!!") # generate body_fn xlacomputation body_result = body_fn(*fake_carried_inputs) # [:-3], weight_0=fake_carried_inputs[-1], output_value=fake_carried_inputs[-3], bias_0=fake_carried_inputs[-2]) body_ctx = torch_xla._XLAC.lowering.LoweringContext() @@ -132,11 +132,11 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): body_hlo = body_ctx.hlo() body_computation = xb.computation_from_module_proto("bodycomputation", body_hlo) - print("!!! arrive here too after body !!!") + # print("!!! arrive here too after body !!!") - print("!!! arrive here too before args!!!") + # print("!!! arrive here too before args!!!") total_inputs = carried_inputs + additional_inputs - print("total_inputs: ", total_inputs) + # print("total_inputs: ", total_inputs) # trans fake_carried_inputs from list(tensor) to list(xla::op), which part could change init of xla::while kwargs = {} if type(total_inputs) is tuple: @@ -156,10 +156,10 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): params.append(tmp_bias) # params.append(tmp_output_value) - print("args params: ", params) - print("!!! arrive here too after args!!!") + # print("args params: ", params) + # print("!!! arrive here too after args!!!") - print("!!! arrive here too before while!!!") + # print("!!! arrive here too before while!!!") # generate while xlacomputation input_tuple = xb.Op.tuple(tuple(params)) w = xb.mkop( @@ -169,7 +169,7 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): name = 'fori_loop_ed_torch_func' computation = w.build(name) - print("carried_inputs: ", carried_inputs) + # print("carried_inputs: ", carried_inputs) # gain final result with generated while xlacomputation result = torch_xla._XLAC._xla_user_computation('xla::_op_test_while', From d1e141a04509d88ff442bf4c50cc8f27c577b9ab Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:12:15 +0000 Subject: [PATCH 205/323] update --- torch_xla/experimental/fori_loop.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 46ee2578cf0..4bdf3d6c70b 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -170,11 +170,12 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): computation = w.build(name) # print("carried_inputs: ", carried_inputs) + print("total_inputs: ", total_inputs) # gain final result with generated while xlacomputation result = torch_xla._XLAC._xla_user_computation('xla::_op_test_while', - (total_inputs), # (carried_inputs), + (total_inputs), computation) - print("!!! arrive here too after while!!!") + # print("!!! arrive here too after while!!!") return result \ No newline at end of file From 5f73913d30833b0bb69799bff3842076c06b5248 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:12:30 +0000 Subject: [PATCH 206/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index c126636b59e..aeef18c9841 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -109,7 +109,7 @@ def forward(self, upper, lower, one_value, x, input_value, output_value): # def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): # def cond_fn(upper, lower, one_value, x, input_value, weight_1, bias_1, output_value): def cond_fn(upper, lower, one_value, x, input_value, output_value): - return lower[0] < upper[0] + return lower[0] >= upper[0] # def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): # def body_fn(upper, lower, one_value, x, input_value, weight_1, bias_1, output_value): From 3fc27584f6f6c0b9ba66f33f2d1063f3932d3468 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:16:12 +0000 Subject: [PATCH 207/323] update --- ...p_with_while_loop_simple_add_dispatch_in_torch.py | 12 ++++++++++-- torch_xla/experimental/fori_loop.py | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index aeef18c9841..c5c2765dbcd 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -154,8 +154,16 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, output_value) # bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, weight_0, bias_0, output_value) # , weight_0, bias_0) # bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, weight_0, bias_0, output_value) - bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, output_value) - print("bbb: ", bbb) + upper__, lower__, one_value__, torch_add_res__, input_value__, output_value_real__, weight__, bias__ = simple_with_linear(upper, lower, one_value, init_val, l_in_0, output_value) + # print("bbb: ", bbb) + print("upper__: ", upper__) + print("lower__: ", lower__) + print("one_value__: ", one_value__) + print("torch_add_res__: ", torch_add_res__) + print("input_value__: ", input_value__) + print("output_value_real__: ", output_value_real__) + print("weight__: ", weight__) + print("bias__: ", bias__) # print("start test 6 !!!") return aaa diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 4bdf3d6c70b..6ad00f67c7a 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -170,7 +170,7 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): computation = w.build(name) # print("carried_inputs: ", carried_inputs) - print("total_inputs: ", total_inputs) + # print("total_inputs: ", total_inputs) # gain final result with generated while xlacomputation result = torch_xla._XLAC._xla_user_computation('xla::_op_test_while', From 191b6664bdff72c9a27ba0197f0b2a7019c1b533 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:16:40 +0000 Subject: [PATCH 208/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index c5c2765dbcd..844175ac050 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -162,8 +162,8 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): print("torch_add_res__: ", torch_add_res__) print("input_value__: ", input_value__) print("output_value_real__: ", output_value_real__) - print("weight__: ", weight__) - print("bias__: ", bias__) + # print("weight__: ", weight__) + # print("bias__: ", bias__) # print("start test 6 !!!") return aaa From d6935186149db6ca216a77fdfd391c95844280a0 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:20:05 +0000 Subject: [PATCH 209/323] update --- torch_xla/experimental/fori_loop.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 6ad00f67c7a..fb7b37b21a8 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -113,6 +113,9 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): cond_hlo = cond_ctx.hlo() cond_computation = xb.computation_from_module_proto("condcomputation", cond_hlo) + cond_hlo_print = xb.get_computation_hlo(cond_computation) + print("cond computation: !!!!!!!!!") + print(cond_hlo_print) # print("!!! arrive here too after cond !!!") # print("!!! arrive here too before body !!!") @@ -132,6 +135,9 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): body_hlo = body_ctx.hlo() body_computation = xb.computation_from_module_proto("bodycomputation", body_hlo) + body_hlo_print = xb.get_computation_hlo(body_computation) + print("body computation: !!!!!!!!!") + print(body_hlo_print) # print("!!! arrive here too after body !!!") # print("!!! arrive here too before args!!!") @@ -168,6 +174,9 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): body_computation=body_computation) name = 'fori_loop_ed_torch_func' computation = w.build(name) + hlo_print = xb.get_computation_hlo(computation) + print("while computation: !!!!!!!!!") + print(hlo_print) # print("carried_inputs: ", carried_inputs) # print("total_inputs: ", total_inputs) From f8cc89ec788aaab74bc1b652e0f3359e083d9d76 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:29:37 +0000 Subject: [PATCH 210/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 844175ac050..e13449266ea 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -122,7 +122,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # new_one_value = one_value # new_input_value = input_value # return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value_real - return upper.clone(), lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value_real, weight.clone(), bias.clone() + return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value_real, weight.clone(), bias.clone() # return while_loop(cond_fn, body_fn, (iter, x)) # return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) # return 1 From 089a27f9b09bc34aefc1546c3db511ab4088b685 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:30:16 +0000 Subject: [PATCH 211/323] update --- torch_xla/experimental/fori_loop.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index fb7b37b21a8..14ceea7af04 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -113,9 +113,9 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): cond_hlo = cond_ctx.hlo() cond_computation = xb.computation_from_module_proto("condcomputation", cond_hlo) - cond_hlo_print = xb.get_computation_hlo(cond_computation) - print("cond computation: !!!!!!!!!") - print(cond_hlo_print) + # cond_hlo_print = xb.get_computation_hlo(cond_computation) + # print("cond computation: !!!!!!!!!") + # print(cond_hlo_print) # print("!!! arrive here too after cond !!!") # print("!!! arrive here too before body !!!") @@ -135,9 +135,9 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): body_hlo = body_ctx.hlo() body_computation = xb.computation_from_module_proto("bodycomputation", body_hlo) - body_hlo_print = xb.get_computation_hlo(body_computation) - print("body computation: !!!!!!!!!") - print(body_hlo_print) + # body_hlo_print = xb.get_computation_hlo(body_computation) + # print("body computation: !!!!!!!!!") + # print(body_hlo_print) # print("!!! arrive here too after body !!!") # print("!!! arrive here too before args!!!") @@ -174,9 +174,9 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): body_computation=body_computation) name = 'fori_loop_ed_torch_func' computation = w.build(name) - hlo_print = xb.get_computation_hlo(computation) - print("while computation: !!!!!!!!!") - print(hlo_print) + # hlo_print = xb.get_computation_hlo(computation) + # print("while computation: !!!!!!!!!") + # print(hlo_print) # print("carried_inputs: ", carried_inputs) # print("total_inputs: ", total_inputs) From 3a1fcf1a581708ea4e7345f73e08ee6b4bbb4de8 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:30:59 +0000 Subject: [PATCH 212/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index e13449266ea..4d85222ef01 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -109,7 +109,7 @@ def forward(self, upper, lower, one_value, x, input_value, output_value): # def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): # def cond_fn(upper, lower, one_value, x, input_value, weight_1, bias_1, output_value): def cond_fn(upper, lower, one_value, x, input_value, output_value): - return lower[0] >= upper[0] + return lower[0] <= upper[0] # def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): # def body_fn(upper, lower, one_value, x, input_value, weight_1, bias_1, output_value): From ea49168ee29839b2146c8d755c8187464070a30f Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:31:56 +0000 Subject: [PATCH 213/323] update --- ...est_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 4d85222ef01..cb33020965c 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -168,6 +168,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): return aaa expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) + print("expected: ", expected) self.assertTrue(torch.all(torch.eq(expected, l_out_))) # res = simple_with_linear.apply((upper, lower, one_value, init_val, l_in_0, output_value)) From ab065d5f8e84daf45ab7fcbe54e1889341472474 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:32:39 +0000 Subject: [PATCH 214/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index cb33020965c..c31b8bf0e78 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -165,12 +165,12 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # print("weight__: ", weight__) # print("bias__: ", bias__) # print("start test 6 !!!") - return aaa + # return aaa expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) print("expected: ", expected) - self.assertTrue(torch.all(torch.eq(expected, l_out_))) + return self.assertTrue(torch.all(torch.eq(expected, l_out_))) # res = simple_with_linear.apply((upper, lower, one_value, init_val, l_in_0, output_value)) # print("res: ", res) # import pdb; pdb.set_trace() From 060eaace1bf7950d71e4b162c318f23170a210fb Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:33:04 +0000 Subject: [PATCH 215/323] update --- ...t_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index c31b8bf0e78..9beffd3fe94 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -170,7 +170,8 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) print("expected: ", expected) - return self.assertTrue(torch.all(torch.eq(expected, l_out_))) + self.assertTrue(torch.all(torch.eq(expected, l_out_))) + return aaa # res = simple_with_linear.apply((upper, lower, one_value, init_val, l_in_0, output_value)) # print("res: ", res) # import pdb; pdb.set_trace() From b649e7e8fb93847409dd105927f02347c3adb319 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:35:20 +0000 Subject: [PATCH 216/323] update --- ...t_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 9beffd3fe94..b82d0f3b994 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -167,6 +167,9 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # print("start test 6 !!!") # return aaa + linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) + linear_0.weight_.data = weight__ + linear_0.bias_.data = bias__ expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) print("expected: ", expected) From 1d901a3dd66e1e0cbb2886f177178358682fb078 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:35:53 +0000 Subject: [PATCH 217/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index b82d0f3b994..144fc024549 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -168,8 +168,8 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # return aaa linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) - linear_0.weight_.data = weight__ - linear_0.bias_.data = bias__ + linear_0.weight.data = weight__ + linear_0.bias.data = bias__ expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) print("expected: ", expected) From b62ba4621d768bd565e0ca729fb431c042d21dc0 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:36:31 +0000 Subject: [PATCH 218/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 144fc024549..34906cc363d 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -173,7 +173,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) print("expected: ", expected) - self.assertTrue(torch.all(torch.eq(expected, l_out_))) + self.assertTrue(torch.all(torch.eq(expected, output_value_real__))) return aaa # res = simple_with_linear.apply((upper, lower, one_value, init_val, l_in_0, output_value)) # print("res: ", res) From b0f18f6285075e8e31199bf58da4b564f0b7af1a Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:37:49 +0000 Subject: [PATCH 219/323] update --- ...t_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 34906cc363d..401e17f2ca4 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -136,7 +136,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # return _xla_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) simple_with_linear = SimpleWithLinear() - upper = torch.tensor([52], dtype=torch.int32, device=device) + upper = torch.tensor([2], dtype=torch.int32, device=device) lower = torch.tensor([0], dtype=torch.int32, device=device) one_value = torch.tensor([1], dtype=torch.int32, device=device) init_val = torch.tensor([1], dtype=torch.int32, device=device) # x @@ -172,6 +172,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): linear_0.bias.data = bias__ expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) print("expected: ", expected) + print("l_in_0: ", l_in_0) self.assertTrue(torch.all(torch.eq(expected, output_value_real__))) return aaa From a37f72beff8271fe8f02ee799644b9ad8f32c475 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:38:49 +0000 Subject: [PATCH 220/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 401e17f2ca4..c79631e94a7 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -109,7 +109,7 @@ def forward(self, upper, lower, one_value, x, input_value, output_value): # def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): # def cond_fn(upper, lower, one_value, x, input_value, weight_1, bias_1, output_value): def cond_fn(upper, lower, one_value, x, input_value, output_value): - return lower[0] <= upper[0] + return lower[0] < upper[0] # def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): # def body_fn(upper, lower, one_value, x, input_value, weight_1, bias_1, output_value): From 36fa72effccd2a560909f8579c729a4104350062 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:41:41 +0000 Subject: [PATCH 221/323] update --- ...while_loop_simple_add_dispatch_in_torch.py | 46 ++----------------- 1 file changed, 5 insertions(+), 41 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index c79631e94a7..e569ebf62dc 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -98,83 +98,47 @@ class SimpleWithLinear(torch.nn.Module): def __init__(self): super().__init__() self.linear = torch.nn.Linear(10, 20).to(xm.xla_device()) - # self.register_buffer("dec", torch.tensor(1)) - # def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): def forward(self, upper, lower, one_value, x, input_value, output_value): - # def forward(self, upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): - # weight_1 = self.linear.weight - # bias_1 = self.linear.bias - - # def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): - # def cond_fn(upper, lower, one_value, x, input_value, weight_1, bias_1, output_value): def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] - # def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): - # def body_fn(upper, lower, one_value, x, input_value, weight_1, bias_1, output_value): def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) output_value_real = self.linear(input_value) - weight = self.linear.weight # not be used actually, would be used as - bias = self.linear.bias - # new_upper = upper - # new_one_value = one_value - # new_input_value = input_value - # return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value_real + weight = self.linear.weight # not be used actually, initialized as placeholder xlacomputation requirement + bias = self.linear.bias # not be used actually, initialized as placeholder xlacomputation requirement return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value_real, weight.clone(), bias.clone() - # return while_loop(cond_fn, body_fn, (iter, x)) - # return while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) - # return 1 - # return upper, lower, one_value, x, input_value, output_value - # return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, weight_0, bias_0, output_value)) - # return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, weight_1, bias_1, output_value)) - # weight_1 = self.linear.weight - # bias_1 = self.linear.bias - # return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, output_value), (bias_1, weight_1)) return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, output_value)) - # return _xla_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) simple_with_linear = SimpleWithLinear() upper = torch.tensor([2], dtype=torch.int32, device=device) lower = torch.tensor([0], dtype=torch.int32, device=device) one_value = torch.tensor([1], dtype=torch.int32, device=device) - init_val = torch.tensor([1], dtype=torch.int32, device=device) # x - # l_in_0 = torch.randn(10, device=xm.xla_device()) # input_value + init_val = torch.tensor([1], dtype=torch.int32, device=device) l_in_0 = torch.ones(10, device=xm.xla_device()) # input_value output_value = torch.zeros([20], dtype=torch.float32, device=device) - # linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) weight_0 = simple_with_linear.linear.weight bias_0 = simple_with_linear.linear.bias aaa = {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} - # upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = aaa - # print("aaa: ", aaa) - # bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, output_value) - # bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, weight_0, bias_0, output_value) # , weight_0, bias_0) - # bbb = simple_with_linear(upper, lower, one_value, init_val, l_in_0, weight_0, bias_0, output_value) upper__, lower__, one_value__, torch_add_res__, input_value__, output_value_real__, weight__, bias__ = simple_with_linear(upper, lower, one_value, init_val, l_in_0, output_value) - # print("bbb: ", bbb) print("upper__: ", upper__) print("lower__: ", lower__) print("one_value__: ", one_value__) print("torch_add_res__: ", torch_add_res__) print("input_value__: ", input_value__) print("output_value_real__: ", output_value_real__) - # print("weight__: ", weight__) - # print("bias__: ", bias__) - # print("start test 6 !!!") - # return aaa linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) linear_0.weight.data = weight__ linear_0.bias.data = bias__ expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) print("expected: ", expected) - print("l_in_0: ", l_in_0) + # print("l_in_0: ", l_in_0) - self.assertTrue(torch.all(torch.eq(expected, output_value_real__))) + self.assertTrue(torch.all(torch.eq(expected, l_in_0))) return aaa # res = simple_with_linear.apply((upper, lower, one_value, init_val, l_in_0, output_value)) # print("res: ", res) From 6312c498b26ff41f25ef5c4b0b3cf15e24742be5 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:42:31 +0000 Subject: [PATCH 222/323] update --- ...ri_loop_with_while_loop_simple_add_dispatch_in_torch.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index e569ebf62dc..9a88267c030 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -136,14 +136,9 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): linear_0.bias.data = bias__ expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) print("expected: ", expected) - # print("l_in_0: ", l_in_0) - self.assertTrue(torch.all(torch.eq(expected, l_in_0))) + self.assertTrue(torch.all(torch.eq(expected, output_value_real__))) return aaa - # res = simple_with_linear.apply((upper, lower, one_value, init_val, l_in_0, output_value)) - # print("res: ", res) - # import pdb; pdb.set_trace() - # return {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} def test_fori_loop_tpu_addition(self): From 4be4c237e526719cfe7f1d7d3076f20bb4a45273 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:48:22 +0000 Subject: [PATCH 223/323] update --- ...while_loop_simple_add_dispatch_in_torch.py | 43 -------- torch_xla/experimental/fori_loop.py | 99 +++---------------- 2 files changed, 16 insertions(+), 126 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 9a88267c030..a3e684f3069 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -7,7 +7,6 @@ # We need to import the underlying implementation function to register with the dispatcher import torch_xla.experimental.fori_loop from torch_xla.experimental.fori_loop import fori_loop -# from torch_xla.experimental.fori_loop import _xla_while_loop from torch._higher_order_ops.while_loop import while_loop import torch_xla.core.xla_model as xm import torch_xla.core.xla_builder as xb @@ -24,7 +23,6 @@ def _fake_fori_loop(lower, upper, body_fun, *init_val): if len(init_val) > 1: (a, b) = init_val for i in range((upper - lower)[0]): - # a = body_fun(a, b) a = body_fun(*init_val) else: for i in range((upper - lower)[0]): @@ -180,44 +178,3 @@ def test_fori_loop_tpu_simple_linear(self): if __name__ == '__main__': test = unittest.main() sys.exit(0 if test.result.wasSuccessful() else 1) - - -######## --------------------------------------------------------- - -# x = torch.zeros(1) -# y = torch.zeros(1) -# z = torch.zeros(1) -# return {"simple_with_linear": (simple_with_linear, (torch.tensor(3), torch.randn(2, 2)))} - - # xm.mark_step() - # device = xm.xla_device() - # torch.set_grad_enabled(False) - - # upper = torch.tensor([52], dtype=torch.int32, device=device) - # lower = torch.tensor([0], dtype=torch.int32, device=device) - # one_value = torch.tensor([1], dtype=torch.int32, device=device) - # init_val = torch.tensor([1], dtype=torch.int32, device=device) # x - # l_in_0 = torch.randn(10, device=xm.xla_device()) # input_value - # output_value = torch.zeros([20], dtype=torch.float32, device=device) - - # linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) - # weight_0 = linear_0.weight - # bias_0 = linear_0.bias - - # # def cond_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bias_0): - # def cond_fn(upper, lower, one_value, x, input_value, output_value): - # return lower[0] < upper[0] - - # def body_fn(upper, lower, one_value, x, input_value, output_value): - # new_lower = torch.add(one_value, lower) - # output_value = linear_0(input_value) - # weight = linear_0.weight - # bias = linear_0.bias - # return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value - - # # print("!!! arrive here !!!") - # upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) - - # expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) - - # self.assertTrue(torch.all(torch.eq(expected, l_out_))) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 14ceea7af04..baa2dcebed7 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -17,18 +17,14 @@ def fori_loop(upper, lower, body_fun, init_val, *input_value): device = xm.xla_device() - def cond_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bias_0): # , bias_0): # , output_value): + def cond_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bias_0): return lower[0] < upper[0] - def body_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bias_0): # , bias_0): - # weight = body_fun.weight - new_lower = torch.add(one_value, lower) ### !!! this matter, torch.add might would change the second argument's value, even we use a new variable to catch the result!!! - output_value = body_fun(*input_value) ### !!! due to the output_value is not actually used here, - # --- !!! its original value would not be used, and it would be replaces by the result of body_fun - # --- !!! so, due to PTXLA is traced from result tensor, so the arguments `output_value` would not be included in the body_xlacomputation - # --- !!! so, we need to modify ini_python_binding.cpp to add a fake arguments in the xlacompputation - weight = body_fun.weight - bias = body_fun.bias + def body_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bias_0): + new_lower = torch.add(one_value, lower) + output_value = body_fun(*input_value) + weight = body_fun.weight # not be used actually, initialized as placeholder xlacomputation requirement + bias = body_fun.bias # not be used actually, initialized as placeholder xlacomputation requirement return upper, new_lower, one_value, torch.add(one_value, x), *input_value, weight, bias, output_value output_value = torch.zeros([20], dtype=torch.float32, device=device) @@ -40,34 +36,16 @@ def body_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bi @while_loop_op.py_impl(DispatchKey.XLA) -def while_loop(cond_fn, body_fn, carried_inputs, additional_inputs): +def while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): # TODO(@manfei): PyTorch require carried_inputs to be list/tuple, PyTorch/XLA _xla_while_loop only accept *operands, *operands would tuple items again: (a, '') # cond_fn&body_fn: callable # carried_inputs: (Tuple of possibly nested dict/list/tuple of tensors) - # print("!!! arrive here @while_loop_op.py_impl(DispatchKey.XLA) !!!") - # print("while_loop additional_inputs: ", additional_inputs) if additional_inputs is None: additional_inputs = tuple() - return _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=additional_inputs) # a=a, b=b, c=c, - - -def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): - # print("!!! arrive here def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): !!!") - # print("original_carried_inputs: ", original_carried_inputs) - # print("additional_inputs: ", additional_inputs) - # import pdb; pdb.set_trace() - # untuple carried_inputs from while_loop - # carried_inputs = original_carried_inputs[0] ### due to PyTorch has already treat them , so skip split here - # TODO(@manfei): please clear pass additional_inputs in `while_loop`'s defination in this file - ### due to PyTorch has already treat them , so skip split here - # if len(original_carried_inputs) == 2: - # print("use original_carried_inputs for additional_inputs") - # additional_inputs = original_carried_inputs[1] - - # # exchange order of bias and weight in additional_inputs - # (bias_p, weight_p) = additional_inputs - # additional_inputs = (weight_p, bias_p) + return _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs) + +def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): # fake carried_inputs to split formal code fake_carried_inputs = [] for carried_input in carried_inputs: @@ -76,74 +54,41 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): fake_carried_inputs.append( torch.randint(10, carried_input.size(), dtype=carried_input.dtype).to(device)) - # fake_carried_inputs = tuple(fake_carried_inputs) - # print("fake_carried_inputs first: ", fake_carried_inputs) for additional_input in additional_inputs: device = additional_input.device #TODO(@manfei) type = carried_input.type fake_carried_inputs.append( torch.randint(10, additional_input.size(), dtype=additional_input.dtype).to(device)) - # fake_carried_inputs = tuple(fake_carried_inputs) - # print("fake_carried_inputs second: ", fake_carried_inputs) - # print("!!! arrive here too before cond !!!") - # generate cond_fn xlacomputation - # print("print fake_carried_inputs: ", fake_carried_inputs) # TODO(@manfei): specify which element is for which argument like a,b,c - cond_result = cond_fn(*fake_carried_inputs) # [:-3], weight_0=fake_carried_inputs[-2], output_value=fake_carried_inputs[-3], bias_0=fake_carried_inputs[-1]) - # print("nnn here ???") + cond_result = cond_fn(*fake_carried_inputs) cond_ctx = torch_xla._XLAC.lowering.LoweringContext() cond_ctx.set_name_string("condctx") additional_inputs_list_cond = list(fake_carried_inputs[2:]) # all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor tmp_bias = additional_inputs_list_cond[-2] # not used, change order doesn't affect logic - # tmp_output_value = additional_inputs_list_cond[-3] # not used, change order doesn't affect logic - # del additional_inputs_list_cond[-3] # not used, change order doesn't affect logic del additional_inputs_list_cond[-2] # not used, change order doesn't affect logic additional_inputs_list_cond.append(tmp_bias) # not used, change order doesn't affect logic - # additional_inputs_list_cond.append(tmp_output_value) # not used, change order doesn't affect logic - # treat and pass additional_inputs to cond_fn - # print("additional_inputs_list_cond one: ", additional_inputs_list_cond) - # for i in range(len(additional_inputs)): - # additional_inputs_list_cond.append(additional_inputs[i]) - # print("additional_inputs_list_cond two: ", additional_inputs_list_cond) cond_ctx.buildforiloop([cond_result], additional_inputs_list_cond) cond_hlo = cond_ctx.hlo() cond_computation = xb.computation_from_module_proto("condcomputation", cond_hlo) - # cond_hlo_print = xb.get_computation_hlo(cond_computation) - # print("cond computation: !!!!!!!!!") - # print(cond_hlo_print) - # print("!!! arrive here too after cond !!!") - # print("!!! arrive here too before body !!!") # generate body_fn xlacomputation - body_result = body_fn(*fake_carried_inputs) # [:-3], weight_0=fake_carried_inputs[-1], output_value=fake_carried_inputs[-3], bias_0=fake_carried_inputs[-2]) + body_result = body_fn(*fake_carried_inputs) body_ctx = torch_xla._XLAC.lowering.LoweringContext() body_ctx.set_name_string("bodyctx") - additional_inputs_list_body = [fake_carried_inputs[-3]] # missed arguments due to given output_value was not used and PyTorch/XLA trace xlacomputation from output tensor - # TODO(@manfei): treat and pass additional_inputs to body_fn too - # print("list(fake_carried_inputs[-2]: ", fake_carried_inputs[-2]) - # print("len0!!!: ", len(additional_inputs_list_body)) - # for i in range(len(additional_inputs)): - # additional_inputs_list_body.append(additional_inputs[i]) - # print("len!!!: ", len(additional_inputs_list_body)) - # print("additional_inputs_list_body: ", additional_inputs_list_body) + additional_inputs_list_body = [fake_carried_inputs[-3]] + # TODO(@manfei): treat hard-code parameters: additional_inputs_list_body body_ctx.buildforiloop(list(body_result), additional_inputs_list_body) body_hlo = body_ctx.hlo() body_computation = xb.computation_from_module_proto("bodycomputation", body_hlo) - # body_hlo_print = xb.get_computation_hlo(body_computation) - # print("body computation: !!!!!!!!!") - # print(body_hlo_print) - # print("!!! arrive here too after body !!!") - # print("!!! arrive here too before args!!!") - total_inputs = carried_inputs + additional_inputs - # print("total_inputs: ", total_inputs) # trans fake_carried_inputs from list(tensor) to list(xla::op), which part could change init of xla::while + total_inputs = carried_inputs + additional_inputs kwargs = {} if type(total_inputs) is tuple: shapes = xb.tensor_shape(total_inputs) @@ -155,17 +100,11 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): p = xb.mkparam(builder, len(params), shape) params.append(p) + # TODO(@manfei): treat hard-code input arguments tmp_bias = params[-2] - # tmp_output_value = params[-3] - # del params[-3] del params[-2] params.append(tmp_bias) - # params.append(tmp_output_value) - # print("args params: ", params) - # print("!!! arrive here too after args!!!") - - # print("!!! arrive here too before while!!!") # generate while xlacomputation input_tuple = xb.Op.tuple(tuple(params)) w = xb.mkop( @@ -174,12 +113,6 @@ def _xla_while_loop(cond_fn, body_fn, *carried_inputs, additional_inputs=()): body_computation=body_computation) name = 'fori_loop_ed_torch_func' computation = w.build(name) - # hlo_print = xb.get_computation_hlo(computation) - # print("while computation: !!!!!!!!!") - # print(hlo_print) - - # print("carried_inputs: ", carried_inputs) - # print("total_inputs: ", total_inputs) # gain final result with generated while xlacomputation result = torch_xla._XLAC._xla_user_computation('xla::_op_test_while', From e3a2fcd8a1daca469296706153c01f23112a8132 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:51:14 +0000 Subject: [PATCH 224/323] update --- ...ri_loop_with_while_loop_simple_add_dispatch_in_torch.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index a3e684f3069..111b4203b8b 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -122,13 +122,8 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): aaa = {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} upper__, lower__, one_value__, torch_add_res__, input_value__, output_value_real__, weight__, bias__ = simple_with_linear(upper, lower, one_value, init_val, l_in_0, output_value) - print("upper__: ", upper__) - print("lower__: ", lower__) - print("one_value__: ", one_value__) - print("torch_add_res__: ", torch_add_res__) - print("input_value__: ", input_value__) - print("output_value_real__: ", output_value_real__) + # same weight/bias liear model linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) linear_0.weight.data = weight__ linear_0.bias.data = bias__ From abb30456f68e4929070317be8c429572d7d471e3 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:52:15 +0000 Subject: [PATCH 225/323] update --- ...est_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 111b4203b8b..d06c8e8d56c 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -128,7 +128,6 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): linear_0.weight.data = weight__ linear_0.bias.data = bias__ expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) - print("expected: ", expected) self.assertTrue(torch.all(torch.eq(expected, output_value_real__))) return aaa From 95608ff09b4c54d31a19d52b3e4ba7c95930ca72 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:53:58 +0000 Subject: [PATCH 226/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index d06c8e8d56c..88243eee9b4 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -171,4 +171,4 @@ def test_fori_loop_tpu_simple_linear(self): if __name__ == '__main__': test = unittest.main() - sys.exit(0 if test.result.wasSuccessful() else 1) + sys.exit(0 if test.result.wasSuccessful() else 1) \ No newline at end of file From c8d722ee54bb6c74ba5170eecbd2adb14ec4b266 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Mon, 15 Apr 2024 23:59:20 +0000 Subject: [PATCH 227/323] update --- torch_xla/csrc/init_python_bindings.cpp | 2 ++ torch_xla/experimental/fori_loop.py | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index 145739e1d1a..c7013569dd1 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -917,6 +917,7 @@ class PyLoweringContext { if (GetNameString() == "condctx") { xla::XlaBuilder* local_builder = lowering_ctx.builder(); // hard-code parameter_idx to 2 to skip existing upper/lower arguments + // TODO(@manfei): get body xlacomputation arguments' number first then decide items in `additional_inputs_list`, maybe implement in python level // !!! since cond_fn only compare upper and lower, so it would only use two arguments, due to PyTorch/XLA // !!! trace xlacomputation from result tensor, so all the other arguments would not be included or generated; // !!! but to meet xla::while requirement, we would skip first two arguments, @@ -935,6 +936,7 @@ class PyLoweringContext { } // hard-code modify body xlacomputation input arguments + // TODO(@manfei): get body xlacomputation arguments' number first then decide items in `additional_inputs_list`, maybe implement in python level if (GetNameString() == "bodyctx") { xla::XlaBuilder* local_builder = lowering_ctx.builder(); int64_t parameter_idx = 7; // tensors.size(); diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index baa2dcebed7..a0f8024333d 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -75,6 +75,9 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): cond_hlo = cond_ctx.hlo() cond_computation = xb.computation_from_module_proto("condcomputation", cond_hlo) + cond_hlo_print = xb.get_computation_hlo(cond_computation) + print("cond computation: !!!!!!!!!") + print(cond_hlo_print) # generate body_fn xlacomputation body_result = body_fn(*fake_carried_inputs) @@ -86,6 +89,9 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): body_hlo = body_ctx.hlo() body_computation = xb.computation_from_module_proto("bodycomputation", body_hlo) + body_hlo_print = xb.get_computation_hlo(body_computation) + print("body computation: !!!!!!!!!") + print(body_hlo_print) # trans fake_carried_inputs from list(tensor) to list(xla::op), which part could change init of xla::while total_inputs = carried_inputs + additional_inputs @@ -113,6 +119,9 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): body_computation=body_computation) name = 'fori_loop_ed_torch_func' computation = w.build(name) + hlo_print = xb.get_computation_hlo(computation) + print("while computation: !!!!!!!!!") + print(hlo_print) # gain final result with generated while xlacomputation result = torch_xla._XLAC._xla_user_computation('xla::_op_test_while', From d33f14c82ffa25cdfff6ea22add19498a973f126 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 16 Apr 2024 17:06:12 +0000 Subject: [PATCH 228/323] update --- ...while_loop_simple_add_dispatch_in_torch.py | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 88243eee9b4..c7e5b9392e7 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -86,12 +86,52 @@ def body_fn(init, limit_value): expected = _fake_while_loop(cond_fn, body_fn, (init, limit_value)) self.assertEqual(expected, res) +# passed def test_while_loop_tpu_simple_linear(self): xm.mark_step() device = xm.xla_device() torch.set_grad_enabled(False) + # def forward(self, upper, lower, one_value, x, input_value, output_value): + linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) + + def cond_fn(upper, lower, one_value, x, input_value, output_value): + return lower[0] < upper[0] + + def body_fn(upper, lower, one_value, x, input_value, output_value): + new_lower = torch.add(one_value, lower) + output_value_real = linear_0(input_value) + weight = linear_0.weight # not be used actually, initialized as placeholder xlacomputation requirement + bias = linear_0.bias # not be used actually, initialized as placeholder xlacomputation requirement + return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value_real, weight.clone(), bias.clone() + + simple_with_linear = SimpleWithLinear() + upper = torch.tensor([2], dtype=torch.int32, device=device) + lower = torch.tensor([0], dtype=torch.int32, device=device) + one_value = torch.tensor([1], dtype=torch.int32, device=device) + init_val = torch.tensor([1], dtype=torch.int32, device=device) + l_in_0 = torch.ones(10, device=xm.xla_device()) # input_value + output_value = torch.zeros([20], dtype=torch.float32, device=device) + + # weight_0 = simple_with_linear.linear.weight + # bias_0 = simple_with_linear.linear.bias + + upper__, lower__, one_value__, torch_add_res__, input_value__, output_value_real__, weight__, bias__ = + while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, output_value)) + + expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) + + self.assertTrue(torch.all(torch.eq(expected, output_value_real__))) + return aaa + +# passed + def test_while_loop_tpu_simple_linear_class(self): + + xm.mark_step() + device = xm.xla_device() + torch.set_grad_enabled(False) + class SimpleWithLinear(torch.nn.Module): def __init__(self): super().__init__() From 1f8002a07893545be707b11f4cef5091f721ed59 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 16 Apr 2024 17:07:05 +0000 Subject: [PATCH 229/323] update --- ...t_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index c7e5b9392e7..e33cd21e476 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -117,8 +117,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # weight_0 = simple_with_linear.linear.weight # bias_0 = simple_with_linear.linear.bias - upper__, lower__, one_value__, torch_add_res__, input_value__, output_value_real__, weight__, bias__ = - while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, output_value)) + upper__, lower__, one_value__, torch_add_res__, input_value__, output_value_real__, weight__, bias__ = while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, output_value)) expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) From 5cffda24f659ed8cdd1b4abd3092b7a03ff82494 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 16 Apr 2024 17:07:41 +0000 Subject: [PATCH 230/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index e33cd21e476..304ce22b96e 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -106,7 +106,6 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): bias = linear_0.bias # not be used actually, initialized as placeholder xlacomputation requirement return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value_real, weight.clone(), bias.clone() - simple_with_linear = SimpleWithLinear() upper = torch.tensor([2], dtype=torch.int32, device=device) lower = torch.tensor([0], dtype=torch.int32, device=device) one_value = torch.tensor([1], dtype=torch.int32, device=device) @@ -114,9 +113,6 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): l_in_0 = torch.ones(10, device=xm.xla_device()) # input_value output_value = torch.zeros([20], dtype=torch.float32, device=device) - # weight_0 = simple_with_linear.linear.weight - # bias_0 = simple_with_linear.linear.bias - upper__, lower__, one_value__, torch_add_res__, input_value__, output_value_real__, weight__, bias__ = while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, output_value)) expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) From f9cd4dc55bdf180c85d68b20bff8a64cbb412a84 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 16 Apr 2024 17:08:49 +0000 Subject: [PATCH 231/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 304ce22b96e..db73f40a87c 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -113,7 +113,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): l_in_0 = torch.ones(10, device=xm.xla_device()) # input_value output_value = torch.zeros([20], dtype=torch.float32, device=device) - upper__, lower__, one_value__, torch_add_res__, input_value__, output_value_real__, weight__, bias__ = while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, output_value)) + upper__, lower__, one_value__, torch_add_res__, input_value__, output_value_real__, weight__, bias__ = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) From 1fc141409d24c83b5e7c80dcd64bb0484aeae7de Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 16 Apr 2024 17:09:17 +0000 Subject: [PATCH 232/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index db73f40a87c..436e5a68b55 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -113,7 +113,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): l_in_0 = torch.ones(10, device=xm.xla_device()) # input_value output_value = torch.zeros([20], dtype=torch.float32, device=device) - upper__, lower__, one_value__, torch_add_res__, input_value__, output_value_real__, weight__, bias__ = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) + upper__, lower__, one_value__, torch_add_res__, input_value__, output_value_real__, weight__, bias__ = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) From 90481612e5e838118ce7084834507b57f1d42250 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 16 Apr 2024 17:10:07 +0000 Subject: [PATCH 233/323] update --- ...t_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 436e5a68b55..411d2d9b41e 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -117,6 +117,9 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) + print("output_value_real__: ", output_value_real__) + print("expected: ", expected) + self.assertTrue(torch.all(torch.eq(expected, output_value_real__))) return aaa From 614a57fe461cd79be05a6d5e292aa19963d0b3b8 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 16 Apr 2024 17:10:46 +0000 Subject: [PATCH 234/323] update --- torch_xla/experimental/fori_loop.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index a0f8024333d..b8b0583e10e 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -75,9 +75,9 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): cond_hlo = cond_ctx.hlo() cond_computation = xb.computation_from_module_proto("condcomputation", cond_hlo) - cond_hlo_print = xb.get_computation_hlo(cond_computation) - print("cond computation: !!!!!!!!!") - print(cond_hlo_print) + # cond_hlo_print = xb.get_computation_hlo(cond_computation) + # print("cond computation: !!!!!!!!!") + # print(cond_hlo_print) # generate body_fn xlacomputation body_result = body_fn(*fake_carried_inputs) @@ -89,9 +89,9 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): body_hlo = body_ctx.hlo() body_computation = xb.computation_from_module_proto("bodycomputation", body_hlo) - body_hlo_print = xb.get_computation_hlo(body_computation) - print("body computation: !!!!!!!!!") - print(body_hlo_print) + # body_hlo_print = xb.get_computation_hlo(body_computation) + # print("body computation: !!!!!!!!!") + # print(body_hlo_print) # trans fake_carried_inputs from list(tensor) to list(xla::op), which part could change init of xla::while total_inputs = carried_inputs + additional_inputs @@ -119,9 +119,9 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): body_computation=body_computation) name = 'fori_loop_ed_torch_func' computation = w.build(name) - hlo_print = xb.get_computation_hlo(computation) - print("while computation: !!!!!!!!!") - print(hlo_print) + # hlo_print = xb.get_computation_hlo(computation) + # print("while computation: !!!!!!!!!") + # print(hlo_print) # gain final result with generated while xlacomputation result = torch_xla._XLAC._xla_user_computation('xla::_op_test_while', From eded2acc639cd03d600b2e60ac25d21b68c24ce3 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 16 Apr 2024 17:12:27 +0000 Subject: [PATCH 235/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 411d2d9b41e..738d592035a 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -148,7 +148,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, output_value)) simple_with_linear = SimpleWithLinear() - upper = torch.tensor([2], dtype=torch.int32, device=device) + upper = torch.tensor([52], dtype=torch.int32, device=device) lower = torch.tensor([0], dtype=torch.int32, device=device) one_value = torch.tensor([1], dtype=torch.int32, device=device) init_val = torch.tensor([1], dtype=torch.int32, device=device) From 504ea2ba74e2a599a936d161d371b6ddc1cd1da3 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 16 Apr 2024 17:13:21 +0000 Subject: [PATCH 236/323] update --- ...t_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 738d592035a..aef680f2edf 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -86,7 +86,6 @@ def body_fn(init, limit_value): expected = _fake_while_loop(cond_fn, body_fn, (init, limit_value)) self.assertEqual(expected, res) -# passed def test_while_loop_tpu_simple_linear(self): xm.mark_step() @@ -106,7 +105,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): bias = linear_0.bias # not be used actually, initialized as placeholder xlacomputation requirement return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value_real, weight.clone(), bias.clone() - upper = torch.tensor([2], dtype=torch.int32, device=device) + upper = torch.tensor([1], dtype=torch.int32, device=device) lower = torch.tensor([0], dtype=torch.int32, device=device) one_value = torch.tensor([1], dtype=torch.int32, device=device) init_val = torch.tensor([1], dtype=torch.int32, device=device) From b5889a85f4838fd504afb974e87b16b9e10e9b06 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 16 Apr 2024 17:14:47 +0000 Subject: [PATCH 237/323] update --- ...est_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index aef680f2edf..f75a87b8cbc 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -116,6 +116,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) + print("torch_add_res__: ", torch_add_res__) print("output_value_real__: ", output_value_real__) print("expected: ", expected) From a572c1b6662fd0d59c6aa3e2c7f2cab32a233231 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 16 Apr 2024 17:15:24 +0000 Subject: [PATCH 238/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index f75a87b8cbc..287797bab62 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -105,7 +105,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): bias = linear_0.bias # not be used actually, initialized as placeholder xlacomputation requirement return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value_real, weight.clone(), bias.clone() - upper = torch.tensor([1], dtype=torch.int32, device=device) + upper = torch.tensor([52], dtype=torch.int32, device=device) lower = torch.tensor([0], dtype=torch.int32, device=device) one_value = torch.tensor([1], dtype=torch.int32, device=device) init_val = torch.tensor([1], dtype=torch.int32, device=device) From aeda7f78f91f70dc235fd4a6dc824c8c1f687669 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 16 Apr 2024 17:16:07 +0000 Subject: [PATCH 239/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 287797bab62..ef01d7213d0 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -103,7 +103,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): output_value_real = linear_0(input_value) weight = linear_0.weight # not be used actually, initialized as placeholder xlacomputation requirement bias = linear_0.bias # not be used actually, initialized as placeholder xlacomputation requirement - return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value_real, weight.clone(), bias.clone() + return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), weight.clone(), bias.clone(), output_value_real upper = torch.tensor([52], dtype=torch.int32, device=device) lower = torch.tensor([0], dtype=torch.int32, device=device) From c6344a9aa60e763849323fd1910afd7bbd6e4fa0 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 16 Apr 2024 17:17:50 +0000 Subject: [PATCH 240/323] update --- ...ori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- torch_xla/experimental/fori_loop.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index ef01d7213d0..287797bab62 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -103,7 +103,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): output_value_real = linear_0(input_value) weight = linear_0.weight # not be used actually, initialized as placeholder xlacomputation requirement bias = linear_0.bias # not be used actually, initialized as placeholder xlacomputation requirement - return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), weight.clone(), bias.clone(), output_value_real + return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value_real, weight.clone(), bias.clone() upper = torch.tensor([52], dtype=torch.int32, device=device) lower = torch.tensor([0], dtype=torch.int32, device=device) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index b8b0583e10e..0160fca2d5a 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -119,9 +119,9 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): body_computation=body_computation) name = 'fori_loop_ed_torch_func' computation = w.build(name) - # hlo_print = xb.get_computation_hlo(computation) - # print("while computation: !!!!!!!!!") - # print(hlo_print) + hlo_print = xb.get_computation_hlo(computation) + print("while computation: !!!!!!!!!") + print(hlo_print) # gain final result with generated while xlacomputation result = torch_xla._XLAC._xla_user_computation('xla::_op_test_while', From 2e7f5fb0beed5539ab2aeab7ba26f439716cc327 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 16 Apr 2024 17:26:53 +0000 Subject: [PATCH 241/323] update --- ...i_loop_with_while_loop_simple_add_dispatch_in_torch.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 287797bab62..e60de52f2bb 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -94,16 +94,18 @@ def test_while_loop_tpu_simple_linear(self): # def forward(self, upper, lower, one_value, x, input_value, output_value): linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) + weight_0 = linear_0.weight_ + bias_0 = linear_0.bias_ - def cond_fn(upper, lower, one_value, x, input_value, output_value): + def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): return lower[0] < upper[0] - def body_fn(upper, lower, one_value, x, input_value, output_value): + def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): new_lower = torch.add(one_value, lower) output_value_real = linear_0(input_value) weight = linear_0.weight # not be used actually, initialized as placeholder xlacomputation requirement bias = linear_0.bias # not be used actually, initialized as placeholder xlacomputation requirement - return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value_real, weight.clone(), bias.clone() + return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), weight.clone(), output_value_real, bias.clone() upper = torch.tensor([52], dtype=torch.int32, device=device) lower = torch.tensor([0], dtype=torch.int32, device=device) From abc2c9c77b971e6a0cdbff3c7e8a5c3f4d1349cd Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 16 Apr 2024 17:27:27 +0000 Subject: [PATCH 242/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index e60de52f2bb..ec29fa9e0f7 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -94,8 +94,8 @@ def test_while_loop_tpu_simple_linear(self): # def forward(self, upper, lower, one_value, x, input_value, output_value): linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) - weight_0 = linear_0.weight_ - bias_0 = linear_0.bias_ + weight_0 = linear_0.weight + bias_0 = linear_0.bias def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): return lower[0] < upper[0] From c7d46545bf0a59795b675a55a0a695541f732d52 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 16 Apr 2024 18:14:45 +0000 Subject: [PATCH 243/323] update --- ...t_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index ec29fa9e0f7..01178fb6fa5 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -86,6 +86,7 @@ def body_fn(init, limit_value): expected = _fake_while_loop(cond_fn, body_fn, (init, limit_value)) self.assertEqual(expected, res) +# debugging def test_while_loop_tpu_simple_linear(self): xm.mark_step() @@ -105,7 +106,7 @@ def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_va output_value_real = linear_0(input_value) weight = linear_0.weight # not be used actually, initialized as placeholder xlacomputation requirement bias = linear_0.bias # not be used actually, initialized as placeholder xlacomputation requirement - return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), weight.clone(), output_value_real, bias.clone() + return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), weight.clone(), bias.clone(), output_value_real upper = torch.tensor([52], dtype=torch.int32, device=device) lower = torch.tensor([0], dtype=torch.int32, device=device) From 5dbbffb396f37cfd27aaa8557bdf592c194a7fb1 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 16 Apr 2024 18:18:37 +0000 Subject: [PATCH 244/323] update --- torch_xla/experimental/fori_loop.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 0160fca2d5a..d4fc5c96d09 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -40,12 +40,14 @@ def while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): # TODO(@manfei): PyTorch require carried_inputs to be list/tuple, PyTorch/XLA _xla_while_loop only accept *operands, *operands would tuple items again: (a, '') # cond_fn&body_fn: callable # carried_inputs: (Tuple of possibly nested dict/list/tuple of tensors) + print("arrive here @while_loop_op.py_impl(DispatchKey.XLA) !!!") if additional_inputs is None: additional_inputs = tuple() return _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs) def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): + print("arrive here _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): !!!") # fake carried_inputs to split formal code fake_carried_inputs = [] for carried_input in carried_inputs: From 5fca07d41090cd6424fa8aa3c0b1220c79c6ac26 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 16 Apr 2024 18:28:38 +0000 Subject: [PATCH 245/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 01178fb6fa5..ba045688258 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -115,7 +115,7 @@ def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_va l_in_0 = torch.ones(10, device=xm.xla_device()) # input_value output_value = torch.zeros([20], dtype=torch.float32, device=device) - upper__, lower__, one_value__, torch_add_res__, input_value__, output_value_real__, weight__, bias__ = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) + upper__, lower__, one_value__, torch_add_res__, input_value__, output_value_real__, weight__, bias__ = while_loop( cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, weight_0, bias_0, output_value)) expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) From 35ed14dd5da3cb5a8d5cf221840fb0cc0c54145e Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 16 Apr 2024 18:33:44 +0000 Subject: [PATCH 246/323] update --- torch_xla/experimental/fori_loop.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index d4fc5c96d09..418080ed90a 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -41,6 +41,8 @@ def while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): # cond_fn&body_fn: callable # carried_inputs: (Tuple of possibly nested dict/list/tuple of tensors) print("arrive here @while_loop_op.py_impl(DispatchKey.XLA) !!!") + print("carried_inputs: ", carried_inputs) + print("additional_inputs: ", additional_inputs) if additional_inputs is None: additional_inputs = tuple() return _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs) From b826cf9b0ec0f437e00cf340f374d82b9a76fd72 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 16 Apr 2024 18:38:07 +0000 Subject: [PATCH 247/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index ba045688258..d1028fea36b 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -115,7 +115,7 @@ def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_va l_in_0 = torch.ones(10, device=xm.xla_device()) # input_value output_value = torch.zeros([20], dtype=torch.float32, device=device) - upper__, lower__, one_value__, torch_add_res__, input_value__, output_value_real__, weight__, bias__ = while_loop( cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, weight_0, bias_0, output_value)) + upper__, lower__, one_value__, torch_add_res__, input_value__, output_value_real__, weight__, bias__ = while_loop( cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value, weight_0, bias_0)) expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) From df34a6bd967a0ecae8e94f6f7deaf5acbf9f74ce Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 16 Apr 2024 18:41:37 +0000 Subject: [PATCH 248/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index d1028fea36b..f16abca316b 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -115,7 +115,7 @@ def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_va l_in_0 = torch.ones(10, device=xm.xla_device()) # input_value output_value = torch.zeros([20], dtype=torch.float32, device=device) - upper__, lower__, one_value__, torch_add_res__, input_value__, output_value_real__, weight__, bias__ = while_loop( cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value, weight_0, bias_0)) + upper__, lower__, one_value__, torch_add_res__, input_value__, output_value_real__, weight__, bias__ = while_loop( cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) From fde54ac7038908d24042a3460d86be619b2b954e Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 16 Apr 2024 18:43:00 +0000 Subject: [PATCH 249/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index f16abca316b..0ac78cffbda 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -98,10 +98,10 @@ def test_while_loop_tpu_simple_linear(self): weight_0 = linear_0.weight bias_0 = linear_0.bias - def cond_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] - def body_fn(upper, lower, one_value, x, input_value, weight_0, bias_0, output_value): + def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) output_value_real = linear_0(input_value) weight = linear_0.weight # not be used actually, initialized as placeholder xlacomputation requirement From 1f2f50e21d00cfc06d1358814b483eaa37a7f90f Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 16 Apr 2024 19:28:54 +0000 Subject: [PATCH 250/323] update --- ...while_loop_simple_add_dispatch_in_torch.py | 2 +- torch_xla/experimental/fori_loop.py | 46 ++++++++++--------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 0ac78cffbda..511f8a8d853 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -106,7 +106,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): output_value_real = linear_0(input_value) weight = linear_0.weight # not be used actually, initialized as placeholder xlacomputation requirement bias = linear_0.bias # not be used actually, initialized as placeholder xlacomputation requirement - return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), weight.clone(), bias.clone(), output_value_real + return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value_real, weight.clone(), bias.clone() # , output_value_real upper = torch.tensor([52], dtype=torch.int32, device=device) lower = torch.tensor([0], dtype=torch.int32, device=device) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 418080ed90a..a69dd8d99df 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -12,7 +12,7 @@ from torch._higher_order_ops.while_loop import while_loop_op -# TODO(@manfei): delete one_value? +### TODO(@manfei): delete one_value? def fori_loop(upper, lower, body_fun, init_val, *input_value): device = xm.xla_device() @@ -23,8 +23,8 @@ def cond_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bi def body_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bias_0): new_lower = torch.add(one_value, lower) output_value = body_fun(*input_value) - weight = body_fun.weight # not be used actually, initialized as placeholder xlacomputation requirement - bias = body_fun.bias # not be used actually, initialized as placeholder xlacomputation requirement + weight = body_fun.weight ### not be used actually, initialized as placeholder xlacomputation requirement + bias = body_fun.bias ### not be used actually, initialized as placeholder xlacomputation requirement return upper, new_lower, one_value, torch.add(one_value, x), *input_value, weight, bias, output_value output_value = torch.zeros([20], dtype=torch.float32, device=device) @@ -37,9 +37,9 @@ def body_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bi @while_loop_op.py_impl(DispatchKey.XLA) def while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): - # TODO(@manfei): PyTorch require carried_inputs to be list/tuple, PyTorch/XLA _xla_while_loop only accept *operands, *operands would tuple items again: (a, '') - # cond_fn&body_fn: callable - # carried_inputs: (Tuple of possibly nested dict/list/tuple of tensors) + ### TODO(@manfei): PyTorch require carried_inputs to be list/tuple, PyTorch/XLA _xla_while_loop only accept *operands, *operands would tuple items again: (a, '') + ### cond_fn&body_fn: callable + ### carried_inputs: (Tuple of possibly nested dict/list/tuple of tensors) print("arrive here @while_loop_op.py_impl(DispatchKey.XLA) !!!") print("carried_inputs: ", carried_inputs) print("additional_inputs: ", additional_inputs) @@ -50,30 +50,30 @@ def while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): print("arrive here _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): !!!") - # fake carried_inputs to split formal code + ### fake carried_inputs to split formal code fake_carried_inputs = [] for carried_input in carried_inputs: device = carried_input.device - #TODO(@manfei) type = carried_input.type + ###TODO(@manfei) type = carried_input.type fake_carried_inputs.append( torch.randint(10, carried_input.size(), dtype=carried_input.dtype).to(device)) for additional_input in additional_inputs: device = additional_input.device - #TODO(@manfei) type = carried_input.type + ###TODO(@manfei) type = carried_input.type fake_carried_inputs.append( torch.randint(10, additional_input.size(), dtype=additional_input.dtype).to(device)) - # TODO(@manfei): specify which element is for which argument like a,b,c + ### TODO(@manfei): specify which element is for which argument like a,b,c cond_result = cond_fn(*fake_carried_inputs) cond_ctx = torch_xla._XLAC.lowering.LoweringContext() cond_ctx.set_name_string("condctx") - additional_inputs_list_cond = list(fake_carried_inputs[2:]) # all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor - - tmp_bias = additional_inputs_list_cond[-2] # not used, change order doesn't affect logic - del additional_inputs_list_cond[-2] # not used, change order doesn't affect logic - additional_inputs_list_cond.append(tmp_bias) # not used, change order doesn't affect logic + # !!! cond xlacomputation change !!! switch bias and weight position + additional_inputs_list_cond = list(fake_carried_inputs[2:]) ### all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor + tmp_bias = additional_inputs_list_cond[-2] ### not used, change order doesn't affect logic + del additional_inputs_list_cond[-2] ### not used, change order doesn't affect logic + additional_inputs_list_cond.append(tmp_bias) ### not used, change order doesn't affect logic cond_ctx.buildforiloop([cond_result], additional_inputs_list_cond) cond_hlo = cond_ctx.hlo() @@ -83,12 +83,13 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): # print("cond computation: !!!!!!!!!") # print(cond_hlo_print) - # generate body_fn xlacomputation + ### generate body_fn xlacomputation body_result = body_fn(*fake_carried_inputs) body_ctx = torch_xla._XLAC.lowering.LoweringContext() body_ctx.set_name_string("bodyctx") + # !!! body xlacomputation change !!! add output_value argument additional_inputs_list_body = [fake_carried_inputs[-3]] - # TODO(@manfei): treat hard-code parameters: additional_inputs_list_body + ### TODO(@manfei): treat hard-code parameters: additional_inputs_list_body body_ctx.buildforiloop(list(body_result), additional_inputs_list_body) body_hlo = body_ctx.hlo() body_computation = xb.computation_from_module_proto("bodycomputation", @@ -97,7 +98,7 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): # print("body computation: !!!!!!!!!") # print(body_hlo_print) - # trans fake_carried_inputs from list(tensor) to list(xla::op), which part could change init of xla::while + ### trans fake_carried_inputs from list(tensor) to list(xla::op), which part could change init of xla::while total_inputs = carried_inputs + additional_inputs kwargs = {} if type(total_inputs) is tuple: @@ -110,12 +111,13 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): p = xb.mkparam(builder, len(params), shape) params.append(p) - # TODO(@manfei): treat hard-code input arguments + ### TODO(@manfei): treat hard-code input arguments + # !!! init change !!! tmp_bias = params[-2] del params[-2] params.append(tmp_bias) - # generate while xlacomputation + ### generate while xlacomputation input_tuple = xb.Op.tuple(tuple(params)) w = xb.mkop( 'While', (input_tuple.op,), @@ -127,10 +129,10 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): print("while computation: !!!!!!!!!") print(hlo_print) - # gain final result with generated while xlacomputation + ### gain final result with generated while xlacomputation result = torch_xla._XLAC._xla_user_computation('xla::_op_test_while', (total_inputs), computation) - # print("!!! arrive here too after while!!!") + ### print("!!! arrive here too after while!!!") return result \ No newline at end of file From 27f20b7489f2592d51a0c13781a1c304de831c5b Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 16 Apr 2024 22:36:39 +0000 Subject: [PATCH 251/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 511f8a8d853..33b11e8eafe 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -106,7 +106,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): output_value_real = linear_0(input_value) weight = linear_0.weight # not be used actually, initialized as placeholder xlacomputation requirement bias = linear_0.bias # not be used actually, initialized as placeholder xlacomputation requirement - return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value_real, weight.clone(), bias.clone() # , output_value_real + return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value_real.clone(), weight.clone(), bias.clone() # , output_value_real upper = torch.tensor([52], dtype=torch.int32, device=device) lower = torch.tensor([0], dtype=torch.int32, device=device) From 43af2152df0ad7a0ac87bdf4f5b58f6c60431cbe Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Tue, 16 Apr 2024 22:38:17 +0000 Subject: [PATCH 252/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 33b11e8eafe..d5bedc787f6 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -155,7 +155,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): lower = torch.tensor([0], dtype=torch.int32, device=device) one_value = torch.tensor([1], dtype=torch.int32, device=device) init_val = torch.tensor([1], dtype=torch.int32, device=device) - l_in_0 = torch.ones(10, device=xm.xla_device()) # input_value + l_in_0 = torch.randint(10, device=xm.xla_device()) # input_value output_value = torch.zeros([20], dtype=torch.float32, device=device) weight_0 = simple_with_linear.linear.weight From 79bd30345593dde19a3cfbefc1bbe22be5907577 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 05:00:25 +0000 Subject: [PATCH 253/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index d5bedc787f6..1355697b32d 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -155,7 +155,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): lower = torch.tensor([0], dtype=torch.int32, device=device) one_value = torch.tensor([1], dtype=torch.int32, device=device) init_val = torch.tensor([1], dtype=torch.int32, device=device) - l_in_0 = torch.randint(10, device=xm.xla_device()) # input_value + l_in_0 = torch.randint(10, (10,), device=xm.xla_device()) # input_value output_value = torch.zeros([20], dtype=torch.float32, device=device) weight_0 = simple_with_linear.linear.weight From 08a155ede78326be59ba446c3592a9b9813e17f4 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 05:02:08 +0000 Subject: [PATCH 254/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 1355697b32d..c8119721b19 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -155,7 +155,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): lower = torch.tensor([0], dtype=torch.int32, device=device) one_value = torch.tensor([1], dtype=torch.int32, device=device) init_val = torch.tensor([1], dtype=torch.int32, device=device) - l_in_0 = torch.randint(10, (10,), device=xm.xla_device()) # input_value + l_in_0 = torch.rand(10, device=xm.xla_device()) # input_value output_value = torch.zeros([20], dtype=torch.float32, device=device) weight_0 = simple_with_linear.linear.weight From 2840aefe6af8a5035c45103e763094cbaeb3749f Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 17:09:58 +0000 Subject: [PATCH 255/323] update --- ...est_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index c8119721b19..0b578ded851 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -113,6 +113,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): one_value = torch.tensor([1], dtype=torch.int32, device=device) init_val = torch.tensor([1], dtype=torch.int32, device=device) l_in_0 = torch.ones(10, device=xm.xla_device()) # input_value + # l_in_0 = torch.rand(10, device=xm.xla_device()) # input_value output_value = torch.zeros([20], dtype=torch.float32, device=device) upper__, lower__, one_value__, torch_add_res__, input_value__, output_value_real__, weight__, bias__ = while_loop( cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) From f144d25c3306a0ba45b89a56066b96a93fae6f3f Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 17:17:43 +0000 Subject: [PATCH 256/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 0b578ded851..76ad459798e 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -112,8 +112,8 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): lower = torch.tensor([0], dtype=torch.int32, device=device) one_value = torch.tensor([1], dtype=torch.int32, device=device) init_val = torch.tensor([1], dtype=torch.int32, device=device) - l_in_0 = torch.ones(10, device=xm.xla_device()) # input_value - # l_in_0 = torch.rand(10, device=xm.xla_device()) # input_value + # l_in_0 = torch.ones(10, device=xm.xla_device()) # input_value + l_in_0 = torch.rand(10, device=xm.xla_device()) # input_value output_value = torch.zeros([20], dtype=torch.float32, device=device) upper__, lower__, one_value__, torch_add_res__, input_value__, output_value_real__, weight__, bias__ = while_loop( cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) From 03743edbdc91df0739f1ffaab6258686041ad190 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 17:30:53 +0000 Subject: [PATCH 257/323] update --- ...i_loop_with_while_loop_simple_add_dispatch_in_torch.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 76ad459798e..e00f2ffeaa1 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -95,8 +95,8 @@ def test_while_loop_tpu_simple_linear(self): # def forward(self, upper, lower, one_value, x, input_value, output_value): linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) - weight_0 = linear_0.weight - bias_0 = linear_0.bias + # weight_0 = linear_0.weight + # bias_0 = linear_0.bias def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] @@ -115,8 +115,10 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # l_in_0 = torch.ones(10, device=xm.xla_device()) # input_value l_in_0 = torch.rand(10, device=xm.xla_device()) # input_value output_value = torch.zeros([20], dtype=torch.float32, device=device) + # weight_0 = linear_0.weight + # bias_0 = linear_0.bias - upper__, lower__, one_value__, torch_add_res__, input_value__, output_value_real__, weight__, bias__ = while_loop( cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) + upper__, lower__, one_value__, torch_add_res__, input_value__, output_value_real__, weight__, bias__ = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) From 118e64023d783e47c9c66f467a44a312f575f6bf Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 18:00:07 +0000 Subject: [PATCH 258/323] update --- ...ori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index e00f2ffeaa1..bbcfdb60d83 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -103,10 +103,12 @@ def cond_fn(upper, lower, one_value, x, input_value, output_value): def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) - output_value_real = linear_0(input_value) + # output_value_real = linear_0(input_value) + output_value = linear_0(input_value) weight = linear_0.weight # not be used actually, initialized as placeholder xlacomputation requirement bias = linear_0.bias # not be used actually, initialized as placeholder xlacomputation requirement - return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value_real.clone(), weight.clone(), bias.clone() # , output_value_real + # return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value_real.clone(), weight.clone(), bias.clone() # , output_value_real + return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value.clone(), weight.clone(), bias.clone() # , output_value_real upper = torch.tensor([52], dtype=torch.int32, device=device) lower = torch.tensor([0], dtype=torch.int32, device=device) From 915ca5a6126e5323340cb55cc2e7e8aa2cf37f3a Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 18:01:17 +0000 Subject: [PATCH 259/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index bbcfdb60d83..1b771d20af1 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -108,7 +108,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): weight = linear_0.weight # not be used actually, initialized as placeholder xlacomputation requirement bias = linear_0.bias # not be used actually, initialized as placeholder xlacomputation requirement # return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value_real.clone(), weight.clone(), bias.clone() # , output_value_real - return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value.clone(), weight.clone(), bias.clone() # , output_value_real + return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), weight.clone(), bias.clone(), output_value.clone() # , output_value_real upper = torch.tensor([52], dtype=torch.int32, device=device) lower = torch.tensor([0], dtype=torch.int32, device=device) From 0bca16d922038a8e377612ea0102c1d341df86cf Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 18:02:36 +0000 Subject: [PATCH 260/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 1b771d20af1..4f52e21dc6a 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -108,7 +108,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): weight = linear_0.weight # not be used actually, initialized as placeholder xlacomputation requirement bias = linear_0.bias # not be used actually, initialized as placeholder xlacomputation requirement # return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value_real.clone(), weight.clone(), bias.clone() # , output_value_real - return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), weight.clone(), bias.clone(), output_value.clone() # , output_value_real + return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), bias.clone(), weight.clone(), output_value.clone() # , output_value_real upper = torch.tensor([52], dtype=torch.int32, device=device) lower = torch.tensor([0], dtype=torch.int32, device=device) From 0b04e2819ec1f0065eb833750bd5f7f709200ad3 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 18:03:19 +0000 Subject: [PATCH 261/323] update --- ...est_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 4f52e21dc6a..173afeba744 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -126,6 +126,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): print("torch_add_res__: ", torch_add_res__) print("output_value_real__: ", output_value_real__) + print("bias__: ", bias__) print("expected: ", expected) self.assertTrue(torch.all(torch.eq(expected, output_value_real__))) From 68e9aba51643232884dc216a898aa0a9086f928e Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 18:15:33 +0000 Subject: [PATCH 262/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 173afeba744..58bc78c806e 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -110,7 +110,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value_real.clone(), weight.clone(), bias.clone() # , output_value_real return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), bias.clone(), weight.clone(), output_value.clone() # , output_value_real - upper = torch.tensor([52], dtype=torch.int32, device=device) + upper = torch.tensor([1], dtype=torch.int32, device=device) lower = torch.tensor([0], dtype=torch.int32, device=device) one_value = torch.tensor([1], dtype=torch.int32, device=device) init_val = torch.tensor([1], dtype=torch.int32, device=device) From 94d004582913e9e520112782550bd9b01d2d6f9b Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 18:21:02 +0000 Subject: [PATCH 263/323] update --- ...t_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 58bc78c806e..b4344c90d31 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -96,7 +96,8 @@ def test_while_loop_tpu_simple_linear(self): # def forward(self, upper, lower, one_value, x, input_value, output_value): linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) # weight_0 = linear_0.weight - # bias_0 = linear_0.bias + bias_0 = linear_0.bias + print("original bias: ", bias_0) def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] From b9192beb819839246c55d636bf1f75861cc95235 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 18:21:55 +0000 Subject: [PATCH 264/323] update --- torch_xla/experimental/fori_loop.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index a69dd8d99df..b239d7eb56d 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -94,9 +94,9 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): body_hlo = body_ctx.hlo() body_computation = xb.computation_from_module_proto("bodycomputation", body_hlo) - # body_hlo_print = xb.get_computation_hlo(body_computation) - # print("body computation: !!!!!!!!!") - # print(body_hlo_print) + body_hlo_print = xb.get_computation_hlo(body_computation) + print("body computation: !!!!!!!!!") + print(body_hlo_print) ### trans fake_carried_inputs from list(tensor) to list(xla::op), which part could change init of xla::while total_inputs = carried_inputs + additional_inputs @@ -125,9 +125,9 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): body_computation=body_computation) name = 'fori_loop_ed_torch_func' computation = w.build(name) - hlo_print = xb.get_computation_hlo(computation) - print("while computation: !!!!!!!!!") - print(hlo_print) + # hlo_print = xb.get_computation_hlo(computation) + # print("while computation: !!!!!!!!!") + # print(hlo_print) ### gain final result with generated while xlacomputation result = torch_xla._XLAC._xla_user_computation('xla::_op_test_while', From 1b594e60120dfda7e71c59cf7aba77ca57e9f0e1 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 18:29:42 +0000 Subject: [PATCH 265/323] update --- torch_xla/experimental/fori_loop.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index b239d7eb56d..5694a1ba1f0 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -64,11 +64,13 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): fake_carried_inputs.append( torch.randint(10, additional_input.size(), dtype=additional_input.dtype).to(device)) + print("fake_carried_inputs: ", fake_carried_inputs) ### TODO(@manfei): specify which element is for which argument like a,b,c cond_result = cond_fn(*fake_carried_inputs) cond_ctx = torch_xla._XLAC.lowering.LoweringContext() cond_ctx.set_name_string("condctx") + # !!! cond xlacomputation change !!! switch bias and weight position additional_inputs_list_cond = list(fake_carried_inputs[2:]) ### all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor tmp_bias = additional_inputs_list_cond[-2] ### not used, change order doesn't affect logic @@ -87,6 +89,7 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): body_result = body_fn(*fake_carried_inputs) body_ctx = torch_xla._XLAC.lowering.LoweringContext() body_ctx.set_name_string("bodyctx") + # !!! body xlacomputation change !!! add output_value argument additional_inputs_list_body = [fake_carried_inputs[-3]] ### TODO(@manfei): treat hard-code parameters: additional_inputs_list_body From 867e488701ec4147331586cd948c16df4bb42a42 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 18:33:55 +0000 Subject: [PATCH 266/323] update --- torch_xla/experimental/fori_loop.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 5694a1ba1f0..e69323f1c8b 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -71,10 +71,16 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): cond_ctx = torch_xla._XLAC.lowering.LoweringContext() cond_ctx.set_name_string("condctx") - # !!! cond xlacomputation change !!! switch bias and weight position + # # !!! cond xlacomputation change !!! switch bias and weight position + # additional_inputs_list_cond = list(fake_carried_inputs[2:]) ### all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor + # tmp_bias = additional_inputs_list_cond[-2] ### not used, change order doesn't affect logic + # del additional_inputs_list_cond[-2] ### not used, change order doesn't affect logic + # additional_inputs_list_cond.append(tmp_bias) ### not used, change order doesn't affect logic + + # !!! cond xlacomputation change !!! switch output_value and weight position additional_inputs_list_cond = list(fake_carried_inputs[2:]) ### all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor - tmp_bias = additional_inputs_list_cond[-2] ### not used, change order doesn't affect logic - del additional_inputs_list_cond[-2] ### not used, change order doesn't affect logic + tmp_bias = additional_inputs_list_cond[-3] ### not used, change order doesn't affect logic + del additional_inputs_list_cond[-3] ### not used, change order doesn't affect logic additional_inputs_list_cond.append(tmp_bias) ### not used, change order doesn't affect logic cond_ctx.buildforiloop([cond_result], additional_inputs_list_cond) From 7a1bde9229c780fc6219710d0ac44057eeab2be9 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 18:35:20 +0000 Subject: [PATCH 267/323] update --- torch_xla/experimental/fori_loop.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index e69323f1c8b..c4923c76fe7 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -96,8 +96,9 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): body_ctx = torch_xla._XLAC.lowering.LoweringContext() body_ctx.set_name_string("bodyctx") - # !!! body xlacomputation change !!! add output_value argument + # !!! body xlacomputation change !!! add non-changed output_value argument additional_inputs_list_body = [fake_carried_inputs[-3]] + ### TODO(@manfei): treat hard-code parameters: additional_inputs_list_body body_ctx.buildforiloop(list(body_result), additional_inputs_list_body) body_hlo = body_ctx.hlo() @@ -120,10 +121,16 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): p = xb.mkparam(builder, len(params), shape) params.append(p) + # ### TODO(@manfei): treat hard-code input arguments + # # !!! init change !!! + # tmp_bias = params[-2] + # del params[-2] + # params.append(tmp_bias) + ### TODO(@manfei): treat hard-code input arguments - # !!! init change !!! - tmp_bias = params[-2] - del params[-2] + # !!! init change !!! switch bias and output_value + tmp_bias = params[-3] + del params[-3] params.append(tmp_bias) ### generate while xlacomputation From 120c33598e00838e943bd7a82253a86076c93881 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 18:36:36 +0000 Subject: [PATCH 268/323] update --- ...oop_with_while_loop_simple_add_dispatch_in_torch.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index b4344c90d31..2ddb6af2f17 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -121,14 +121,14 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # weight_0 = linear_0.weight # bias_0 = linear_0.bias - upper__, lower__, one_value__, torch_add_res__, input_value__, output_value_real__, weight__, bias__ = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) + upper__, lower__, one_value__, torch_add_res__, input_value__, bias__, weight__, output_value_real__, = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) - print("torch_add_res__: ", torch_add_res__) - print("output_value_real__: ", output_value_real__) - print("bias__: ", bias__) - print("expected: ", expected) + # print("torch_add_res__: ", torch_add_res__) + # print("output_value_real__: ", output_value_real__) + # print("bias__: ", bias__) + # print("expected: ", expected) self.assertTrue(torch.all(torch.eq(expected, output_value_real__))) return aaa From bc5950a04ad2af1113f657f228e824fef5653b77 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 18:37:40 +0000 Subject: [PATCH 269/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 2ddb6af2f17..90d23dc2686 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -131,7 +131,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # print("expected: ", expected) self.assertTrue(torch.all(torch.eq(expected, output_value_real__))) - return aaa + return True # passed def test_while_loop_tpu_simple_linear_class(self): From 91a3aa8a11230ce8ec8f3e4ad46871f2f898ea37 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 18:38:04 +0000 Subject: [PATCH 270/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 90d23dc2686..956acee8b1a 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -130,8 +130,8 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): # print("bias__: ", bias__) # print("expected: ", expected) - self.assertTrue(torch.all(torch.eq(expected, output_value_real__))) - return True + # self.assertTrue(torch.all(torch.eq(expected, output_value_real__))) + return self.assertTrue(torch.all(torch.eq(expected, output_value_real__))) # passed def test_while_loop_tpu_simple_linear_class(self): From 7041bc32203a74a298f1a11730aa45629647b5cf Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 18:38:54 +0000 Subject: [PATCH 271/323] update --- torch_xla/experimental/fori_loop.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index c4923c76fe7..3e88a5f4446 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -41,8 +41,8 @@ def while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): ### cond_fn&body_fn: callable ### carried_inputs: (Tuple of possibly nested dict/list/tuple of tensors) print("arrive here @while_loop_op.py_impl(DispatchKey.XLA) !!!") - print("carried_inputs: ", carried_inputs) - print("additional_inputs: ", additional_inputs) + # print("carried_inputs: ", carried_inputs) + # print("additional_inputs: ", additional_inputs) if additional_inputs is None: additional_inputs = tuple() return _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs) @@ -64,7 +64,7 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): fake_carried_inputs.append( torch.randint(10, additional_input.size(), dtype=additional_input.dtype).to(device)) - print("fake_carried_inputs: ", fake_carried_inputs) + # print("fake_carried_inputs: ", fake_carried_inputs) ### TODO(@manfei): specify which element is for which argument like a,b,c cond_result = cond_fn(*fake_carried_inputs) @@ -104,9 +104,9 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): body_hlo = body_ctx.hlo() body_computation = xb.computation_from_module_proto("bodycomputation", body_hlo) - body_hlo_print = xb.get_computation_hlo(body_computation) - print("body computation: !!!!!!!!!") - print(body_hlo_print) + # body_hlo_print = xb.get_computation_hlo(body_computation) + # print("body computation: !!!!!!!!!") + # print(body_hlo_print) ### trans fake_carried_inputs from list(tensor) to list(xla::op), which part could change init of xla::while total_inputs = carried_inputs + additional_inputs From 3ec8120e9e5f4261427d2da608ded09011edb6cc Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 19:40:59 +0000 Subject: [PATCH 272/323] update --- ..._loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- torch_xla/experimental/fori_loop.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 956acee8b1a..fc803d252a3 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -86,7 +86,7 @@ def body_fn(init, limit_value): expected = _fake_while_loop(cond_fn, body_fn, (init, limit_value)) self.assertEqual(expected, res) -# debugging +# passed def test_while_loop_tpu_simple_linear(self): xm.mark_step() diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 3e88a5f4446..5918fd40900 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -23,9 +23,12 @@ def cond_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bi def body_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bias_0): new_lower = torch.add(one_value, lower) output_value = body_fun(*input_value) - weight = body_fun.weight ### not be used actually, initialized as placeholder xlacomputation requirement - bias = body_fun.bias ### not be used actually, initialized as placeholder xlacomputation requirement - return upper, new_lower, one_value, torch.add(one_value, x), *input_value, weight, bias, output_value + if (hasattr(body_fun, 'weight') and hasattr(body_fun, 'bias')): + weight = body_fun.weight ### not be used actually, initialized as placeholder xlacomputation requirement + bias = body_fun.bias ### not be used actually, initialized as placeholder xlacomputation requirement + return upper, new_lower, one_value, torch.add(one_value, x), *input_value, weight, bias, output_value + else: + return upper, new_lower, one_value, torch.add(one_value, x), *input_value, output_value output_value = torch.zeros([20], dtype=torch.float32, device=device) weight_0 = body_fun.weight From 9beac796744f17d1cea55556e843f3d503cb2444 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 19:42:15 +0000 Subject: [PATCH 273/323] update --- torch_xla/experimental/fori_loop.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 5918fd40900..d6832d2e532 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -31,10 +31,13 @@ def body_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bi return upper, new_lower, one_value, torch.add(one_value, x), *input_value, output_value output_value = torch.zeros([20], dtype=torch.float32, device=device) - weight_0 = body_fun.weight - bias_0 = body_fun.bias one_value = torch.tensor([1], dtype=torch.int32, device=device) - res = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, *input_value, weight_0, bias_0, output_value)) + if (hasattr(body_fun, 'weight') and hasattr(body_fun, 'bias')): + weight_0 = body_fun.weight + bias_0 = body_fun.bias + res = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, *input_value, weight_0, bias_0, output_value)) + else: + res = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, *input_value, output_value)) return res From 70891937cfc91bc125f5f09d99ebb72195c0e001 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 19:44:22 +0000 Subject: [PATCH 274/323] update --- ...st_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 2 +- torch_xla/experimental/fori_loop.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index fc803d252a3..7ae046f696b 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -97,7 +97,7 @@ def test_while_loop_tpu_simple_linear(self): linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) # weight_0 = linear_0.weight bias_0 = linear_0.bias - print("original bias: ", bias_0) + # print("original bias: ", bias_0) def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index d6832d2e532..80e9b290848 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -70,7 +70,7 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): fake_carried_inputs.append( torch.randint(10, additional_input.size(), dtype=additional_input.dtype).to(device)) - # print("fake_carried_inputs: ", fake_carried_inputs) + print("fake_carried_inputs: ", fake_carried_inputs) ### TODO(@manfei): specify which element is for which argument like a,b,c cond_result = cond_fn(*fake_carried_inputs) From 9d9bc32a84bffc10b884a0d30f744ce8b385fc87 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 19:50:11 +0000 Subject: [PATCH 275/323] update --- torch_xla/experimental/fori_loop.py | 30 +++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 80e9b290848..47b998857ff 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -16,28 +16,38 @@ def fori_loop(upper, lower, body_fun, init_val, *input_value): device = xm.xla_device() + + output_value = torch.zeros([20], dtype=torch.float32, device=device) + one_value = torch.tensor([1], dtype=torch.int32, device=device) def cond_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bias_0): return lower[0] < upper[0] - def body_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bias_0): - new_lower = torch.add(one_value, lower) - output_value = body_fun(*input_value) - if (hasattr(body_fun, 'weight') and hasattr(body_fun, 'bias')): + if (hasattr(body_fun, 'weight') or hasattr(body_fun, 'bias')): + def body_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bias_0): + new_lower = torch.add(one_value, lower) + output_value = body_fun(*input_value) weight = body_fun.weight ### not be used actually, initialized as placeholder xlacomputation requirement bias = body_fun.bias ### not be used actually, initialized as placeholder xlacomputation requirement return upper, new_lower, one_value, torch.add(one_value, x), *input_value, weight, bias, output_value - else: - return upper, new_lower, one_value, torch.add(one_value, x), *input_value, output_value - - output_value = torch.zeros([20], dtype=torch.float32, device=device) - one_value = torch.tensor([1], dtype=torch.int32, device=device) - if (hasattr(body_fun, 'weight') and hasattr(body_fun, 'bias')): weight_0 = body_fun.weight bias_0 = body_fun.bias res = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, *input_value, weight_0, bias_0, output_value)) else: + def body_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bias_0): + new_lower = torch.add(one_value, lower) + output_value = body_fun(*input_value) + return upper, new_lower, one_value, torch.add(one_value, x), *input_value, output_value res = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, *input_value, output_value)) + + # output_value = torch.zeros([20], dtype=torch.float32, device=device) + # one_value = torch.tensor([1], dtype=torch.int32, device=device) + # if (hasattr(body_fun, 'weight') or hasattr(body_fun, 'bias')): + # weight_0 = body_fun.weight + # bias_0 = body_fun.bias + # res = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, *input_value, weight_0, bias_0, output_value)) + # else: + # res = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, *input_value, output_value)) return res From 0d218c8e208247ff339b7011df4209234f3168c3 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 19:58:39 +0000 Subject: [PATCH 276/323] update --- torch_xla/experimental/fori_loop.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 47b998857ff..bdc03d21981 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -24,6 +24,8 @@ def cond_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bi return lower[0] < upper[0] if (hasattr(body_fun, 'weight') or hasattr(body_fun, 'bias')): + print("body_fun.weight: ", body_fun.weight) + print("body_fun.bias: ", body_fun.bias) def body_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bias_0): new_lower = torch.add(one_value, lower) output_value = body_fun(*input_value) From bae4952783bfe1ac464297bd05c892041229be55 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 20:02:30 +0000 Subject: [PATCH 277/323] update --- torch_xla/experimental/fori_loop.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index bdc03d21981..b09632dee2a 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -12,21 +12,34 @@ from torch._higher_order_ops.while_loop import while_loop_op +# /////////////// +# def cond_fn(upper, lower, one_value, x, input_value, output_value): +# return lower[0] < upper[0] + +# def body_fn(upper, lower, one_value, x, input_value, output_value): +# new_lower = torch.add(one_value, lower) +# output_value = linear_0(input_value) +# weight = linear_0.weight +# bias = linear_0.bias +# return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), bias.clone(), weight.clone(), output_value.clone() +# /////////////// + + ### TODO(@manfei): delete one_value? def fori_loop(upper, lower, body_fun, init_val, *input_value): device = xm.xla_device() - + output_value = torch.zeros([20], dtype=torch.float32, device=device) one_value = torch.tensor([1], dtype=torch.int32, device=device) - def cond_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bias_0): + def cond_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bias_0): return lower[0] < upper[0] if (hasattr(body_fun, 'weight') or hasattr(body_fun, 'bias')): print("body_fun.weight: ", body_fun.weight) print("body_fun.bias: ", body_fun.bias) - def body_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bias_0): + def body_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bias_0): new_lower = torch.add(one_value, lower) output_value = body_fun(*input_value) weight = body_fun.weight ### not be used actually, initialized as placeholder xlacomputation requirement From 7bb4791dd8c2a2bb755f894fada8c9c6cb22704c Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 20:07:04 +0000 Subject: [PATCH 278/323] update --- torch_xla/experimental/fori_loop.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index b09632dee2a..73b9362f607 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -37,8 +37,8 @@ def cond_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bia return lower[0] < upper[0] if (hasattr(body_fun, 'weight') or hasattr(body_fun, 'bias')): - print("body_fun.weight: ", body_fun.weight) - print("body_fun.bias: ", body_fun.bias) + # print("body_fun.weight: ", body_fun.weight) + # print("body_fun.bias: ", body_fun.bias) def body_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bias_0): new_lower = torch.add(one_value, lower) output_value = body_fun(*input_value) From 114531545a22c2045010b58fc10e5a3faf71e172 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 20:11:19 +0000 Subject: [PATCH 279/323] update --- torch_xla/experimental/fori_loop.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 73b9362f607..af36c8d11c7 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -22,10 +22,22 @@ # weight = linear_0.weight # bias = linear_0.bias # return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), bias.clone(), weight.clone(), output_value.clone() + # upper = torch.tensor([1], dtype=torch.int32, device=device) + # lower = torch.tensor([0], dtype=torch.int32, device=device) + # one_value = torch.tensor([1], dtype=torch.int32, device=device) + # init_val = torch.tensor([1], dtype=torch.int32, device=device) + # # l_in_0 = torch.ones(10, device=xm.xla_device()) # input_value + # l_in_0 = torch.rand(10, device=xm.xla_device()) # input_value + # output_value = torch.zeros([20], dtype=torch.float32, device=device) + # # weight_0 = linear_0.weight + # # bias_0 = linear_0.bias + + # upper__, lower__, one_value__, torch_add_res__, input_value__, bias__, weight__, output_value_real__, = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) + # /////////////// -### TODO(@manfei): delete one_value? +### TODO(@manfei): treat *input_value def fori_loop(upper, lower, body_fun, init_val, *input_value): device = xm.xla_device() @@ -41,13 +53,13 @@ def cond_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bia # print("body_fun.bias: ", body_fun.bias) def body_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bias_0): new_lower = torch.add(one_value, lower) - output_value = body_fun(*input_value) + output_value = body_fun(input_value) weight = body_fun.weight ### not be used actually, initialized as placeholder xlacomputation requirement bias = body_fun.bias ### not be used actually, initialized as placeholder xlacomputation requirement - return upper, new_lower, one_value, torch.add(one_value, x), *input_value, weight, bias, output_value + return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value weight_0 = body_fun.weight bias_0 = body_fun.bias - res = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, *input_value, weight_0, bias_0, output_value)) + res = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) else: def body_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bias_0): new_lower = torch.add(one_value, lower) From bad4c1fe3338a9dbaac1dd94093dd6785d4e6258 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 20:13:18 +0000 Subject: [PATCH 280/323] update --- torch_xla/experimental/fori_loop.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index af36c8d11c7..2f603b427ae 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -84,8 +84,8 @@ def while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): ### cond_fn&body_fn: callable ### carried_inputs: (Tuple of possibly nested dict/list/tuple of tensors) print("arrive here @while_loop_op.py_impl(DispatchKey.XLA) !!!") - # print("carried_inputs: ", carried_inputs) - # print("additional_inputs: ", additional_inputs) + print("carried_inputs: ", carried_inputs) + print("additional_inputs: ", additional_inputs) if additional_inputs is None: additional_inputs = tuple() return _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs) From 00cd07c103cdd536f4f0032b302889d03c47a190 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 20:18:23 +0000 Subject: [PATCH 281/323] update --- torch_xla/experimental/fori_loop.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 2f603b427ae..b141717a157 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -45,12 +45,11 @@ def fori_loop(upper, lower, body_fun, init_val, *input_value): output_value = torch.zeros([20], dtype=torch.float32, device=device) one_value = torch.tensor([1], dtype=torch.int32, device=device) - def cond_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bias_0): - return lower[0] < upper[0] - if (hasattr(body_fun, 'weight') or hasattr(body_fun, 'bias')): # print("body_fun.weight: ", body_fun.weight) # print("body_fun.bias: ", body_fun.bias) + def cond_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bias_0): + return lower[0] < upper[0] def body_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bias_0): new_lower = torch.add(one_value, lower) output_value = body_fun(input_value) @@ -61,10 +60,12 @@ def body_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bia bias_0 = body_fun.bias res = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) else: - def body_fn(upper, lower, one_value, x, *input_value, weight_0, output_value, bias_0): + def cond_fn(upper, lower, one_value, x, input_value, output_value): + return lower[0] < upper[0] + def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) - output_value = body_fun(*input_value) - return upper, new_lower, one_value, torch.add(one_value, x), *input_value, output_value + output_value = body_fun(input_value) + return upper, new_lower, one_value, torch.add(one_value, x), input_value, output_value res = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, *input_value, output_value)) # output_value = torch.zeros([20], dtype=torch.float32, device=device) From 629f42e444cdaa39926701c9d0048e52daa061d9 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 20:20:32 +0000 Subject: [PATCH 282/323] update --- torch_xla/experimental/fori_loop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index b141717a157..fe125f4e54e 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -38,7 +38,7 @@ ### TODO(@manfei): treat *input_value -def fori_loop(upper, lower, body_fun, init_val, *input_value): +def fori_loop(upper, lower, body_fun, init_val, input_value): device = xm.xla_device() From d7bab3854838427ed407b8e87ecfb772952c83ef Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 20:25:18 +0000 Subject: [PATCH 283/323] update --- torch_xla/experimental/fori_loop.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index fe125f4e54e..0436cb449a0 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -48,9 +48,9 @@ def fori_loop(upper, lower, body_fun, init_val, input_value): if (hasattr(body_fun, 'weight') or hasattr(body_fun, 'bias')): # print("body_fun.weight: ", body_fun.weight) # print("body_fun.bias: ", body_fun.bias) - def cond_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bias_0): + def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] - def body_fn(upper, lower, one_value, x, input_value, weight_0, output_value, bias_0): + def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) output_value = body_fun(input_value) weight = body_fun.weight ### not be used actually, initialized as placeholder xlacomputation requirement From 2e485a50cc49e40e5b4cd8b57b65a26122add77b Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 20:34:43 +0000 Subject: [PATCH 284/323] update --- torch_xla/experimental/fori_loop.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 0436cb449a0..ef5f2156043 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -56,8 +56,8 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): weight = body_fun.weight ### not be used actually, initialized as placeholder xlacomputation requirement bias = body_fun.bias ### not be used actually, initialized as placeholder xlacomputation requirement return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value - weight_0 = body_fun.weight - bias_0 = body_fun.bias + # weight_0 = body_fun.weight + # bias_0 = body_fun.bias res = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) else: def cond_fn(upper, lower, one_value, x, input_value, output_value): From 5ec118425c2300dfb9601e93aaba9301344d669c Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 20:38:38 +0000 Subject: [PATCH 285/323] update --- torch_xla/experimental/fori_loop.py | 43 ++++++++++++----------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index ef5f2156043..0073d9d1ccd 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -12,31 +12,6 @@ from torch._higher_order_ops.while_loop import while_loop_op -# /////////////// -# def cond_fn(upper, lower, one_value, x, input_value, output_value): -# return lower[0] < upper[0] - -# def body_fn(upper, lower, one_value, x, input_value, output_value): -# new_lower = torch.add(one_value, lower) -# output_value = linear_0(input_value) -# weight = linear_0.weight -# bias = linear_0.bias -# return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), bias.clone(), weight.clone(), output_value.clone() - # upper = torch.tensor([1], dtype=torch.int32, device=device) - # lower = torch.tensor([0], dtype=torch.int32, device=device) - # one_value = torch.tensor([1], dtype=torch.int32, device=device) - # init_val = torch.tensor([1], dtype=torch.int32, device=device) - # # l_in_0 = torch.ones(10, device=xm.xla_device()) # input_value - # l_in_0 = torch.rand(10, device=xm.xla_device()) # input_value - # output_value = torch.zeros([20], dtype=torch.float32, device=device) - # # weight_0 = linear_0.weight - # # bias_0 = linear_0.bias - - # upper__, lower__, one_value__, torch_add_res__, input_value__, bias__, weight__, output_value_real__, = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) - -# /////////////// - - ### TODO(@manfei): treat *input_value def fori_loop(upper, lower, body_fun, init_val, input_value): @@ -45,6 +20,21 @@ def fori_loop(upper, lower, body_fun, init_val, input_value): output_value = torch.zeros([20], dtype=torch.float32, device=device) one_value = torch.tensor([1], dtype=torch.int32, device=device) +# ///////// +# def cond_fn(upper, lower, one_value, x, input_value, output_value): +# return lower[0] < upper[0] + +# def body_fn(upper, lower, one_value, x, input_value, output_value): +# new_lower = torch.add(one_value, lower) +# # output_value_real = linear_0(input_value) +# output_value = linear_0(input_value) +# weight = linear_0.weight # not be used actually, initialized as placeholder xlacomputation requirement +# bias = linear_0.bias # not be used actually, initialized as placeholder xlacomputation requirement +# # return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value_real.clone(), weight.clone(), bias.clone() # , output_value_real +# return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), bias.clone(), weight.clone(), output_value.clone() # , output_value_real + +# ///////// + if (hasattr(body_fun, 'weight') or hasattr(body_fun, 'bias')): # print("body_fun.weight: ", body_fun.weight) # print("body_fun.bias: ", body_fun.bias) @@ -55,7 +45,8 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): output_value = body_fun(input_value) weight = body_fun.weight ### not be used actually, initialized as placeholder xlacomputation requirement bias = body_fun.bias ### not be used actually, initialized as placeholder xlacomputation requirement - return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value + # return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value + return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), bias.clone(), weight.clone(), output_value.clone() # # weight_0 = body_fun.weight # bias_0 = body_fun.bias res = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) From db3c8bfc11730a3df3ed0bf65f39f96da478b8bb Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 20:40:07 +0000 Subject: [PATCH 286/323] update --- ...ith_while_loop_simple_add_dispatch_in_torch.py | 2 +- torch_xla/experimental/fori_loop.py | 15 --------------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 7ae046f696b..1cdc0e054af 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -96,7 +96,7 @@ def test_while_loop_tpu_simple_linear(self): # def forward(self, upper, lower, one_value, x, input_value, output_value): linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) # weight_0 = linear_0.weight - bias_0 = linear_0.bias + # bias_0 = linear_0.bias # print("original bias: ", bias_0) def cond_fn(upper, lower, one_value, x, input_value, output_value): diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 0073d9d1ccd..15b12464d2c 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -20,21 +20,6 @@ def fori_loop(upper, lower, body_fun, init_val, input_value): output_value = torch.zeros([20], dtype=torch.float32, device=device) one_value = torch.tensor([1], dtype=torch.int32, device=device) -# ///////// -# def cond_fn(upper, lower, one_value, x, input_value, output_value): -# return lower[0] < upper[0] - -# def body_fn(upper, lower, one_value, x, input_value, output_value): -# new_lower = torch.add(one_value, lower) -# # output_value_real = linear_0(input_value) -# output_value = linear_0(input_value) -# weight = linear_0.weight # not be used actually, initialized as placeholder xlacomputation requirement -# bias = linear_0.bias # not be used actually, initialized as placeholder xlacomputation requirement -# # return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value_real.clone(), weight.clone(), bias.clone() # , output_value_real -# return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), bias.clone(), weight.clone(), output_value.clone() # , output_value_real - -# ///////// - if (hasattr(body_fun, 'weight') or hasattr(body_fun, 'bias')): # print("body_fun.weight: ", body_fun.weight) # print("body_fun.bias: ", body_fun.bias) From 14f056962e16a2c9c0d7d7d3141d9c4dda52c179 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 20:41:45 +0000 Subject: [PATCH 287/323] update --- torch_xla/experimental/fori_loop.py | 1 + 1 file changed, 1 insertion(+) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 15b12464d2c..c2ba37f2473 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -16,6 +16,7 @@ def fori_loop(upper, lower, body_fun, init_val, input_value): device = xm.xla_device() + body_fun = torch.nn.Linear(10, 20).to(xm.xla_device()) output_value = torch.zeros([20], dtype=torch.float32, device=device) one_value = torch.tensor([1], dtype=torch.int32, device=device) From d07015a03effef894117ad1075bbe93e9e19fa35 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 20:46:33 +0000 Subject: [PATCH 288/323] update --- torch_xla/experimental/fori_loop.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index c2ba37f2473..40992de631e 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -16,11 +16,25 @@ def fori_loop(upper, lower, body_fun, init_val, input_value): device = xm.xla_device() - body_fun = torch.nn.Linear(10, 20).to(xm.xla_device()) + # body_fun = torch.nn.Linear(10, 20).to(xm.xla_device()) output_value = torch.zeros([20], dtype=torch.float32, device=device) one_value = torch.tensor([1], dtype=torch.int32, device=device) + def cond_fn(upper, lower, one_value, x, input_value, output_value): + return lower[0] < upper[0] + def body_fn(upper, lower, one_value, x, input_value, output_value): + new_lower = torch.add(one_value, lower) + output_value = body_fun(input_value) + weight = body_fun.weight ### not be used actually, initialized as placeholder xlacomputation requirement + bias = body_fun.bias ### not be used actually, initialized as placeholder xlacomputation requirement + # return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value + return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), bias.clone(), weight.clone(), output_value.clone() + # weight_0 = body_fun.weight + # bias_0 = body_fun.bias + res = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) + return res + if (hasattr(body_fun, 'weight') or hasattr(body_fun, 'bias')): # print("body_fun.weight: ", body_fun.weight) # print("body_fun.bias: ", body_fun.bias) @@ -32,7 +46,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): weight = body_fun.weight ### not be used actually, initialized as placeholder xlacomputation requirement bias = body_fun.bias ### not be used actually, initialized as placeholder xlacomputation requirement # return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value - return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), bias.clone(), weight.clone(), output_value.clone() # + return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), bias.clone(), weight.clone(), output_value.clone() # weight_0 = body_fun.weight # bias_0 = body_fun.bias res = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) @@ -43,7 +57,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) output_value = body_fun(input_value) return upper, new_lower, one_value, torch.add(one_value, x), input_value, output_value - res = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, *input_value, output_value)) + res = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) # output_value = torch.zeros([20], dtype=torch.float32, device=device) # one_value = torch.tensor([1], dtype=torch.int32, device=device) From 55061c3a17f15d342ae8a0cd13b29b75eae70502 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 21:00:05 +0000 Subject: [PATCH 289/323] update --- torch_xla/experimental/fori_loop.py | 1 + 1 file changed, 1 insertion(+) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 40992de631e..77eb4485f78 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -10,6 +10,7 @@ from torch._ops import HigherOrderOperator import torch._higher_order_ops.while_loop from torch._higher_order_ops.while_loop import while_loop_op +from torch._higher_order_ops.while_loop import while_loop ### TODO(@manfei): treat *input_value From f1a596a724d12c086d2f1826f12931ddad5ea391 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 21:01:28 +0000 Subject: [PATCH 290/323] update --- torch_xla/experimental/fori_loop.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 77eb4485f78..e634fb797a2 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -10,7 +10,7 @@ from torch._ops import HigherOrderOperator import torch._higher_order_ops.while_loop from torch._higher_order_ops.while_loop import while_loop_op -from torch._higher_order_ops.while_loop import while_loop +from torch._higher_order_ops.while_loop import while_loop as torch_while_loop ### TODO(@manfei): treat *input_value @@ -33,7 +33,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), bias.clone(), weight.clone(), output_value.clone() # weight_0 = body_fun.weight # bias_0 = body_fun.bias - res = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) + res = torch_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) return res if (hasattr(body_fun, 'weight') or hasattr(body_fun, 'bias')): From 3818380dcdfc6f3fe2abe309a617d93c1e9ba671 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 21:02:56 +0000 Subject: [PATCH 291/323] update --- torch_xla/experimental/fori_loop.py | 30 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index e634fb797a2..2ecb88fc1cc 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -22,19 +22,19 @@ def fori_loop(upper, lower, body_fun, init_val, input_value): output_value = torch.zeros([20], dtype=torch.float32, device=device) one_value = torch.tensor([1], dtype=torch.int32, device=device) - def cond_fn(upper, lower, one_value, x, input_value, output_value): - return lower[0] < upper[0] - def body_fn(upper, lower, one_value, x, input_value, output_value): - new_lower = torch.add(one_value, lower) - output_value = body_fun(input_value) - weight = body_fun.weight ### not be used actually, initialized as placeholder xlacomputation requirement - bias = body_fun.bias ### not be used actually, initialized as placeholder xlacomputation requirement - # return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value - return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), bias.clone(), weight.clone(), output_value.clone() - # weight_0 = body_fun.weight - # bias_0 = body_fun.bias - res = torch_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) - return res + # def cond_fn(upper, lower, one_value, x, input_value, output_value): + # return lower[0] < upper[0] + # def body_fn(upper, lower, one_value, x, input_value, output_value): + # new_lower = torch.add(one_value, lower) + # output_value = body_fun(input_value) + # weight = body_fun.weight ### not be used actually, initialized as placeholder xlacomputation requirement + # bias = body_fun.bias ### not be used actually, initialized as placeholder xlacomputation requirement + # # return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value + # return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), bias.clone(), weight.clone(), output_value.clone() + # # weight_0 = body_fun.weight + # # bias_0 = body_fun.bias + # res = torch_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) + # return res if (hasattr(body_fun, 'weight') or hasattr(body_fun, 'bias')): # print("body_fun.weight: ", body_fun.weight) @@ -50,7 +50,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), bias.clone(), weight.clone(), output_value.clone() # weight_0 = body_fun.weight # bias_0 = body_fun.bias - res = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) + res = torch_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) else: def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] @@ -58,7 +58,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) output_value = body_fun(input_value) return upper, new_lower, one_value, torch.add(one_value, x), input_value, output_value - res = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) + res = torch_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) # output_value = torch.zeros([20], dtype=torch.float32, device=device) # one_value = torch.tensor([1], dtype=torch.int32, device=device) From b70a34d5f2e0e203821828dadd9b6c73203625a9 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 21:03:48 +0000 Subject: [PATCH 292/323] update --- torch_xla/experimental/fori_loop.py | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 2ecb88fc1cc..cf94532ca15 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -17,28 +17,11 @@ def fori_loop(upper, lower, body_fun, init_val, input_value): device = xm.xla_device() - # body_fun = torch.nn.Linear(10, 20).to(xm.xla_device()) output_value = torch.zeros([20], dtype=torch.float32, device=device) one_value = torch.tensor([1], dtype=torch.int32, device=device) - # def cond_fn(upper, lower, one_value, x, input_value, output_value): - # return lower[0] < upper[0] - # def body_fn(upper, lower, one_value, x, input_value, output_value): - # new_lower = torch.add(one_value, lower) - # output_value = body_fun(input_value) - # weight = body_fun.weight ### not be used actually, initialized as placeholder xlacomputation requirement - # bias = body_fun.bias ### not be used actually, initialized as placeholder xlacomputation requirement - # # return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value - # return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), bias.clone(), weight.clone(), output_value.clone() - # # weight_0 = body_fun.weight - # # bias_0 = body_fun.bias - # res = torch_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) - # return res - if (hasattr(body_fun, 'weight') or hasattr(body_fun, 'bias')): - # print("body_fun.weight: ", body_fun.weight) - # print("body_fun.bias: ", body_fun.bias) def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] def body_fn(upper, lower, one_value, x, input_value, output_value): @@ -46,10 +29,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): output_value = body_fun(input_value) weight = body_fun.weight ### not be used actually, initialized as placeholder xlacomputation requirement bias = body_fun.bias ### not be used actually, initialized as placeholder xlacomputation requirement - # return upper, new_lower, one_value, torch.add(one_value, x), input_value, weight, bias, output_value return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), bias.clone(), weight.clone(), output_value.clone() - # weight_0 = body_fun.weight - # bias_0 = body_fun.bias res = torch_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) else: def cond_fn(upper, lower, one_value, x, input_value, output_value): @@ -60,14 +40,6 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): return upper, new_lower, one_value, torch.add(one_value, x), input_value, output_value res = torch_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) - # output_value = torch.zeros([20], dtype=torch.float32, device=device) - # one_value = torch.tensor([1], dtype=torch.int32, device=device) - # if (hasattr(body_fun, 'weight') or hasattr(body_fun, 'bias')): - # weight_0 = body_fun.weight - # bias_0 = body_fun.bias - # res = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, *input_value, weight_0, bias_0, output_value)) - # else: - # res = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, *input_value, output_value)) return res From 26d2fdb57486ff7cd246af243aa72518a31a78b2 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 21:06:46 +0000 Subject: [PATCH 293/323] update --- ...ri_loop_with_while_loop_simple_add_dispatch_in_torch.py | 1 + torch_xla/experimental/fori_loop.py | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 1cdc0e054af..322829a1e61 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -198,6 +198,7 @@ def body_fun(a, b): expected = _fake_fori_loop(lower, upper, body_fun, init_val, one_value) self.assertEqual(expected, res_) +# passed def test_fori_loop_tpu_simple_linear(self): xm.mark_step() diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index cf94532ca15..3aac50599a0 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -87,9 +87,10 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): # !!! cond xlacomputation change !!! switch output_value and weight position additional_inputs_list_cond = list(fake_carried_inputs[2:]) ### all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor - tmp_bias = additional_inputs_list_cond[-3] ### not used, change order doesn't affect logic - del additional_inputs_list_cond[-3] ### not used, change order doesn't affect logic - additional_inputs_list_cond.append(tmp_bias) ### not used, change order doesn't affect logic + if additional_inputs: + tmp_bias = additional_inputs_list_cond[-3] ### not used, change order doesn't affect logic + del additional_inputs_list_cond[-3] ### not used, change order doesn't affect logic + additional_inputs_list_cond.append(tmp_bias) ### not used, change order doesn't affect logic cond_ctx.buildforiloop([cond_result], additional_inputs_list_cond) cond_hlo = cond_ctx.hlo() From c8e39fe8f883c565e1cb1a51201ee5ddbc03d49c Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 21:07:45 +0000 Subject: [PATCH 294/323] update --- torch_xla/experimental/fori_loop.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 3aac50599a0..7140bafb039 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -106,7 +106,10 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): body_ctx.set_name_string("bodyctx") # !!! body xlacomputation change !!! add non-changed output_value argument - additional_inputs_list_body = [fake_carried_inputs[-3]] + if additional_inputs: + additional_inputs_list_body = [fake_carried_inputs[-3]] + else: + additional_inputs_list_body = [] ### TODO(@manfei): treat hard-code parameters: additional_inputs_list_body body_ctx.buildforiloop(list(body_result), additional_inputs_list_body) From 12371764f300045e96241e112b4a8b02c2df5bb0 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 21:08:49 +0000 Subject: [PATCH 295/323] update --- torch_xla/experimental/fori_loop.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 7140bafb039..4c2920bbf1e 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -141,9 +141,10 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): ### TODO(@manfei): treat hard-code input arguments # !!! init change !!! switch bias and output_value - tmp_bias = params[-3] - del params[-3] - params.append(tmp_bias) + if additional_inputs: + tmp_bias = params[-3] + del params[-3] + params.append(tmp_bias) ### generate while xlacomputation input_tuple = xb.Op.tuple(tuple(params)) From 620d6270e71782833a84987cd9ba693739a2775a Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 21:09:51 +0000 Subject: [PATCH 296/323] update --- torch_xla/experimental/fori_loop.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 4c2920bbf1e..f5af1b8c967 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -85,7 +85,7 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): # del additional_inputs_list_cond[-2] ### not used, change order doesn't affect logic # additional_inputs_list_cond.append(tmp_bias) ### not used, change order doesn't affect logic - # !!! cond xlacomputation change !!! switch output_value and weight position + # !!! cond xlacomputation change !!! switch output_value and weight position if additional_inputs(weight/bias) exists additional_inputs_list_cond = list(fake_carried_inputs[2:]) ### all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor if additional_inputs: tmp_bias = additional_inputs_list_cond[-3] ### not used, change order doesn't affect logic @@ -105,7 +105,7 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): body_ctx = torch_xla._XLAC.lowering.LoweringContext() body_ctx.set_name_string("bodyctx") - # !!! body xlacomputation change !!! add non-changed output_value argument + # !!! body xlacomputation change !!! add non-changed output_value argument if additional_inputs(weight/bias) exists if additional_inputs: additional_inputs_list_body = [fake_carried_inputs[-3]] else: @@ -140,7 +140,7 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): # params.append(tmp_bias) ### TODO(@manfei): treat hard-code input arguments - # !!! init change !!! switch bias and output_value + # !!! init change !!! switch bias and output_value if additional_inputs(weight/bias) exists if additional_inputs: tmp_bias = params[-3] del params[-3] From cfa5f7e932a364bfb52eac25ec46e68b7e5019c2 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 21:10:06 +0000 Subject: [PATCH 297/323] update --- torch_xla/experimental/fori_loop.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index f5af1b8c967..ed6bf8438c5 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -79,12 +79,6 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): cond_ctx = torch_xla._XLAC.lowering.LoweringContext() cond_ctx.set_name_string("condctx") - # # !!! cond xlacomputation change !!! switch bias and weight position - # additional_inputs_list_cond = list(fake_carried_inputs[2:]) ### all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor - # tmp_bias = additional_inputs_list_cond[-2] ### not used, change order doesn't affect logic - # del additional_inputs_list_cond[-2] ### not used, change order doesn't affect logic - # additional_inputs_list_cond.append(tmp_bias) ### not used, change order doesn't affect logic - # !!! cond xlacomputation change !!! switch output_value and weight position if additional_inputs(weight/bias) exists additional_inputs_list_cond = list(fake_carried_inputs[2:]) ### all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor if additional_inputs: From 0cb1dce13221b29b5da139facfb8712a7b817ddc Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 21:13:41 +0000 Subject: [PATCH 298/323] update --- ...ori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 6 ++++-- torch_xla/experimental/fori_loop.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 322829a1e61..84dfe3e11d8 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -32,6 +32,7 @@ def _fake_fori_loop(lower, upper, body_fun, *init_val): class WhileLoopTest(unittest.TestCase): +# passed def test_while_loop_tpu_subtraction(self): device = xm.xla_device() @@ -50,6 +51,7 @@ def body_fn(init, limit_value): expected = _fake_while_loop(cond_fn, body_fn, (init, limit_value)) self.assertEqual(expected, res) +# passed def test_while_loop_tpu_addition(self): device = xm.xla_device() @@ -68,6 +70,7 @@ def body_fn(init, limit_value): expected = _fake_while_loop(cond_fn, body_fn, (init, limit_value)) self.assertEqual(expected, res) +# passed def test_while_loop_tpu_subtraction_nested(self): device = xm.xla_device() @@ -193,8 +196,7 @@ def test_fori_loop_tpu_addition(self): def body_fun(a, b): return torch.add(a, b) - lower_, upper_, res_ = fori_loop(upper, lower, body_fun, one_value, - init_val) + lower_, upper_, res_ = fori_loop(upper, lower, body_fun, one_value, init_val) expected = _fake_fori_loop(lower, upper, body_fun, init_val, one_value) self.assertEqual(expected, res_) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index ed6bf8438c5..e99953c9ec4 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -26,7 +26,7 @@ def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) - output_value = body_fun(input_value) + output_value = body_fun(input_value, one_value) weight = body_fun.weight ### not be used actually, initialized as placeholder xlacomputation requirement bias = body_fun.bias ### not be used actually, initialized as placeholder xlacomputation requirement return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), bias.clone(), weight.clone(), output_value.clone() From 2dcfab0790dd95b103a2805e690d1fd3c71dc473 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 21:14:21 +0000 Subject: [PATCH 299/323] update --- torch_xla/experimental/fori_loop.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index e99953c9ec4..da166177d01 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -26,7 +26,7 @@ def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) - output_value = body_fun(input_value, one_value) + output_value = body_fun(input_value) weight = body_fun.weight ### not be used actually, initialized as placeholder xlacomputation requirement bias = body_fun.bias ### not be used actually, initialized as placeholder xlacomputation requirement return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), bias.clone(), weight.clone(), output_value.clone() @@ -36,7 +36,7 @@ def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) - output_value = body_fun(input_value) + output_value = body_fun(input_value, one_value) return upper, new_lower, one_value, torch.add(one_value, x), input_value, output_value res = torch_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) From d0270b6cf80720b099f5853fc2e4facace86baff Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 21:14:57 +0000 Subject: [PATCH 300/323] update --- torch_xla/experimental/fori_loop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index da166177d01..5c66d48010e 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -36,7 +36,7 @@ def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) - output_value = body_fun(input_value, one_value) + output_value = body_fun(one_value, input_value) return upper, new_lower, one_value, torch.add(one_value, x), input_value, output_value res = torch_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) From 2377b8b12e85d67c1a23759dd0801fa4093843fc Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 21:23:16 +0000 Subject: [PATCH 301/323] update --- torch_xla/experimental/fori_loop.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 5c66d48010e..4c25db6515c 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -12,6 +12,32 @@ from torch._higher_order_ops.while_loop import while_loop_op from torch._higher_order_ops.while_loop import while_loop as torch_while_loop +///////// + def test_while_loop_tpu_addition(self): + device = xm.xla_device() + def cond_fn(init, limit_value): + return limit_value[0] >= init[0] + def body_fn(init, limit_value): + one_value = torch.ones(1, dtype=torch.int32, device=device) + return (torch.add(init, one_value), limit_value.clone()) + # TODO(@manfei): init and limit_value has to be torch.tensor. + init = torch.tensor([0], dtype=torch.int32, device=device) + limit_value = torch.tensor([10], dtype=torch.int32, device=device) + res = while_loop(cond_fn, body_fn, (init, limit_value)) +///////// +def fori_loop(lower, upper, user_body_func, *init_val): + device = xm.xla_device() + def cond_fn(upper, lower, *init_val): + return lower[0] < upper[0] + def body_fn(upper, lower, *init_val): + one_value_i = torch.ones(1, dtype=torch.int32, device=device) + res_list = list(user_body_func(*init_val)) + res_list.insert(0, lower) + res_list.insert(0, torch.sub(upper, one_value_i)) + return res_list + res = while_loop(cond_fn, body_fn, (lower, upper, *init_val)) + return res +///////// ### TODO(@manfei): treat *input_value def fori_loop(upper, lower, body_fun, init_val, input_value): @@ -37,7 +63,7 @@ def cond_fn(upper, lower, one_value, x, input_value, output_value): def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) output_value = body_fun(one_value, input_value) - return upper, new_lower, one_value, torch.add(one_value, x), input_value, output_value + return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value.clone() res = torch_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) return res From 8947db7e6ec4b0233a0532f1c7b2637107400b8c Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 21:23:40 +0000 Subject: [PATCH 302/323] update --- torch_xla/experimental/fori_loop.py | 52 ++++++++++++++--------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 4c25db6515c..eef46f7f0e6 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -12,32 +12,32 @@ from torch._higher_order_ops.while_loop import while_loop_op from torch._higher_order_ops.while_loop import while_loop as torch_while_loop -///////// - def test_while_loop_tpu_addition(self): - device = xm.xla_device() - def cond_fn(init, limit_value): - return limit_value[0] >= init[0] - def body_fn(init, limit_value): - one_value = torch.ones(1, dtype=torch.int32, device=device) - return (torch.add(init, one_value), limit_value.clone()) - # TODO(@manfei): init and limit_value has to be torch.tensor. - init = torch.tensor([0], dtype=torch.int32, device=device) - limit_value = torch.tensor([10], dtype=torch.int32, device=device) - res = while_loop(cond_fn, body_fn, (init, limit_value)) -///////// -def fori_loop(lower, upper, user_body_func, *init_val): - device = xm.xla_device() - def cond_fn(upper, lower, *init_val): - return lower[0] < upper[0] - def body_fn(upper, lower, *init_val): - one_value_i = torch.ones(1, dtype=torch.int32, device=device) - res_list = list(user_body_func(*init_val)) - res_list.insert(0, lower) - res_list.insert(0, torch.sub(upper, one_value_i)) - return res_list - res = while_loop(cond_fn, body_fn, (lower, upper, *init_val)) - return res -///////// +# ///////// +# def test_while_loop_tpu_addition(self): +# device = xm.xla_device() +# def cond_fn(init, limit_value): +# return limit_value[0] >= init[0] +# def body_fn(init, limit_value): +# one_value = torch.ones(1, dtype=torch.int32, device=device) +# return (torch.add(init, one_value), limit_value.clone()) +# # TODO(@manfei): init and limit_value has to be torch.tensor. +# init = torch.tensor([0], dtype=torch.int32, device=device) +# limit_value = torch.tensor([10], dtype=torch.int32, device=device) +# res = while_loop(cond_fn, body_fn, (init, limit_value)) +# ///////// +# def fori_loop(lower, upper, user_body_func, *init_val): +# device = xm.xla_device() +# def cond_fn(upper, lower, *init_val): +# return lower[0] < upper[0] +# def body_fn(upper, lower, *init_val): +# one_value_i = torch.ones(1, dtype=torch.int32, device=device) +# res_list = list(user_body_func(*init_val)) +# res_list.insert(0, lower) +# res_list.insert(0, torch.sub(upper, one_value_i)) +# return res_list +# res = while_loop(cond_fn, body_fn, (lower, upper, *init_val)) +# return res +# ///////// ### TODO(@manfei): treat *input_value def fori_loop(upper, lower, body_fun, init_val, input_value): From 0fbb23d0049d2f61ee9e9b728ee552d8a9f98200 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 21:27:25 +0000 Subject: [PATCH 303/323] update --- torch_xla/experimental/fori_loop.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index eef46f7f0e6..a492e56a462 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -58,13 +58,13 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), bias.clone(), weight.clone(), output_value.clone() res = torch_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) else: - def cond_fn(upper, lower, one_value, x, input_value, output_value): + def cond_fn(upper, lower, one_value, x, input_value): return lower[0] < upper[0] - def body_fn(upper, lower, one_value, x, input_value, output_value): + def body_fn(upper, lower, one_value, x, input_value): new_lower = torch.add(one_value, lower) - output_value = body_fun(one_value, input_value) - return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value.clone() - res = torch_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) + output_val = body_fun(one_value, input_value) + return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), output_val.clone() + res = torch_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value)) return res From 53f818564c0a46ee18d3395b0c3dde0402318f38 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 21:29:29 +0000 Subject: [PATCH 304/323] update --- ...i_loop_with_while_loop_simple_add_dispatch_in_torch.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 84dfe3e11d8..ad14be19f40 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -196,7 +196,13 @@ def test_fori_loop_tpu_addition(self): def body_fun(a, b): return torch.add(a, b) - lower_, upper_, res_ = fori_loop(upper, lower, body_fun, one_value, init_val) + # lower_, upper_, res_ = fori_loop(upper, lower, body_fun, one_value, init_val) + upper_, new_lower_, one_value_, add_res_x_, res_ = fori_loop(upper, lower, body_fun, one_value, init_val) + print("upper_: ", upper_) + print("new_lower_: ", new_lower_) + print("one_value_: ", one_value_) + print("add_res_x_: ", add_res_x_) + print("res_: ", res_) expected = _fake_fori_loop(lower, upper, body_fun, init_val, one_value) self.assertEqual(expected, res_) From 52435ecbf6152d10471b06d0189f3b79528b98db Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 21:33:18 +0000 Subject: [PATCH 305/323] update --- torch_xla/experimental/fori_loop.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index a492e56a462..0696977b069 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -44,10 +44,11 @@ def fori_loop(upper, lower, body_fun, init_val, input_value): device = xm.xla_device() - output_value = torch.zeros([20], dtype=torch.float32, device=device) + # output_value = torch.zeros([20], dtype=torch.float32, device=device) one_value = torch.tensor([1], dtype=torch.int32, device=device) if (hasattr(body_fun, 'weight') or hasattr(body_fun, 'bias')): + output_value = torch.zeros([20], dtype=torch.float32, device=device) def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] def body_fn(upper, lower, one_value, x, input_value, output_value): @@ -58,13 +59,15 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), bias.clone(), weight.clone(), output_value.clone() res = torch_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) else: - def cond_fn(upper, lower, one_value, x, input_value): + # output_value = torch.zeros([1], dtype=torch.float32, device=device) + output_value = torch.tensor([1], dtype=torch.int32, device=device) + def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] - def body_fn(upper, lower, one_value, x, input_value): + def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) output_val = body_fun(one_value, input_value) - return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), output_val.clone() - res = torch_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value)) + return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_val.clone() + res = torch_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) return res From 116a68bc9b19ac61ae60e92af25a08fea41a0256 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 21:39:13 +0000 Subject: [PATCH 306/323] update --- torch_xla/experimental/fori_loop.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 0696977b069..950e26d4e3e 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -132,7 +132,8 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): if additional_inputs: additional_inputs_list_body = [fake_carried_inputs[-3]] else: - additional_inputs_list_body = [] + # add fake output_value to do map and not reuse output in the next turn + additional_inputs_list_body = [fake_carried_inputs[-1]] ### TODO(@manfei): treat hard-code parameters: additional_inputs_list_body body_ctx.buildforiloop(list(body_result), additional_inputs_list_body) From 3cb631a21bd1d952d9a3d089dac73882de486714 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 21:40:53 +0000 Subject: [PATCH 307/323] update --- ..._fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 4 ++++ torch_xla/experimental/fori_loop.py | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index ad14be19f40..9a49d6b5c2b 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -49,6 +49,8 @@ def body_fn(init, limit_value): limit_value = torch.tensor([0], dtype=torch.int32, device=device) res = while_loop(cond_fn, body_fn, (init, limit_value)) expected = _fake_while_loop(cond_fn, body_fn, (init, limit_value)) + print("expected: ", expected) + print("res: ", res) self.assertEqual(expected, res) # passed @@ -69,6 +71,8 @@ def body_fn(init, limit_value): res = while_loop(cond_fn, body_fn, (init, limit_value)) expected = _fake_while_loop(cond_fn, body_fn, (init, limit_value)) self.assertEqual(expected, res) + print("expected: ", expected) + print("res: ", res) # passed def test_while_loop_tpu_subtraction_nested(self): diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 950e26d4e3e..0696977b069 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -132,8 +132,7 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): if additional_inputs: additional_inputs_list_body = [fake_carried_inputs[-3]] else: - # add fake output_value to do map and not reuse output in the next turn - additional_inputs_list_body = [fake_carried_inputs[-1]] + additional_inputs_list_body = [] ### TODO(@manfei): treat hard-code parameters: additional_inputs_list_body body_ctx.buildforiloop(list(body_result), additional_inputs_list_body) From fe3a5302d314630af0dfcb3d01f1338acc50238f Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 21:42:22 +0000 Subject: [PATCH 308/323] update --- torch_xla/experimental/fori_loop.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 0696977b069..32513a59936 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -61,13 +61,13 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): else: # output_value = torch.zeros([1], dtype=torch.float32, device=device) output_value = torch.tensor([1], dtype=torch.int32, device=device) - def cond_fn(upper, lower, one_value, x, input_value, output_value): + def cond_fn(upper, lower, one_value, x, input_value): # , output_value): return lower[0] < upper[0] - def body_fn(upper, lower, one_value, x, input_value, output_value): + def body_fn(upper, lower, one_value, x, input_value): # , output_value): new_lower = torch.add(one_value, lower) output_val = body_fun(one_value, input_value) - return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_val.clone() - res = torch_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) + return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), output_val.clone() + res = torch_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value)) return res From ac574f35f9be4630e532f8d8e8961612c077de7e Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 21:44:08 +0000 Subject: [PATCH 309/323] update --- ...est_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 9a49d6b5c2b..6d7009b04ce 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -208,6 +208,7 @@ def body_fun(a, b): print("add_res_x_: ", add_res_x_) print("res_: ", res_) expected = _fake_fori_loop(lower, upper, body_fun, init_val, one_value) + print("expected: ", expected) self.assertEqual(expected, res_) # passed From ca3e7576e3885c103cb8d40cac737df13bc4450f Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 21:46:51 +0000 Subject: [PATCH 310/323] update --- ...t_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 6d7009b04ce..1cacbdee9f6 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -23,7 +23,8 @@ def _fake_fori_loop(lower, upper, body_fun, *init_val): if len(init_val) > 1: (a, b) = init_val for i in range((upper - lower)[0]): - a = body_fun(*init_val) + # a = body_fun(*init_val) + a = body_fun(a, b) else: for i in range((upper - lower)[0]): a = body_fun(*init_val) From 18194202a1444db45602395fa544eb51aef54f47 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 21:49:25 +0000 Subject: [PATCH 311/323] update --- ...while_loop_simple_add_dispatch_in_torch.py | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 1cacbdee9f6..29ae7e108c0 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -50,8 +50,8 @@ def body_fn(init, limit_value): limit_value = torch.tensor([0], dtype=torch.int32, device=device) res = while_loop(cond_fn, body_fn, (init, limit_value)) expected = _fake_while_loop(cond_fn, body_fn, (init, limit_value)) - print("expected: ", expected) - print("res: ", res) + # print("expected: ", expected) + # print("res: ", res) self.assertEqual(expected, res) # passed @@ -72,8 +72,8 @@ def body_fn(init, limit_value): res = while_loop(cond_fn, body_fn, (init, limit_value)) expected = _fake_while_loop(cond_fn, body_fn, (init, limit_value)) self.assertEqual(expected, res) - print("expected: ", expected) - print("res: ", res) + # print("expected: ", expected) + # print("res: ", res) # passed def test_while_loop_tpu_subtraction_nested(self): @@ -188,6 +188,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): self.assertTrue(torch.all(torch.eq(expected, output_value_real__))) return aaa +# passed def test_fori_loop_tpu_addition(self): xm.mark_step() @@ -203,13 +204,13 @@ def body_fun(a, b): # lower_, upper_, res_ = fori_loop(upper, lower, body_fun, one_value, init_val) upper_, new_lower_, one_value_, add_res_x_, res_ = fori_loop(upper, lower, body_fun, one_value, init_val) - print("upper_: ", upper_) - print("new_lower_: ", new_lower_) - print("one_value_: ", one_value_) - print("add_res_x_: ", add_res_x_) - print("res_: ", res_) + # print("upper_: ", upper_) + # print("new_lower_: ", new_lower_) + # print("one_value_: ", one_value_) + # print("add_res_x_: ", add_res_x_) + # print("res_: ", res_) expected = _fake_fori_loop(lower, upper, body_fun, init_val, one_value) - print("expected: ", expected) + # print("expected: ", expected) self.assertEqual(expected, res_) # passed From 1b91fc82a12eb429e35f2844c35967ff87491910 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 21:49:51 +0000 Subject: [PATCH 312/323] update --- torch_xla/experimental/fori_loop.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 32513a59936..863ba0c6d1f 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -78,8 +78,8 @@ def while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): ### cond_fn&body_fn: callable ### carried_inputs: (Tuple of possibly nested dict/list/tuple of tensors) print("arrive here @while_loop_op.py_impl(DispatchKey.XLA) !!!") - print("carried_inputs: ", carried_inputs) - print("additional_inputs: ", additional_inputs) + # print("carried_inputs: ", carried_inputs) + # print("additional_inputs: ", additional_inputs) if additional_inputs is None: additional_inputs = tuple() return _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs) @@ -101,7 +101,7 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): fake_carried_inputs.append( torch.randint(10, additional_input.size(), dtype=additional_input.dtype).to(device)) - print("fake_carried_inputs: ", fake_carried_inputs) + # print("fake_carried_inputs: ", fake_carried_inputs) ### TODO(@manfei): specify which element is for which argument like a,b,c cond_result = cond_fn(*fake_carried_inputs) From 673145d105d15c965bf72bbe8bc160c7df6307ab Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 21:50:44 +0000 Subject: [PATCH 313/323] update --- torch_xla/experimental/fori_loop.py | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 863ba0c6d1f..1c4394d73bd 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -12,32 +12,6 @@ from torch._higher_order_ops.while_loop import while_loop_op from torch._higher_order_ops.while_loop import while_loop as torch_while_loop -# ///////// -# def test_while_loop_tpu_addition(self): -# device = xm.xla_device() -# def cond_fn(init, limit_value): -# return limit_value[0] >= init[0] -# def body_fn(init, limit_value): -# one_value = torch.ones(1, dtype=torch.int32, device=device) -# return (torch.add(init, one_value), limit_value.clone()) -# # TODO(@manfei): init and limit_value has to be torch.tensor. -# init = torch.tensor([0], dtype=torch.int32, device=device) -# limit_value = torch.tensor([10], dtype=torch.int32, device=device) -# res = while_loop(cond_fn, body_fn, (init, limit_value)) -# ///////// -# def fori_loop(lower, upper, user_body_func, *init_val): -# device = xm.xla_device() -# def cond_fn(upper, lower, *init_val): -# return lower[0] < upper[0] -# def body_fn(upper, lower, *init_val): -# one_value_i = torch.ones(1, dtype=torch.int32, device=device) -# res_list = list(user_body_func(*init_val)) -# res_list.insert(0, lower) -# res_list.insert(0, torch.sub(upper, one_value_i)) -# return res_list -# res = while_loop(cond_fn, body_fn, (lower, upper, *init_val)) -# return res -# ///////// ### TODO(@manfei): treat *input_value def fori_loop(upper, lower, body_fun, init_val, input_value): @@ -77,7 +51,7 @@ def while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): ### TODO(@manfei): PyTorch require carried_inputs to be list/tuple, PyTorch/XLA _xla_while_loop only accept *operands, *operands would tuple items again: (a, '') ### cond_fn&body_fn: callable ### carried_inputs: (Tuple of possibly nested dict/list/tuple of tensors) - print("arrive here @while_loop_op.py_impl(DispatchKey.XLA) !!!") + # print("arrive here @while_loop_op.py_impl(DispatchKey.XLA) !!!") # print("carried_inputs: ", carried_inputs) # print("additional_inputs: ", additional_inputs) if additional_inputs is None: From 12f6f71716785bc2fd7940aa947f28839d074a25 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 22:00:51 +0000 Subject: [PATCH 314/323] update --- torch_xla/experimental/fori_loop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 1c4394d73bd..80bc209aacf 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -60,7 +60,7 @@ def while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): - print("arrive here _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): !!!") + # print("arrive here _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): !!!") ### fake carried_inputs to split formal code fake_carried_inputs = [] for carried_input in carried_inputs: From 89605cbb6b91336c3012bc715b0ae870eaa26f2e Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 22:38:43 +0000 Subject: [PATCH 315/323] format --- ...while_loop_simple_add_dispatch_in_torch.py | 37 +------------------ torch_xla/experimental/fori_loop.py | 36 +++--------------- 2 files changed, 7 insertions(+), 66 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 29ae7e108c0..73d55d3dc47 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -23,7 +23,6 @@ def _fake_fori_loop(lower, upper, body_fun, *init_val): if len(init_val) > 1: (a, b) = init_val for i in range((upper - lower)[0]): - # a = body_fun(*init_val) a = body_fun(a, b) else: for i in range((upper - lower)[0]): @@ -33,7 +32,6 @@ def _fake_fori_loop(lower, upper, body_fun, *init_val): class WhileLoopTest(unittest.TestCase): -# passed def test_while_loop_tpu_subtraction(self): device = xm.xla_device() @@ -50,11 +48,8 @@ def body_fn(init, limit_value): limit_value = torch.tensor([0], dtype=torch.int32, device=device) res = while_loop(cond_fn, body_fn, (init, limit_value)) expected = _fake_while_loop(cond_fn, body_fn, (init, limit_value)) - # print("expected: ", expected) - # print("res: ", res) self.assertEqual(expected, res) -# passed def test_while_loop_tpu_addition(self): device = xm.xla_device() @@ -72,10 +67,7 @@ def body_fn(init, limit_value): res = while_loop(cond_fn, body_fn, (init, limit_value)) expected = _fake_while_loop(cond_fn, body_fn, (init, limit_value)) self.assertEqual(expected, res) - # print("expected: ", expected) - # print("res: ", res) -# passed def test_while_loop_tpu_subtraction_nested(self): device = xm.xla_device() @@ -94,54 +86,37 @@ def body_fn(init, limit_value): expected = _fake_while_loop(cond_fn, body_fn, (init, limit_value)) self.assertEqual(expected, res) -# passed def test_while_loop_tpu_simple_linear(self): xm.mark_step() device = xm.xla_device() torch.set_grad_enabled(False) - # def forward(self, upper, lower, one_value, x, input_value, output_value): linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) - # weight_0 = linear_0.weight - # bias_0 = linear_0.bias - # print("original bias: ", bias_0) def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) - # output_value_real = linear_0(input_value) output_value = linear_0(input_value) weight = linear_0.weight # not be used actually, initialized as placeholder xlacomputation requirement bias = linear_0.bias # not be used actually, initialized as placeholder xlacomputation requirement - # return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value_real.clone(), weight.clone(), bias.clone() # , output_value_real return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), bias.clone(), weight.clone(), output_value.clone() # , output_value_real upper = torch.tensor([1], dtype=torch.int32, device=device) lower = torch.tensor([0], dtype=torch.int32, device=device) one_value = torch.tensor([1], dtype=torch.int32, device=device) init_val = torch.tensor([1], dtype=torch.int32, device=device) - # l_in_0 = torch.ones(10, device=xm.xla_device()) # input_value - l_in_0 = torch.rand(10, device=xm.xla_device()) # input_value + l_in_0 = torch.rand(10, device=xm.xla_device()) output_value = torch.zeros([20], dtype=torch.float32, device=device) - # weight_0 = linear_0.weight - # bias_0 = linear_0.bias upper__, lower__, one_value__, torch_add_res__, input_value__, bias__, weight__, output_value_real__, = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) - # print("torch_add_res__: ", torch_add_res__) - # print("output_value_real__: ", output_value_real__) - # print("bias__: ", bias__) - # print("expected: ", expected) - - # self.assertTrue(torch.all(torch.eq(expected, output_value_real__))) return self.assertTrue(torch.all(torch.eq(expected, output_value_real__))) -# passed def test_while_loop_tpu_simple_linear_class(self): xm.mark_step() @@ -177,6 +152,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): bias_0 = simple_with_linear.linear.bias aaa = {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} + upper__, lower__, one_value__, torch_add_res__, input_value__, output_value_real__, weight__, bias__ = simple_with_linear(upper, lower, one_value, init_val, l_in_0, output_value) # same weight/bias liear model @@ -188,7 +164,6 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): self.assertTrue(torch.all(torch.eq(expected, output_value_real__))) return aaa -# passed def test_fori_loop_tpu_addition(self): xm.mark_step() @@ -202,18 +177,10 @@ def test_fori_loop_tpu_addition(self): def body_fun(a, b): return torch.add(a, b) - # lower_, upper_, res_ = fori_loop(upper, lower, body_fun, one_value, init_val) upper_, new_lower_, one_value_, add_res_x_, res_ = fori_loop(upper, lower, body_fun, one_value, init_val) - # print("upper_: ", upper_) - # print("new_lower_: ", new_lower_) - # print("one_value_: ", one_value_) - # print("add_res_x_: ", add_res_x_) - # print("res_: ", res_) expected = _fake_fori_loop(lower, upper, body_fun, init_val, one_value) - # print("expected: ", expected) self.assertEqual(expected, res_) -# passed def test_fori_loop_tpu_simple_linear(self): xm.mark_step() diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index 80bc209aacf..da1ebb4a0c9 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -18,7 +18,6 @@ def fori_loop(upper, lower, body_fun, init_val, input_value): device = xm.xla_device() - # output_value = torch.zeros([20], dtype=torch.float32, device=device) one_value = torch.tensor([1], dtype=torch.int32, device=device) if (hasattr(body_fun, 'weight') or hasattr(body_fun, 'bias')): @@ -33,11 +32,10 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), bias.clone(), weight.clone(), output_value.clone() res = torch_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) else: - # output_value = torch.zeros([1], dtype=torch.float32, device=device) output_value = torch.tensor([1], dtype=torch.int32, device=device) - def cond_fn(upper, lower, one_value, x, input_value): # , output_value): + def cond_fn(upper, lower, one_value, x, input_value): return lower[0] < upper[0] - def body_fn(upper, lower, one_value, x, input_value): # , output_value): + def body_fn(upper, lower, one_value, x, input_value): new_lower = torch.add(one_value, lower) output_val = body_fun(one_value, input_value) return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), output_val.clone() @@ -51,38 +49,31 @@ def while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): ### TODO(@manfei): PyTorch require carried_inputs to be list/tuple, PyTorch/XLA _xla_while_loop only accept *operands, *operands would tuple items again: (a, '') ### cond_fn&body_fn: callable ### carried_inputs: (Tuple of possibly nested dict/list/tuple of tensors) - # print("arrive here @while_loop_op.py_impl(DispatchKey.XLA) !!!") - # print("carried_inputs: ", carried_inputs) - # print("additional_inputs: ", additional_inputs) if additional_inputs is None: additional_inputs = tuple() return _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs) def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): - # print("arrive here _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): !!!") ### fake carried_inputs to split formal code fake_carried_inputs = [] for carried_input in carried_inputs: device = carried_input.device - ###TODO(@manfei) type = carried_input.type fake_carried_inputs.append( torch.randint(10, carried_input.size(), dtype=carried_input.dtype).to(device)) for additional_input in additional_inputs: device = additional_input.device - ###TODO(@manfei) type = carried_input.type fake_carried_inputs.append( torch.randint(10, additional_input.size(), dtype=additional_input.dtype).to(device)) - # print("fake_carried_inputs: ", fake_carried_inputs) ### TODO(@manfei): specify which element is for which argument like a,b,c cond_result = cond_fn(*fake_carried_inputs) cond_ctx = torch_xla._XLAC.lowering.LoweringContext() cond_ctx.set_name_string("condctx") - # !!! cond xlacomputation change !!! switch output_value and weight position if additional_inputs(weight/bias) exists + ### TODO(@manfei): treat hard-code cond xlacomputation change: currently switch output_value and weight position if additional_inputs(weight/bias) exists additional_inputs_list_cond = list(fake_carried_inputs[2:]) ### all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor if additional_inputs: tmp_bias = additional_inputs_list_cond[-3] ### not used, change order doesn't affect logic @@ -93,16 +84,13 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): cond_hlo = cond_ctx.hlo() cond_computation = xb.computation_from_module_proto("condcomputation", cond_hlo) - # cond_hlo_print = xb.get_computation_hlo(cond_computation) - # print("cond computation: !!!!!!!!!") - # print(cond_hlo_print) ### generate body_fn xlacomputation body_result = body_fn(*fake_carried_inputs) body_ctx = torch_xla._XLAC.lowering.LoweringContext() body_ctx.set_name_string("bodyctx") - # !!! body xlacomputation change !!! add non-changed output_value argument if additional_inputs(weight/bias) exists + ### TODO(@manfei): treat hard-code body xlacomputation change: currently add non-changed output_value argument if additional_inputs(weight/bias) exists if additional_inputs: additional_inputs_list_body = [fake_carried_inputs[-3]] else: @@ -113,9 +101,6 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): body_hlo = body_ctx.hlo() body_computation = xb.computation_from_module_proto("bodycomputation", body_hlo) - # body_hlo_print = xb.get_computation_hlo(body_computation) - # print("body computation: !!!!!!!!!") - # print(body_hlo_print) ### trans fake_carried_inputs from list(tensor) to list(xla::op), which part could change init of xla::while total_inputs = carried_inputs + additional_inputs @@ -130,14 +115,7 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): p = xb.mkparam(builder, len(params), shape) params.append(p) - # ### TODO(@manfei): treat hard-code input arguments - # # !!! init change !!! - # tmp_bias = params[-2] - # del params[-2] - # params.append(tmp_bias) - - ### TODO(@manfei): treat hard-code input arguments - # !!! init change !!! switch bias and output_value if additional_inputs(weight/bias) exists + ### TODO(@manfei): treat hard-code input arguments, currently switch bias and output_value if additional_inputs(weight/bias) exists if additional_inputs: tmp_bias = params[-3] del params[-3] @@ -151,14 +129,10 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): body_computation=body_computation) name = 'fori_loop_ed_torch_func' computation = w.build(name) - # hlo_print = xb.get_computation_hlo(computation) - # print("while computation: !!!!!!!!!") - # print(hlo_print) ### gain final result with generated while xlacomputation result = torch_xla._XLAC._xla_user_computation('xla::_op_test_while', (total_inputs), computation) - ### print("!!! arrive here too after while!!!") return result \ No newline at end of file From 2e9c979997e146b51a420ecc61d6a1b2ce93d4b2 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 22:44:27 +0000 Subject: [PATCH 316/323] format --- torch_xla/csrc/init_python_bindings.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index c7013569dd1..f48dcf9eb68 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -914,18 +914,10 @@ class PyLoweringContext { // needed in xlacomputation. void BuildForiLoop(std::vector tensors, std::vector additional_inputs_list = {}) { + // hard-code modify cond xlacomputation input arguments with unusedarguments for xla::while requriement if (GetNameString() == "condctx") { xla::XlaBuilder* local_builder = lowering_ctx.builder(); - // hard-code parameter_idx to 2 to skip existing upper/lower arguments - // TODO(@manfei): get body xlacomputation arguments' number first then decide items in `additional_inputs_list`, maybe implement in python level - // !!! since cond_fn only compare upper and lower, so it would only use two arguments, due to PyTorch/XLA - // !!! trace xlacomputation from result tensor, so all the other arguments would not be included or generated; - // !!! but to meet xla::while requirement, we would skip first two arguments, - // !!! then add all other arguments like body_fn/init - // !!! --- additional_inputs_list: this list include all other arguments like body_fn/init except upper and lower - // !!! --- next step: we add dump paras according to additional_inputs_list - // ??? --- could we get IRvalue of `additional_inputs_list` in this function to complete xlacomputation? - int64_t parameter_idx = 2; // parameter_idx start from 2 after upper and lower + int64_t parameter_idx = 2; // parameter_idx start from 2 after used upper and lower for (auto& additional_input_tensor : additional_inputs_list) { XLATensorPtr xtensor = bridge::GetXlaTensor(additional_input_tensor); xla::Shape shape = xtensor->shape().get(); @@ -935,11 +927,11 @@ class PyLoweringContext { } } - // hard-code modify body xlacomputation input arguments - // TODO(@manfei): get body xlacomputation arguments' number first then decide items in `additional_inputs_list`, maybe implement in python level + // hard-code modify body xlacomputation input arguments with unusedarguments for xla::while requriement if (GetNameString() == "bodyctx") { xla::XlaBuilder* local_builder = lowering_ctx.builder(); - int64_t parameter_idx = 7; // tensors.size(); + // TODO(@manfei): treat hard code parameter_idx value + int64_t parameter_idx = 7; for (auto& additional_input_tensor : additional_inputs_list) { XLATensorPtr xtensor = bridge::GetXlaTensor(additional_input_tensor); xla::Shape shape = xtensor->shape().get(); From 6db813948ce2e9bfb3c526f68d5100f7d7d61e06 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 22:45:32 +0000 Subject: [PATCH 317/323] format --- torch_xla/csrc/init_python_bindings.cpp | 16 +--------------- torch_xla/csrc/lowering_context.cpp | 2 -- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index f48dcf9eb68..85545ae267e 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -966,20 +966,6 @@ class PyLoweringContext { std::vector buffer_donor_indices; xla::ProgramShape program_shape = ConsumeValue(computation.GetProgramShape()); - // // hard-code modify body xlacomputation input arguments - // // xxx: failed due to not change body_xlacomputation, might becase has been traced - // // xxx: after `computation = ConsumeValue(lowering_ctx.BuildXla());` - // if (GetNameString() == "bodyctx") { - // xla::XlaBuilder* local_builder = lowering_ctx.builder(); - // int64_t parameter_idx = program_shape.parameters_size(); // tensors.size(); - // for (auto& additional_input_tensor : additional_inputs_list) { - // XLATensorPtr xtensor = bridge::GetXlaTensor(additional_input_tensor); - // xla::Shape shape = xtensor->shape().get(); - // xla::XlaOp x = xla::Parameter(local_builder, parameter_idx, shape, - // "UnusedArgumentsPlaceholder"); - // parameter_idx += 1; - // } - // } // TODO(@manfei): please confirm whether we check for more than two or use // default value true bool should_wrap_parameter = (program_shape.parameters_size() >= 2); @@ -2635,4 +2621,4 @@ void InitXlaBindings(py::module m) { InitXlaModuleBindings(m); } } // namespace torch_xla -PYBIND11_MODULE(_XLAC, m) { torch_xla::InitXlaBindings(m); } \ No newline at end of file +PYBIND11_MODULE(_XLAC, m) { torch_xla::InitXlaBindings(m); } diff --git a/torch_xla/csrc/lowering_context.cpp b/torch_xla/csrc/lowering_context.cpp index 39f82a4887b..a530995ca78 100644 --- a/torch_xla/csrc/lowering_context.cpp +++ b/torch_xla/csrc/lowering_context.cpp @@ -160,8 +160,6 @@ xla::StatusOr LoweringContext::BuildXla() { if (!root_tuple_.empty() & (root_tuple_.size() == 1) & ((get_name_string() == "condctx") or (get_name_string() == "bodyctx"))) { xla = builder()->Build(root_tuple_.at(0)); - // } else if (!root_tuple_.empty() & (root_tuple_.size() == 1) & ) { - // xla = builder()->Build(root_tuple_.at(0)); } else if (!root_tuple_.empty()) { xla::XlaOp root = xla::Tuple(builder(), root_tuple_); xla = builder()->Build(root); From da3556144b3f2c93a0b1282da38aed00f4952473 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 22:47:15 +0000 Subject: [PATCH 318/323] format --- torch_xla/experimental/fori_loop.py | 40 ++++++++++++++--------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index da1ebb4a0c9..a36649fcc3e 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -13,7 +13,7 @@ from torch._higher_order_ops.while_loop import while_loop as torch_while_loop -### TODO(@manfei): treat *input_value +# TODO(@manfei): treat *input_value def fori_loop(upper, lower, body_fun, init_val, input_value): device = xm.xla_device() @@ -27,8 +27,8 @@ def cond_fn(upper, lower, one_value, x, input_value, output_value): def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) output_value = body_fun(input_value) - weight = body_fun.weight ### not be used actually, initialized as placeholder xlacomputation requirement - bias = body_fun.bias ### not be used actually, initialized as placeholder xlacomputation requirement + weight = body_fun.weight # not be used actually, initialized as placeholder xlacomputation requirement + bias = body_fun.bias # not be used actually, initialized as placeholder xlacomputation requirement return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), bias.clone(), weight.clone(), output_value.clone() res = torch_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) else: @@ -46,16 +46,16 @@ def body_fn(upper, lower, one_value, x, input_value): @while_loop_op.py_impl(DispatchKey.XLA) def while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): - ### TODO(@manfei): PyTorch require carried_inputs to be list/tuple, PyTorch/XLA _xla_while_loop only accept *operands, *operands would tuple items again: (a, '') - ### cond_fn&body_fn: callable - ### carried_inputs: (Tuple of possibly nested dict/list/tuple of tensors) + # TODO(@manfei): PyTorch require carried_inputs to be list/tuple, PyTorch/XLA _xla_while_loop only accept *operands, *operands would tuple items again: (a, '') + # cond_fn&body_fn: callable + # carried_inputs: (Tuple of possibly nested dict/list/tuple of tensors) if additional_inputs is None: additional_inputs = tuple() return _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs) def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): - ### fake carried_inputs to split formal code + # fake carried_inputs to split formal code fake_carried_inputs = [] for carried_input in carried_inputs: device = carried_input.device @@ -68,41 +68,41 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): torch.randint(10, additional_input.size(), dtype=additional_input.dtype).to(device)) - ### TODO(@manfei): specify which element is for which argument like a,b,c + # TODO(@manfei): specify which element is for which argument like a,b,c cond_result = cond_fn(*fake_carried_inputs) cond_ctx = torch_xla._XLAC.lowering.LoweringContext() cond_ctx.set_name_string("condctx") - ### TODO(@manfei): treat hard-code cond xlacomputation change: currently switch output_value and weight position if additional_inputs(weight/bias) exists - additional_inputs_list_cond = list(fake_carried_inputs[2:]) ### all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor + # TODO(@manfei): treat hard-code cond xlacomputation change: currently switch output_value and weight position if additional_inputs(weight/bias) exists + additional_inputs_list_cond = list(fake_carried_inputs[2:]) # all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor if additional_inputs: - tmp_bias = additional_inputs_list_cond[-3] ### not used, change order doesn't affect logic - del additional_inputs_list_cond[-3] ### not used, change order doesn't affect logic - additional_inputs_list_cond.append(tmp_bias) ### not used, change order doesn't affect logic + tmp_bias = additional_inputs_list_cond[-3] # not used, change order doesn't affect logic + del additional_inputs_list_cond[-3] # not used, change order doesn't affect logic + additional_inputs_list_cond.append(tmp_bias) # not used, change order doesn't affect logic cond_ctx.buildforiloop([cond_result], additional_inputs_list_cond) cond_hlo = cond_ctx.hlo() cond_computation = xb.computation_from_module_proto("condcomputation", cond_hlo) - ### generate body_fn xlacomputation + # generate body_fn xlacomputation body_result = body_fn(*fake_carried_inputs) body_ctx = torch_xla._XLAC.lowering.LoweringContext() body_ctx.set_name_string("bodyctx") - ### TODO(@manfei): treat hard-code body xlacomputation change: currently add non-changed output_value argument if additional_inputs(weight/bias) exists + # TODO(@manfei): treat hard-code body xlacomputation change: currently add non-changed output_value argument if additional_inputs(weight/bias) exists if additional_inputs: additional_inputs_list_body = [fake_carried_inputs[-3]] else: additional_inputs_list_body = [] - ### TODO(@manfei): treat hard-code parameters: additional_inputs_list_body + # TODO(@manfei): treat hard-code parameters: additional_inputs_list_body body_ctx.buildforiloop(list(body_result), additional_inputs_list_body) body_hlo = body_ctx.hlo() body_computation = xb.computation_from_module_proto("bodycomputation", body_hlo) - ### trans fake_carried_inputs from list(tensor) to list(xla::op), which part could change init of xla::while + # trans fake_carried_inputs from list(tensor) to list(xla::op), which part could change init of xla::while total_inputs = carried_inputs + additional_inputs kwargs = {} if type(total_inputs) is tuple: @@ -115,13 +115,13 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): p = xb.mkparam(builder, len(params), shape) params.append(p) - ### TODO(@manfei): treat hard-code input arguments, currently switch bias and output_value if additional_inputs(weight/bias) exists + # TODO(@manfei): treat hard-code input arguments, currently switch bias and output_value if additional_inputs(weight/bias) exists if additional_inputs: tmp_bias = params[-3] del params[-3] params.append(tmp_bias) - ### generate while xlacomputation + # generate while xlacomputation input_tuple = xb.Op.tuple(tuple(params)) w = xb.mkop( 'While', (input_tuple.op,), @@ -130,7 +130,7 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): name = 'fori_loop_ed_torch_func' computation = w.build(name) - ### gain final result with generated while xlacomputation + # gain final result with generated while xlacomputation result = torch_xla._XLAC._xla_user_computation('xla::_op_test_while', (total_inputs), computation) From 431ab6627bf51f7a98baa7af6974207115278a8d Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 22:50:56 +0000 Subject: [PATCH 319/323] format --- torch_xla/csrc/init_python_bindings.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index 85545ae267e..f02fc059609 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -914,10 +914,12 @@ class PyLoweringContext { // needed in xlacomputation. void BuildForiLoop(std::vector tensors, std::vector additional_inputs_list = {}) { - // hard-code modify cond xlacomputation input arguments with unusedarguments for xla::while requriement + // hard-code modify cond xlacomputation input arguments with unusedarguments + // for xla::while requriement if (GetNameString() == "condctx") { xla::XlaBuilder* local_builder = lowering_ctx.builder(); - int64_t parameter_idx = 2; // parameter_idx start from 2 after used upper and lower + int64_t parameter_idx = + 2; // parameter_idx start from 2 after used upper and lower for (auto& additional_input_tensor : additional_inputs_list) { XLATensorPtr xtensor = bridge::GetXlaTensor(additional_input_tensor); xla::Shape shape = xtensor->shape().get(); @@ -927,7 +929,8 @@ class PyLoweringContext { } } - // hard-code modify body xlacomputation input arguments with unusedarguments for xla::while requriement + // hard-code modify body xlacomputation input arguments with unusedarguments + // for xla::while requriement if (GetNameString() == "bodyctx") { xla::XlaBuilder* local_builder = lowering_ctx.builder(); // TODO(@manfei): treat hard code parameter_idx value From 6244d21b590373e02c5cb054092c9fd5806434bc Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 22:52:24 +0000 Subject: [PATCH 320/323] format --- torch_xla/csrc/init_python_bindings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index f02fc059609..e20e28fbb8f 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -919,7 +919,7 @@ class PyLoweringContext { if (GetNameString() == "condctx") { xla::XlaBuilder* local_builder = lowering_ctx.builder(); int64_t parameter_idx = - 2; // parameter_idx start from 2 after used upper and lower + 2; // parameter_idx start from 2 after used upper and lower for (auto& additional_input_tensor : additional_inputs_list) { XLATensorPtr xtensor = bridge::GetXlaTensor(additional_input_tensor); xla::Shape shape = xtensor->shape().get(); From 04ca72dceadd12e33a2abb216090efdee40a9c57 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 23:06:39 +0000 Subject: [PATCH 321/323] format --- ...while_loop_simple_add_dispatch_in_torch.py | 71 ++++++++++++------- torch_xla/experimental/fori_loop.py | 41 +++++++---- 2 files changed, 74 insertions(+), 38 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 73d55d3dc47..3b2b018cada 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -100,9 +100,11 @@ def cond_fn(upper, lower, one_value, x, input_value, output_value): def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) output_value = linear_0(input_value) - weight = linear_0.weight # not be used actually, initialized as placeholder xlacomputation requirement - bias = linear_0.bias # not be used actually, initialized as placeholder xlacomputation requirement - return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), bias.clone(), weight.clone(), output_value.clone() # , output_value_real + weight = linear_0.weight # not be used actually, initialized as placeholder xlacomputation requirement + bias = linear_0.bias # not be used actually, initialized as placeholder xlacomputation requirement + return upper.clone(), new_lower.clone(), one_value.clone(), torch.add( + one_value, x), input_value.clone(), bias.clone(), weight.clone( + ), output_value.clone() # , output_value_real upper = torch.tensor([1], dtype=torch.int32, device=device) lower = torch.tensor([0], dtype=torch.int32, device=device) @@ -111,7 +113,9 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): l_in_0 = torch.rand(10, device=xm.xla_device()) output_value = torch.zeros([20], dtype=torch.float32, device=device) - upper__, lower__, one_value__, torch_add_res__, input_value__, bias__, weight__, output_value_real__, = while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, l_in_0, output_value)) + upper__, lower__, one_value__, torch_add_res__, input_value__, bias__, weight__, output_value_real__, = while_loop( + cond_fn, body_fn, + (upper, lower, one_value, init_val, l_in_0, output_value)) expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) @@ -124,36 +128,48 @@ def test_while_loop_tpu_simple_linear_class(self): torch.set_grad_enabled(False) class SimpleWithLinear(torch.nn.Module): - def __init__(self): - super().__init__() - self.linear = torch.nn.Linear(10, 20).to(xm.xla_device()) - - def forward(self, upper, lower, one_value, x, input_value, output_value): - def cond_fn(upper, lower, one_value, x, input_value, output_value): - return lower[0] < upper[0] - - def body_fn(upper, lower, one_value, x, input_value, output_value): - new_lower = torch.add(one_value, lower) - output_value_real = self.linear(input_value) - weight = self.linear.weight # not be used actually, initialized as placeholder xlacomputation requirement - bias = self.linear.bias # not be used actually, initialized as placeholder xlacomputation requirement - return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), output_value_real, weight.clone(), bias.clone() - return while_loop(cond_fn, body_fn, (upper, lower, one_value, x, input_value, output_value)) + + def __init__(self): + super().__init__() + self.linear = torch.nn.Linear(10, 20).to(xm.xla_device()) + + def forward(self, upper, lower, one_value, x, input_value, output_value): + + def cond_fn(upper, lower, one_value, x, input_value, output_value): + return lower[0] < upper[0] + + def body_fn(upper, lower, one_value, x, input_value, output_value): + new_lower = torch.add(one_value, lower) + output_value_real = self.linear(input_value) + weight = self.linear.weight # not be used actually, initialized as placeholder xlacomputation requirement + bias = self.linear.bias # not be used actually, initialized as placeholder xlacomputation requirement + return upper.clone(), new_lower.clone(), one_value.clone(), torch.add( + one_value, x), input_value.clone( + ), output_value_real, weight.clone(), bias.clone() + + return while_loop( + cond_fn, body_fn, + (upper, lower, one_value, x, input_value, output_value)) simple_with_linear = SimpleWithLinear() upper = torch.tensor([52], dtype=torch.int32, device=device) lower = torch.tensor([0], dtype=torch.int32, device=device) one_value = torch.tensor([1], dtype=torch.int32, device=device) init_val = torch.tensor([1], dtype=torch.int32, device=device) - l_in_0 = torch.rand(10, device=xm.xla_device()) # input_value + l_in_0 = torch.rand(10, device=xm.xla_device()) # input_value output_value = torch.zeros([20], dtype=torch.float32, device=device) weight_0 = simple_with_linear.linear.weight bias_0 = simple_with_linear.linear.bias - aaa = {"simple_with_linear": (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, output_value))} + aaa = { + "simple_with_linear": + (simple_with_linear, (upper, lower, one_value, init_val, l_in_0, + output_value)) + } - upper__, lower__, one_value__, torch_add_res__, input_value__, output_value_real__, weight__, bias__ = simple_with_linear(upper, lower, one_value, init_val, l_in_0, output_value) + upper__, lower__, one_value__, torch_add_res__, input_value__, output_value_real__, weight__, bias__ = simple_with_linear( + upper, lower, one_value, init_val, l_in_0, output_value) # same weight/bias liear model linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) @@ -177,7 +193,8 @@ def test_fori_loop_tpu_addition(self): def body_fun(a, b): return torch.add(a, b) - upper_, new_lower_, one_value_, add_res_x_, res_ = fori_loop(upper, lower, body_fun, one_value, init_val) + upper_, new_lower_, one_value_, add_res_x_, res_ = fori_loop( + upper, lower, body_fun, one_value, init_val) expected = _fake_fori_loop(lower, upper, body_fun, init_val, one_value) self.assertEqual(expected, res_) @@ -191,15 +208,17 @@ def test_fori_loop_tpu_simple_linear(self): lower = torch.tensor([0], dtype=torch.int32, device=device) init_val = torch.tensor([1], dtype=torch.int32, device=device) l_in_0 = torch.randn(10, device=xm.xla_device()) - + linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) - upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_= fori_loop(upper, lower, linear_0, init_val, l_in_0) - + upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_= fori_loop( + upper, lower, linear_0, init_val, l_in_0) + expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) self.assertTrue(torch.all(torch.eq(expected, l_out_))) + if __name__ == '__main__': test = unittest.main() sys.exit(0 if test.result.wasSuccessful() else 1) \ No newline at end of file diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index a36649fcc3e..f07e9062f37 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -22,24 +22,36 @@ def fori_loop(upper, lower, body_fun, init_val, input_value): if (hasattr(body_fun, 'weight') or hasattr(body_fun, 'bias')): output_value = torch.zeros([20], dtype=torch.float32, device=device) + def cond_fn(upper, lower, one_value, x, input_value, output_value): return lower[0] < upper[0] + def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) output_value = body_fun(input_value) weight = body_fun.weight # not be used actually, initialized as placeholder xlacomputation requirement bias = body_fun.bias # not be used actually, initialized as placeholder xlacomputation requirement - return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), input_value.clone(), bias.clone(), weight.clone(), output_value.clone() - res = torch_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value, output_value)) + return upper.clone(), new_lower.clone(), one_value.clone(), torch.add( + one_value, x), input_value.clone(), bias.clone(), weight.clone( + ), output_value.clone() + + res = torch_while_loop( + cond_fn, body_fn, + (upper, lower, one_value, init_val, input_value, output_value)) else: output_value = torch.tensor([1], dtype=torch.int32, device=device) + def cond_fn(upper, lower, one_value, x, input_value): return lower[0] < upper[0] + def body_fn(upper, lower, one_value, x, input_value): new_lower = torch.add(one_value, lower) output_val = body_fun(one_value, input_value) - return upper.clone(), new_lower.clone(), one_value.clone(), torch.add(one_value, x), output_val.clone() - res = torch_while_loop(cond_fn, body_fn, (upper, lower, one_value, init_val, input_value)) + return upper.clone(), new_lower.clone(), one_value.clone(), torch.add( + one_value, x), output_val.clone() + + res = torch_while_loop(cond_fn, body_fn, + (upper, lower, one_value, init_val, input_value)) return res @@ -60,8 +72,9 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): for carried_input in carried_inputs: device = carried_input.device fake_carried_inputs.append( - torch.randint(10, carried_input.size(), - dtype=carried_input.dtype).to(device)) + torch.randint( + 10, carried_input.size(), + dtype=carried_input.dtype).to(device)) for additional_input in additional_inputs: device = additional_input.device fake_carried_inputs.append( @@ -74,11 +87,16 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): cond_ctx.set_name_string("condctx") # TODO(@manfei): treat hard-code cond xlacomputation change: currently switch output_value and weight position if additional_inputs(weight/bias) exists - additional_inputs_list_cond = list(fake_carried_inputs[2:]) # all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor + additional_inputs_list_cond = list( + fake_carried_inputs[2:] + ) # all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor if additional_inputs: - tmp_bias = additional_inputs_list_cond[-3] # not used, change order doesn't affect logic - del additional_inputs_list_cond[-3] # not used, change order doesn't affect logic - additional_inputs_list_cond.append(tmp_bias) # not used, change order doesn't affect logic + tmp_bias = additional_inputs_list_cond[ + -3] # not used, change order doesn't affect logic + del additional_inputs_list_cond[ + -3] # not used, change order doesn't affect logic + additional_inputs_list_cond.append( + tmp_bias) # not used, change order doesn't affect logic cond_ctx.buildforiloop([cond_result], additional_inputs_list_cond) cond_hlo = cond_ctx.hlo() @@ -132,7 +150,6 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): # gain final result with generated while xlacomputation result = torch_xla._XLAC._xla_user_computation('xla::_op_test_while', - (total_inputs), - computation) + (total_inputs), computation) return result \ No newline at end of file From 33fa1fbb30f3f305dbd2f1fe60d6225fc0abcf79 Mon Sep 17 00:00:00 2001 From: manfeibaigithub Date: Wed, 17 Apr 2024 23:12:49 +0000 Subject: [PATCH 322/323] format --- ...while_loop_simple_add_dispatch_in_torch.py | 18 ++++++++--------- torch_xla/experimental/fori_loop.py | 20 +++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py index 3b2b018cada..8a1f2bdb737 100644 --- a/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py +++ b/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py @@ -100,11 +100,11 @@ def cond_fn(upper, lower, one_value, x, input_value, output_value): def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) output_value = linear_0(input_value) - weight = linear_0.weight # not be used actually, initialized as placeholder xlacomputation requirement - bias = linear_0.bias # not be used actually, initialized as placeholder xlacomputation requirement + weight = linear_0.weight # not be used actually, initialized as placeholder xlacomputation requirement + bias = linear_0.bias # not be used actually, initialized as placeholder xlacomputation requirement return upper.clone(), new_lower.clone(), one_value.clone(), torch.add( one_value, x), input_value.clone(), bias.clone(), weight.clone( - ), output_value.clone() # , output_value_real + ), output_value.clone() upper = torch.tensor([1], dtype=torch.int32, device=device) lower = torch.tensor([0], dtype=torch.int32, device=device) @@ -141,8 +141,8 @@ def cond_fn(upper, lower, one_value, x, input_value, output_value): def body_fn(upper, lower, one_value, x, input_value, output_value): new_lower = torch.add(one_value, lower) output_value_real = self.linear(input_value) - weight = self.linear.weight # not be used actually, initialized as placeholder xlacomputation requirement - bias = self.linear.bias # not be used actually, initialized as placeholder xlacomputation requirement + weight = self.linear.weight # not be used actually, initialized as placeholder xlacomputation requirement + bias = self.linear.bias # not be used actually, initialized as placeholder xlacomputation requirement return upper.clone(), new_lower.clone(), one_value.clone(), torch.add( one_value, x), input_value.clone( ), output_value_real, weight.clone(), bias.clone() @@ -156,7 +156,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): lower = torch.tensor([0], dtype=torch.int32, device=device) one_value = torch.tensor([1], dtype=torch.int32, device=device) init_val = torch.tensor([1], dtype=torch.int32, device=device) - l_in_0 = torch.rand(10, device=xm.xla_device()) # input_value + l_in_0 = torch.rand(10, device=xm.xla_device()) output_value = torch.zeros([20], dtype=torch.float32, device=device) weight_0 = simple_with_linear.linear.weight @@ -171,7 +171,7 @@ def body_fn(upper, lower, one_value, x, input_value, output_value): upper__, lower__, one_value__, torch_add_res__, input_value__, output_value_real__, weight__, bias__ = simple_with_linear( upper, lower, one_value, init_val, l_in_0, output_value) - # same weight/bias liear model + # create same weight/bias liear model for compare linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) linear_0.weight.data = weight__ linear_0.bias.data = bias__ @@ -211,7 +211,7 @@ def test_fori_loop_tpu_simple_linear(self): linear_0 = torch.nn.Linear(10, 20).to(xm.xla_device()) - upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_= fori_loop( + upper_, lower_, one_value_, add_res_x_, l_in_i_plus_1_, weight_, bias_, l_out_ = fori_loop( upper, lower, linear_0, init_val, l_in_0) expected = _fake_fori_loop(lower, upper, linear_0, l_in_0) @@ -221,4 +221,4 @@ def test_fori_loop_tpu_simple_linear(self): if __name__ == '__main__': test = unittest.main() - sys.exit(0 if test.result.wasSuccessful() else 1) \ No newline at end of file + sys.exit(0 if test.result.wasSuccessful() else 1) diff --git a/torch_xla/experimental/fori_loop.py b/torch_xla/experimental/fori_loop.py index f07e9062f37..8ed3a783200 100644 --- a/torch_xla/experimental/fori_loop.py +++ b/torch_xla/experimental/fori_loop.py @@ -72,14 +72,14 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): for carried_input in carried_inputs: device = carried_input.device fake_carried_inputs.append( - torch.randint( - 10, carried_input.size(), - dtype=carried_input.dtype).to(device)) + torch.randint(10, carried_input.size(), + dtype=carried_input.dtype).to(device)) for additional_input in additional_inputs: device = additional_input.device fake_carried_inputs.append( - torch.randint(10, additional_input.size(), - dtype=additional_input.dtype).to(device)) + torch.randint( + 10, additional_input.size(), + dtype=additional_input.dtype).to(device)) # TODO(@manfei): specify which element is for which argument like a,b,c cond_result = cond_fn(*fake_carried_inputs) @@ -89,14 +89,14 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): # TODO(@manfei): treat hard-code cond xlacomputation change: currently switch output_value and weight position if additional_inputs(weight/bias) exists additional_inputs_list_cond = list( fake_carried_inputs[2:] - ) # all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor + ) # all missed arguments except upper/lower due to PyTorch/XLA trace from output tensor if additional_inputs: tmp_bias = additional_inputs_list_cond[ - -3] # not used, change order doesn't affect logic + -3] # not used, change order doesn't affect logic del additional_inputs_list_cond[ - -3] # not used, change order doesn't affect logic + -3] # not used, change order doesn't affect logic additional_inputs_list_cond.append( - tmp_bias) # not used, change order doesn't affect logic + tmp_bias) # not used, change order doesn't affect logic cond_ctx.buildforiloop([cond_result], additional_inputs_list_cond) cond_hlo = cond_ctx.hlo() @@ -152,4 +152,4 @@ def _xla_while_loop(cond_fn, body_fn, carried_inputs, additional_inputs=None): result = torch_xla._XLAC._xla_user_computation('xla::_op_test_while', (total_inputs), computation) - return result \ No newline at end of file + return result From 332bd402429301d3b0d32a895f226f362aafde3c Mon Sep 17 00:00:00 2001 From: Manfei <41607353+ManfeiBai@users.noreply.github.com> Date: Fri, 31 May 2024 14:48:00 -0700 Subject: [PATCH 323/323] [rebase] rebase fori_loop_simple_case_test (#7165) --- .circleci/README.md | 19 - .circleci/doc_push.sh | 63 - .circleci/docker/cloudbuild.yaml | 29 - .circleci/docker/install_llvm_clang.sh | 33 - .circleci/setup_ci_environment.sh | 2 +- .devcontainer/tpu-internal/devcontainer.json | 6 +- .github/CODEOWNERS | 2 +- .github/ci.md | 139 ++ .github/scripts/run_tests.sh | 108 + .../docker => .github/upstream}/Dockerfile | 1 + .../upstream}/install_conda.sh | 0 .../upstream}/install_valgrind.sh | 0 .github/workflows/_build.yml | 111 - .github/workflows/_build_plugin.yml | 4 +- .github/workflows/_build_torch_with_cuda.yml | 55 + .github/workflows/_build_torch_xla.yml | 22 +- .github/workflows/_docs.yml | 84 +- .github/workflows/_get_torch_commit.yml | 32 + .github/workflows/_test.yml | 151 +- .../workflows/_test_requiring_torch_cuda.yml | 110 + .github/workflows/build_and_test.yml | 61 +- .github/workflows/build_upstream_image.yml | 40 + .github/workflows/lintercheck.yml | 2 +- .github/workflows/torch_xla2.yml | 6 +- .kokoro/Dockerfile | 2 +- .kokoro/presubmit.cfg | 10 +- BUILD | 35 + CONTRIBUTING.md | 57 +- OP_LOWERING_GUIDE.md | 2 +- README.md | 84 +- TROUBLESHOOTING.md | 97 +- WORKSPACE | 57 +- benchmarks/benchmark_experiment.py | 19 +- benchmarks/benchmark_model.py | 31 +- benchmarks/experiment_runner.py | 29 +- benchmarks/requirements.txt | 3 + benchmarks/result_analyzer.py | 5 + benchmarks/run_benchmark.sh | 2 +- benchmarks/torchbench_model.py | 47 +- benchmarks/util.py | 13 +- build_util.py | 4 - codegen/BUILD | 4 + codegen/xla_native_functions.yaml | 1 + configuration.yaml | 21 - contrib/vscode/settings.json | 18 +- docs/README.md | 14 +- docs/assets/ci_test_dependency.png | Bin 0 -> 44721 bytes docs/assets/ci_test_dependency_gpu.png | Bin 0 -> 50628 bytes docs/fori_loop.md | 114 + docs/fsdpv2.md | 20 +- docs/gpu.md | 7 +- docs/pallas.md | 57 + docs/requirements.txt | 4 +- docs/spmd.md | 48 +- examples/README.md | 17 + examples/data_parallel/README.md | 2 + examples/data_parallel/train_resnet_ddp.py | 30 + .../train_resnet_spmd_data_parallel.py | 49 + .../data_parallel/train_resnet_xla_ddp.py | 25 + examples/debug/train_resnet_benchmark.py | 49 + examples/debug/train_resnet_profile.py | 30 + examples/decoder_only_model.py | 227 ++ .../train_decoder_only_flash_attention.py | 33 + ...in_decoder_only_flash_attention_fsdp_v2.py | 36 + examples/fsdp/README.md | 2 + examples/fsdp/train_decoder_only_fsdp_v2.py | 63 + examples/fsdp/train_resnet_fsdp_auto_wrap.py | 56 + examples/train_decoder_only_base.py | 73 + examples/train_resnet_amp.py | 35 + examples/train_resnet_base.py | 71 + experimental/torch_xla2/README.md | 78 +- experimental/torch_xla2/dev-requirements.txt | 12 +- experimental/torch_xla2/docs/dispatch.png | Bin 0 -> 150015 bytes .../torch_xla2/docs/fixing_op_info_test.md | 211 ++ experimental/torch_xla2/docs/how_it_works.md | 134 ++ experimental/torch_xla2/docs/ops_registry.md | 40 + .../torch_xla2/examples/basic_training.py | 31 +- .../torch_xla2/examples/basic_training_jax.py | 12 +- .../torch_xla2/examples/eager_mode.py | 13 +- .../torch_xla2/examples/lightning_training.py | 77 + experimental/torch_xla2/pyproject.toml | 28 +- experimental/torch_xla2/test-requirements.txt | 5 + .../torch_xla2/test/gemma/test_gemma.py | 2 +- .../torch_xla2/test/llama/test_llama.py | 5 +- experimental/torch_xla2/test/moe/__init__.py | 0 experimental/torch_xla2/test/moe/model.py | 260 +++ experimental/torch_xla2/test/moe/moe_test.py | 75 + experimental/torch_xla2/test/test_context.py | 8 +- .../torch_xla2/test/test_core_aten_ops.py | 128 +- experimental/torch_xla2/test/test_exports.py | 100 +- experimental/torch_xla2/test/test_extra.py | 64 - .../torch_xla2/test/test_functions.py | 6 +- .../torch_xla2/test/test_mutations.py | 61 +- experimental/torch_xla2/test/test_ops.py | 28 +- .../torch_xla2/test/test_symbolic_shapes.py | 92 + .../test/test_unbounded_dynamism.py | 662 ++++++ experimental/torch_xla2/test_requirements.txt | 5 - .../torch_xla2/torch_xla2/__init__.py | 29 +- experimental/torch_xla2/torch_xla2/_ops.py | 1745 -------------- .../torch_xla2/torch_xla2/decompositions.py | 19 +- .../torch_xla2/torch_xla2/environment.py | 24 - experimental/torch_xla2/torch_xla2/export.py | 273 ++- experimental/torch_xla2/torch_xla2/extra.py | 62 - .../torch_xla2/torch_xla2/functions.py | 109 - experimental/torch_xla2/torch_xla2/interop.py | 69 + .../torch_xla2/torch_xla2/ops/__init__.py | 9 + .../torch_xla2/torch_xla2/ops/jaten.py | 1998 ++++++++++++++++- .../torch_xla2/torch_xla2/ops/jtorch.py | 88 + .../torch_xla2/torch_xla2/ops/op_base.py | 57 +- .../torch_xla2/torch_xla2/ops/ops_registry.py | 47 + .../torch_xla2/torch_xla2/ops_registry.py | 74 - experimental/torch_xla2/torch_xla2/tensor.py | 328 ++- experimental/torch_xla2/torch_xla2/types.py | 12 + infra/ansible/config/env.yaml | 10 +- infra/ansible/config/vars.yaml | 8 + .../ansible/roles/build_srcs/tasks/main.yaml | 40 + .../artifacts.auto.tfvars | 50 +- infra/tpu-pytorch-releases/dev_images.tf | 2 - .../cuda/torch_xla_cuda_plugin/__init__.py | 3 + requirements.in | 9 + requirements_lock_3_10.txt | 153 ++ requirements_lock_3_11.txt | 153 ++ requirements_lock_3_8.txt | 153 ++ requirements_lock_3_9.txt | 153 ++ scripts/apply_patches.sh | 2 +- setup.py | 8 +- test/benchmarks/run_tests.sh | 14 +- test/benchmarks/test_benchmark_experiment.py | 5 +- test/benchmarks/test_experiment_runner.py | 48 +- test/cpp/run_tests.sh | 2 +- test/cpp/test_aten_xla_tensor_4.cpp | 13 + test/cpp/test_aten_xla_tensor_5.cpp | 21 + test/debug_tool/extract_debug_helper.py | 30 + test/debug_tool/test_mp_pt_xla_debug.py | 4 +- test/debug_tool/test_pt_xla_debug.py | 153 +- test/dynamo/test_dynamo.py | 15 +- test/pjrt/test_runtime_tpu.py | 16 +- test/pytorch_test_base.py | 1 + test/run_tests.sh | 14 +- test/spmd/test_dynamo_spmd.py | 2 + test/spmd/test_fsdp_v2.py | 76 +- test/spmd/test_xla_distributed_checkpoint.py | 95 +- ...test_mark_pattern.py => test_composite.py} | 0 test/stablehlo/test_export_fx_passes.py | 4 +- test/stablehlo/test_exports.py | 2 +- test/stablehlo/test_mlir_debuginfo.py | 30 +- test/stablehlo/test_pt2e_qdq.py | 6 +- test/stablehlo/test_stablehlo_custom_call.py | 121 + test/stablehlo/test_unbounded_dynamism.py | 54 +- test/test_devices.py | 57 +- test/test_gmm.py | 460 ++++ test/test_input_output_aliases.py | 44 + test/test_metrics.py | 54 + test/test_operations.py | 344 +++ test/test_ops.py | 4 +- test/test_pallas.py | 415 +++- test/test_pallas_spmd.py | 110 + test/tpu/Dockerfile | 4 +- test/tpu/run_tests.sh | 9 +- torch_patches/README.md | 32 - torch_xla/__init__.py | 27 +- torch_xla/core/dynamo_bridge.py | 10 +- torch_xla/core/xla_model.py | 16 +- torch_xla/csrc/BUILD | 2 + torch_xla/csrc/aten_cpu_fallback.cpp | 12 + torch_xla/csrc/aten_cpu_fallback.h | 4 +- torch_xla/csrc/aten_xla_type.cpp | 92 +- torch_xla/csrc/debug_util.cpp | 90 +- torch_xla/csrc/debug_util.h | 4 + torch_xla/csrc/dl_convertor.cpp | 345 +++ torch_xla/csrc/dl_convertor.h | 14 + torch_xla/csrc/dtype.cpp | 14 + torch_xla/csrc/init_python_bindings.cpp | 122 +- torch_xla/csrc/ops/custom_call.cpp | 70 + torch_xla/csrc/ops/custom_call.h | 29 + torch_xla/csrc/ops/embedding_bag.cpp | 192 ++ torch_xla/csrc/ops/embedding_bag.h | 31 + torch_xla/csrc/ops/index_ops.cpp | 47 + torch_xla/csrc/ops/xla_ops.cpp | 1 + torch_xla/csrc/ops/xla_ops.h | 1 + torch_xla/csrc/reduction.cpp | 4 +- torch_xla/csrc/runtime/BUILD | 2 +- torch_xla/csrc/runtime/cache.h | 1 + torch_xla/csrc/runtime/computation_client.h | 25 +- .../csrc/runtime/ifrt_computation_client.cc | 53 +- .../csrc/runtime/ifrt_computation_client.h | 24 +- .../csrc/runtime/pjrt_computation_client.cc | 75 +- .../csrc/runtime/pjrt_computation_client.h | 49 +- torch_xla/csrc/runtime/pjrt_registry.cc | 21 +- .../runtime/stablehlo_composite_helper.cc | 2 +- torch_xla/csrc/runtime/xla_coordinator.h | 2 +- torch_xla/csrc/tensor_methods.cpp | 62 +- torch_xla/csrc/tensor_methods.h | 11 + torch_xla/csrc/tensor_util.cpp | 21 + torch_xla/csrc/tensor_util.h | 3 + torch_xla/csrc/unwrap_data.h | 3 + torch_xla/csrc/xla_graph_executor.cpp | 2 + torch_xla/csrc/xla_manual_registration.cpp | 14 + torch_xla/debug/metrics.py | 5 + torch_xla/distributed/spmd/__init__.py | 2 + torch_xla/experimental/custom_kernel.py | 700 +++++- .../distributed_checkpoint/__init__.py | 2 + .../distributed_checkpoint/manager.py | 5 +- .../distributed_checkpoint/util.py | 44 + torch_xla/experimental/plugins.py | 4 +- .../spmd_fully_sharded_data_parallel.py | 34 +- .../experimental/stablehlo_custom_call.py | 31 + torch_xla/experimental/xla_mlir_debuginfo.py | 3 +- torch_xla/stablehlo.py | 69 +- torch_xla/torch_xla.py | 19 + torch_xla/utils/dlpack.py | 36 + 211 files changed, 11677 insertions(+), 3540 deletions(-) delete mode 100644 .circleci/README.md delete mode 100755 .circleci/doc_push.sh delete mode 100644 .circleci/docker/cloudbuild.yaml delete mode 100644 .circleci/docker/install_llvm_clang.sh create mode 100644 .github/ci.md create mode 100755 .github/scripts/run_tests.sh rename {.circleci/docker => .github/upstream}/Dockerfile (98%) rename {.circleci/docker => .github/upstream}/install_conda.sh (100%) rename {.circleci/docker => .github/upstream}/install_valgrind.sh (100%) delete mode 100644 .github/workflows/_build.yml create mode 100644 .github/workflows/_build_torch_with_cuda.yml create mode 100644 .github/workflows/_get_torch_commit.yml create mode 100644 .github/workflows/_test_requiring_torch_cuda.yml create mode 100644 .github/workflows/build_upstream_image.yml create mode 100644 benchmarks/requirements.txt create mode 100644 docs/assets/ci_test_dependency.png create mode 100644 docs/assets/ci_test_dependency_gpu.png create mode 100644 docs/fori_loop.md create mode 100644 docs/pallas.md create mode 100644 examples/README.md create mode 100644 examples/data_parallel/README.md create mode 100644 examples/data_parallel/train_resnet_ddp.py create mode 100644 examples/data_parallel/train_resnet_spmd_data_parallel.py create mode 100644 examples/data_parallel/train_resnet_xla_ddp.py create mode 100644 examples/debug/train_resnet_benchmark.py create mode 100644 examples/debug/train_resnet_profile.py create mode 100644 examples/decoder_only_model.py create mode 100644 examples/flash_attention/train_decoder_only_flash_attention.py create mode 100644 examples/flash_attention/train_decoder_only_flash_attention_fsdp_v2.py create mode 100644 examples/fsdp/README.md create mode 100644 examples/fsdp/train_decoder_only_fsdp_v2.py create mode 100644 examples/fsdp/train_resnet_fsdp_auto_wrap.py create mode 100644 examples/train_decoder_only_base.py create mode 100644 examples/train_resnet_amp.py create mode 100644 examples/train_resnet_base.py create mode 100644 experimental/torch_xla2/docs/dispatch.png create mode 100644 experimental/torch_xla2/docs/fixing_op_info_test.md create mode 100644 experimental/torch_xla2/docs/how_it_works.md create mode 100644 experimental/torch_xla2/docs/ops_registry.md create mode 100644 experimental/torch_xla2/examples/lightning_training.py create mode 100644 experimental/torch_xla2/test-requirements.txt create mode 100644 experimental/torch_xla2/test/moe/__init__.py create mode 100644 experimental/torch_xla2/test/moe/model.py create mode 100644 experimental/torch_xla2/test/moe/moe_test.py delete mode 100644 experimental/torch_xla2/test/test_extra.py create mode 100644 experimental/torch_xla2/test/test_symbolic_shapes.py create mode 100644 experimental/torch_xla2/test/test_unbounded_dynamism.py delete mode 100644 experimental/torch_xla2/test_requirements.txt delete mode 100644 experimental/torch_xla2/torch_xla2/_ops.py delete mode 100644 experimental/torch_xla2/torch_xla2/extra.py delete mode 100644 experimental/torch_xla2/torch_xla2/functions.py create mode 100644 experimental/torch_xla2/torch_xla2/interop.py create mode 100644 experimental/torch_xla2/torch_xla2/ops/ops_registry.py delete mode 100644 experimental/torch_xla2/torch_xla2/ops_registry.py create mode 100644 experimental/torch_xla2/torch_xla2/types.py create mode 100644 requirements.in create mode 100644 requirements_lock_3_10.txt create mode 100644 requirements_lock_3_11.txt create mode 100644 requirements_lock_3_8.txt create mode 100644 requirements_lock_3_9.txt rename test/stablehlo/{test_mark_pattern.py => test_composite.py} (100%) create mode 100644 test/stablehlo/test_stablehlo_custom_call.py create mode 100644 test/test_gmm.py create mode 100644 test/test_pallas_spmd.py delete mode 100644 torch_patches/README.md create mode 100644 torch_xla/csrc/dl_convertor.cpp create mode 100644 torch_xla/csrc/dl_convertor.h create mode 100644 torch_xla/csrc/ops/custom_call.cpp create mode 100644 torch_xla/csrc/ops/custom_call.h create mode 100644 torch_xla/csrc/ops/embedding_bag.cpp create mode 100644 torch_xla/csrc/ops/embedding_bag.h create mode 100644 torch_xla/experimental/distributed_checkpoint/util.py create mode 100644 torch_xla/experimental/stablehlo_custom_call.py create mode 100644 torch_xla/utils/dlpack.py diff --git a/.circleci/README.md b/.circleci/README.md deleted file mode 100644 index d01e6138317..00000000000 --- a/.circleci/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# CircleCI Overview -PyTorch and PyTorch/XLA use CircleCI to lint, build, and test each PR that is submitted. All CircleCI tests should succeed before the PR is merged into master. PyTorch CircleCI pins PyTorch/XLA to a specific commit. On the other hand, PyTorch/XLA CircleCI pulls PyTorch from master unless a pin is manually provided. This README will go through the reasons of these pins, how to pin a PyTorch/XLA PR to an upstream PyTorch PR, and how to coordinate a merge for breaking PyTorch changes. - -## Why does PyTorch CircleCI pin PyTorch/XLA? -As mentioned above, [PyTorch CircleCI pins PyTorch/XLA](https://github.com/pytorch/pytorch/blob/master/.jenkins/pytorch/common_utils.sh#L119) to a "known good" commit to prevent accidental changes from PyTorch/XLA to break PyTorch CircleCI without warning. PyTorch has hundreds of commits each week, and this pin ensures that PyTorch/XLA as a downstream package does not cause failures in PyTorch CircleCI. - -## Why does PyTorch/XLA CircleCI pull from PyTorch master? -[PyTorch/XLA CircleCI pulls PyTorch from master](https://github.com/pytorch/xla/blob/f3415929683880192b63b285921c72439af55bf0/.circleci/common.sh#L15) unless a PyTorch pin is manually provided. PyTorch/XLA is a downstream package to PyTorch, and pulling from master ensures that PyTorch/XLA will stay up-to-date and works with the latest PyTorch changes. - -## Pinning PyTorch PR in PyTorch/XLA PR -Sometimes a PyTorch/XLA PR needs to be pinned to a specific PyTorch PR to test new featurues, fix breaking changes, etc. Since PyTorch/XLA CircleCI pulls from PyTorch master by default, we need to manually provided a PyTorch pin. In a PyTorch/XLA PR, PyTorch an be manually pinned by creating a `.torch_pin` under `/torch_patches`. The `.torch_pin` should have the corresponding PyTorch PR number prefixed by "#". Take a look at [example here](https://github.com/pytorch/xla/pull/3792/commits/40f41fb98b0f2386d287eeac0bae86e873d4a9d8). Before the PyTorch/XLA PR gets merged, the `.torch_pin` must be deleted. - -## Coodinating merges for breaking PyTorch PRs -When PyTorch PR introduces a breaking change, its PyTorch/XLA CircleCI tests will fail. Steps for fixing and merging such breaking PyTorch change is as following: -1. Create a PyTorch/XLA PR to fix this issue with `.torch_pin` and rebase with master to ensure the PR is up-to-date with the latest commit on PyTorch/XLA. Once this PR is created, it'll create a commit hash that will be used in step 2. If you have multiple commits in the PR, use the last one's hash. **Important note: When you rebase this PR, it'll create a new commit hash and make the old hash obsolete. Be cautious about rebasing, and if you rebase, make sure you inform the PyTorch PR's author.** -2. Rebase (or ask the PR owner to rebase) the PyTorch PR with master. Update the PyTorch PR to pin the PyTorch/XLA to the commit hash created in step 1 by updating `pytorch/.github/ci_commit_pins/xla.txt`. -3. Once CircleCI tests are green on both ends, merge PyTorch PR. -4. Remove the `.torch_pin` in PyTorch/XLA PR and merge. To be noted, `git commit --amend` should be avoided in this step as PyTorch CI will keep using the commit hash created in step 1 until other PRs update that manually or the nightly buildbot updates that automatically. -5. Finally, don't delete your branch until 2 days later. See step 4 for explanations. diff --git a/.circleci/doc_push.sh b/.circleci/doc_push.sh deleted file mode 100755 index 72b4a44f6e7..00000000000 --- a/.circleci/doc_push.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/bin/bash - -set -ex - -cd /tmp/pytorch/xla - -source ./xla_env -source .circleci/common.sh - -echo "Building docs" -pushd docs -./docs_build.sh -popd - -echo "Pushing to public" -git config --global user.email "pytorchxla@gmail.com" -git config --global user.name "torchxlabot2" -GH_PAGES_BRANCH=gh-pages -GH_PAGES_DIR=gh-pages-tmp -CURRENT_COMMIT=`git rev-parse HEAD` -BRANCH_NAME=`git rev-parse --abbrev-ref HEAD` -if [[ "$BRANCH_NAME" == release/* ]]; then - SUBDIR_NAME=$BRANCH_NAME -else - SUBDIR_NAME="master" -fi -pushd /tmp -git clone --quiet -b "$GH_PAGES_BRANCH" https://github.com/pytorch/xla.git "$GH_PAGES_DIR" -pushd $GH_PAGES_DIR -rm -rf $SUBDIR_NAME -mkdir -p $SUBDIR_NAME -cp -fR /tmp/pytorch/xla/docs/build/* $SUBDIR_NAME -git_status=$(git status --porcelain) -if [[ $git_status ]]; then - echo "Doc is updated... Pushing to public" - echo "${git_status}" - sudo apt-get -qq update - export DEBIAN_FRONTEND=noninteractive - sudo ln -snf /usr/share/zoneinfo/Etc/UTC /etc/localtime - sudo sh -c "echo Etc/UTC > /etc/timezone" - sudo apt-get -qq -y install tzdata - sudo apt-get -qq install expect - git add . - - COMMIT_MSG="Update doc from commit $CURRENT_COMMIT" - git commit -m "$COMMIT_MSG" - set +x -/usr/bin/expect < /dev/null 2>&1 ; then - VER="buster" - else - VER=$(lsb_release -c -s) - fi - echo "$VER" -} - -function install_llvm_clang() { - local DEBVER=$(debian_version) - if ! apt-get install -y -s clang-8 > /dev/null 2>&1 ; then - maybe_append "deb http://apt.llvm.org/${DEBVER}/ llvm-toolchain-${DEBVER}-8 main" /etc/apt/sources.list - maybe_append "deb-src http://apt.llvm.org/${DEBVER}/ llvm-toolchain-${DEBVER}-8 main" /etc/apt/sources.list - wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add - - sudo apt-get update - fi - # Build config also sets CC=clang-8, CXX=clang++-8 - sudo apt-get install -y clang-8 clang++-8 - sudo apt-get install -y llvm-8 llvm-8-dev llvm-8-tools - sudo ln -s /usr/bin/clang-8 /usr/bin/clang - sudo ln -s /usr/bin/clang++-8 /usr/bin/clang++ - export CC=clang-8 CXX=clang++-8 -} - -install_llvm_clang diff --git a/.circleci/setup_ci_environment.sh b/.circleci/setup_ci_environment.sh index eba2c373b8a..87a61524e7e 100755 --- a/.circleci/setup_ci_environment.sh +++ b/.circleci/setup_ci_environment.sh @@ -58,7 +58,7 @@ sudo apt-get -y remove linux-image-generic linux-headers-generic linux-generic d # How to figure out what the correct versions of these packages are? # My preferred method is to start a Docker instance of the correct # Ubuntu version (e.g., docker run -it ubuntu:16.04) and then ask -# apt what the packages you need are. Note that the CircleCI image +# apt what the packages you need are. Note that the CI image # comes with Docker. # # Using 'retry' here as belt-and-suspenders even though we are diff --git a/.devcontainer/tpu-internal/devcontainer.json b/.devcontainer/tpu-internal/devcontainer.json index 4358bd5612f..a0684c8f90f 100644 --- a/.devcontainer/tpu-internal/devcontainer.json +++ b/.devcontainer/tpu-internal/devcontainer.json @@ -17,14 +17,14 @@ "llvm-vs-code-extensions.vscode-clangd", "ms-vscode.cpptools-themes", "BazelBuild.vscode-bazel", - "DevonDCarew.bazel-code", "StackBuild.bazel-stack-vscode", "StackBuild.bazel-stack-vscode-cc", "xaver.clang-format", "ryanluker.vscode-coverage-gutters", "ms-azuretools.vscode-docker", - "ms-python.python" + "ms-python.python", + "eeyore.yapf" ] } } -} \ No newline at end of file +} diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 87072a65bce..bfff4ef8422 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -/infra @will-cromar @JackCaoG @yeounoh @mateuszlewko @stgpetrovic +/infra @will-cromar @JackCaoG @lsy323 diff --git a/.github/ci.md b/.github/ci.md new file mode 100644 index 00000000000..4f39ad4bd40 --- /dev/null +++ b/.github/ci.md @@ -0,0 +1,139 @@ +# CI Overview + +PyTorch and PyTorch/XLA use CI to lint, build, and test each PR that is submitted. All CI tests should succeed before the PR is merged into master. PyTorch CI pins PyTorch/XLA to a specific commit. On the other hand, PyTorch/XLA CI pulls PyTorch from master unless a pin is manually provided. This README will go through the reasons of these pins, how to pin a PyTorch/XLA PR to an upstream PyTorch PR, and how to coordinate a merge for breaking PyTorch changes. + +## Usage + +### Pinning PyTorch PR in PyTorch/XLA PR + +Sometimes a PyTorch/XLA PR needs to be pinned to a specific PyTorch PR to test new featurues, fix breaking changes, etc. Since PyTorch/XLA CI pulls from PyTorch master by default, we need to manually provided a PyTorch pin. In a PyTorch/XLA PR, PyTorch an be manually pinned by creating a `.torch_pin` file at the root of the repository. The `.torch_pin` should have the corresponding PyTorch PR number prefixed by "#". Take a look at [example here](https://github.com/pytorch/xla/pull/3792/commits/40f41fb98b0f2386d287eeac0bae86e873d4a9d8). Before the PyTorch/XLA PR gets merged, the `.torch_pin` must be deleted. + +### Coodinating merges for breaking PyTorch PRs + +When PyTorch PR introduces a breaking change, its PyTorch/XLA CI tests will fail. Steps for fixing and merging such breaking PyTorch change is as following: +1. Create a PyTorch/XLA PR to fix this issue with `.torch_pin` and rebase with master to ensure the PR is up-to-date with the latest commit on PyTorch/XLA. Once this PR is created, it'll create a commit hash that will be used in step 2. If you have multiple commits in the PR, use the last one's hash. **Important note: When you rebase this PR, it'll create a new commit hash and make the old hash obsolete. Be cautious about rebasing, and if you rebase, make sure you inform the PyTorch PR's author.** +2. Rebase (or ask the PR owner to rebase) the PyTorch PR with master. Update the PyTorch PR to pin the PyTorch/XLA to the commit hash created in step 1 by updating `pytorch/.github/ci_commit_pins/xla.txt`. +3. Once CI tests are green on both ends, merge PyTorch PR. +4. Remove the `.torch_pin` in PyTorch/XLA PR and merge. To be noted, `git commit --amend` should be avoided in this step as PyTorch CI will keep using the commit hash created in step 1 until other PRs update that manually or the nightly buildbot updates that automatically. +5. Finally, don't delete your branch until 2 days later. See step 4 for explanations. + +### Running TPU tests on PRs + +By default, we only run TPU tests on a postsubmit basis to save capacity. If you are making a sensitive change, add the `tpuci` label to your PR. Note that the label must be present before `build_and_test.yml` triggers. If it has already run, make a new commit or rebase to trigger the CI again. + +## CI Environment + +Before the CI in this repository runs, we build a the base dev image. These are the same images we recommend in our VSCode `.devcontainer` setup and nightly build to ensure consistency between environments. We produce variants with and without CUDA, configured in `infra/ansible` (build config) and `infra/tpu-pytorch-releases/dev_images.tf` (build triggers). + +The CI runs in two environments: + +1. Organization self-hosted runners for CPU and GPU: used for amost every step of the CI. These runners are managed by PyTorch and have access to the shared ECR repository. +2. TPU self-hosted runners: these are managed by us and are only availabe in the `pytorch/xla` repository. See the [_TPU CI_](#tpu-ci) section for more details. + +## Build and test (`build_and_test.yml`) + +We have two build paths for each CI run: + +- `torch_xla`: we build the main package to support for both TPU and GPU[^1], along with a CPU bild of `torch` from HEAD. This build step exports the `torch-xla-wheels` artifact for downstream use in tests. + - Some CI tests also require `torchvision`. To reduce flakiness, we compile `torchvision` from [`torch`'s CI pin](https://github.com/pytorch/pytorch/blob/main/.github/ci_commit_pins/vision.txt). + - C++ tests are piggybacked onto the same build and uploaded in the `cpp-test-bin` artifact. +- `torch_xla_cuda_plugin`: the XLA CUDA runtime can be built independently of either `torch` or `torch_xla` -- it depends only on our pinned OpenXLA. Thus, this build should be almost entirely cached, unless your PR changes the XLA pin or adds a patch. + +Both the main package build and plugin build are configured with ansible at `infra/ansible`, although they run in separate stages (`stage=build_srcs` vs `stage=build_plugin`). This is the same configuration we use for our nightly and release builds. + +The CPU and GPU test configs are defined in the same file, `_test.yml`. Since some of the tests come from the upstream PyTorch repository, we check out PyTorch at the same git rev as the `build` step (taken from `torch_xla.version.__torch_gitrev__`). The tests are split up into multiple groups that run in parallel; the `matrix` section of `_test.yml` corresponds to in `.github/scripts/run_tests.sh`. + +CPU tests run immediately after then `torch_xla` build completes. This will likely be the first test feedback on your commit. GPU tests will launch when both the `torch_xla` and `torch_xla_cuda_plugin` complete. GPU compilation is much slower due to the number of possible optimizations, and the GPU chips themselves are quite outdated, so these tests will take longer to run than the CPU tests. + +![CPU tests launch when `torch_xla` is complete](../docs/assets/ci_test_dependency.png) + +![GPU tests also depend on CUDA plugin](../docs/assets/ci_test_dependency_gpu.png) + +For the C++ test groups in either case, the test binaries are pre-built during the build phase and packaged in `cpp-test-bin`. This will only be downloaded if necessary. + +[^1]: Note: both GPU and TPU support require their respective plugins to be installed. This package will _not_ work on either out of the box. + +### TPU CI + +The TPU CI runs only a subset of our tests due to capacity constraints, defined in `_tpu_ci.yml` `test/tpu/run_tests.sh`. The runners themselves are containers in GKE managed by [ARC](https://github.com/actions/actions-runner-controller). The container image is also based on our dev images, with some changes for ARC compatibility. The Dockerfile for this image lives in `test/tpu/Dockerfile`. + +The actual ARC cluster is defined in Terraform at `infra/tpu-pytorch/tpu_ci.yml`. + +### Reproducing test failures + +The best way to reproduce failures in the CI is to use the recommended container configuration in `.devcontainer`. These use identical images/environments as the CI. + +If you cannot reproduce the failure or need to inspect the package built in a CI run, you can download the `torch-xla-wheels` artifact for that run, [either locally in your web browser or remotely with the `gh` CLI tool](https://docs.github.com/en/actions/managing-workflow-runs/downloading-workflow-artifacts). C++ tests in particular can be quite slow to build. If you need to re-run these yourself, download the `cpp-test-bin` artifact. You'll have to set some additional environment variables for these to load the correct `torch` and plugin binaries, so you should copy the variables we set in `_test.yml` before runnign them. + +### Generating docs + +Our API documentation is generated automatically from the `torch_xla` package with `sphinx`. The workflow to update our static site is defined in `_docs.yml`. The workflow is roughly the following: + +- Changes to `master` update the docs at `/master` on the `gh-pages` branch. +- Changes to a release brance update the docs under `/releases/rX.Y`. + +By default, we redirect to the latest stable version, defined in [`index.md`](https://github.com/pytorch/xla/blob/gh-pages/index.md). + +We build preview docs for every CI, but only push to `gh-pages` for `master` and release branches. To preview doc changes, download the `github-pages` artifact locally and open `index.html` in your browser. + +Changes to `gh-pages` are pushed by our bot account, `torchxlabot2`. + +### FAQ and Troubleshooting + +#### Why does PyTorch CI pin PyTorch/XLA? + +As mentioned above, [PyTorch CI pins PyTorch/XLA](https://github.com/pytorch/pytorch/blob/master/.jenkins/pytorch/common_utils.sh#L119) to a "known good" commit to prevent accidental changes from PyTorch/XLA to break PyTorch CI without warning. PyTorch has hundreds of commits each week, and this pin ensures that PyTorch/XLA as a downstream package does not cause failures in PyTorch CI. + +#### Why does PyTorch/XLA CI pull from PyTorch master? + +[PyTorch/XLA CI pulls PyTorch from master](https://github.com/pytorch/xla/blob/f3415929683880192b63b285921c72439af55bf0/.circleci/common.sh#L15) unless a PyTorch pin is manually provided. PyTorch/XLA is a downstream package to PyTorch, and pulling from master ensures that PyTorch/XLA will stay up-to-date and works with the latest PyTorch changes. + +#### TPU CI is broken + +If the TPU CI won't run, try to debug using the following steps: + +On your cloudtop: + +``` +gcloud config set project tpu-pytorch +gcloud container clusters get-credentials tpu-ci --location=us-central2 +``` + +Check to see if the runner pod is working: + +``` +kubectl get pods -n arc-runners +``` + +If it is working, check the logs: + +``` +kubectl logs -n arc-runners +``` + +If there is no runner pod available, you can check the controller logs. First find the controller pod name: + +``` +kubectl get pods -n arc-systems +``` + +The name should match actions-runner-controller-gha-rs-controller-*. You can then check the logs by running the following: + +``` +kubectl logs -n arc-systems +``` + +If the ephemeralrunner spawning the runner pods is stuck in an error, you can attempt the following to restart the ephemeralrunner and check the logs: + +``` +kubectl delete ephemeralrunners --all -A +kubectl logs -f -n arc-runners $(kubectl get pods -n arc-runners -l 'actions.github.com/scale-set-name=v4-runner-set' -o jsonpath='{.items[0].metadata.name}') +``` + +## Upstream CI image (`build_upstream_image.yml`) + +We use different build tools than the upstream `torch` repository due to our dependency on XLA, namely `bazel`. To ensure the upstream CI has the correct tools to run XLA, we layer some additional tools and changes on top of our dev image and push the result to upstream's ECR instance. The upstream CI image is defined in `.github/upstream`. + +If you are making a breaking change to the image, bump the image version tag in `build_upstream_image.yml` first and then send a PR to `pytorch/pytorch` to update the tag on their side ([example](https://github.com/pytorch/pytorch/pull/125319)). + +Note: the upstream CI still relies on some legacy scripts in `.circleci` rather than our Ansible config. Don't update these without checking if they break the upstream CI first! TODO: finally delete these. diff --git a/.github/scripts/run_tests.sh b/.github/scripts/run_tests.sh new file mode 100755 index 00000000000..ae59a51490d --- /dev/null +++ b/.github/scripts/run_tests.sh @@ -0,0 +1,108 @@ +set -ex + +function run_torch_xla_python_tests() { + PYTORCH_DIR=$1 + XLA_DIR=$2 + USE_COVERAGE="${3:-0}" + + pushd $XLA_DIR + echo "Running Python Tests" + if [ "$USE_COVERAGE" != "0" ]; then + pip install coverage==6.5.0 --upgrade + pip install coverage-lcov + pip install toml + ./test/run_tests.sh + coverage combine + mkdir lcov && cp .coverage lcov/ + coverage-lcov --data_file_path lcov/.coverage + coverage html + cp lcov.info htmlcov/ + mv htmlcov ~/ + chmod -R 755 ~/htmlcov + else + ./test/run_tests.sh + fi + popd +} + +function run_torch_xla_cpp_tests() { + PYTORCH_DIR=$1 + XLA_DIR=$2 + USE_COVERAGE="${3:-0}" + + TORCH_DIR=$(python -c "import pkgutil; import os; print(os.path.dirname(pkgutil.get_loader('torch').get_filename()))") + export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${TORCH_DIR}/lib + if [ -x "$(command -v nvidia-smi)" ]; then + CUDA_PLUGIN_DIR=$(python -c "import pkgutil; import os; print(os.path.dirname(pkgutil.get_loader('torch_xla_cuda_plugin').get_filename()))") + export PJRT_LIBRARY_PATH=$CUDA_PLUGIN_DIR/lib/pjrt_c_api_gpu_plugin.so + export PJRT_DEVICE=LIBRARY + export PJRT_DYNAMIC_PLUGINS=1 + else + export PJRT_DEVICE=CPU + fi + export XLA_EXPERIMENTAL="nonzero:masked_select:nms" + + test_names1=("test_aten_xla_tensor_1" + "test_aten_xla_tensor_2" + "test_aten_xla_tensor_3" + "test_aten_xla_tensor_4" + "pjrt_computation_client_test" + "ifrt_computation_client_test") + test_names2=("test_aten_xla_tensor_5" + "test_aten_xla_tensor_6" + "test_ir" + "test_lazy" + "test_replication" + "test_tensor" + # disable test_xla_backend_intf since it is flaky on upstream + #"test_xla_backend_intf" + "test_xla_sharding") + if [[ "$RUN_CPP_TESTS1" == "cpp_tests1" ]]; then + test_names=("${test_names1[@]}") + elif [[ "$RUN_CPP_TESTS2" == "cpp_tests2" ]]; then + test_names=("${test_names2[@]}") + else + test_names=("${test_names1[@]}" "${test_names2[@]}") + fi + + for name in "${test_names[@]}"; do + echo "Running $name cpp test..." + /tmp/test/bin/${name} + done +} + +function run_torch_xla_benchmark_tests() { + XLA_DIR=$1 + pushd $XLA_DIR + echo "Running Benchmark Tests" + test/benchmarks/run_tests.sh -L"" +} + +PYTORCH_DIR=$1 +XLA_DIR=$2 +USE_COVERAGE="${3:-0}" +RUN_CPP="${RUN_CPP_TESTS:0}" +RUN_PYTHON="${RUN_PYTHON_TESTS:0}" + +if [ -x "$(command -v nvidia-smi)" ]; then + num_devices=$(nvidia-smi --list-gpus | wc -l) + echo "Found $num_devices GPU devices..." + export GPU_NUM_DEVICES=$num_devices +fi +export PYTORCH_TESTING_DEVICE_ONLY_FOR="xla" +export CXX_ABI=$(python -c "import torch;print(int(torch._C._GLIBCXX_USE_CXX11_ABI))") + +if [[ -z "$RUN_BENCHMARK_TESTS" && -z "$RUN_CPP_TESTS1" && -z "$RUN_CPP_TESTS2" && -z "$RUN_PYTHON_TESTS" ]]; then + run_torch_xla_python_tests $PYTORCH_DIR $XLA_DIR $USE_COVERAGE + run_torch_xla_cpp_tests $PYTORCH_DIR $XLA_DIR $USE_COVERAGE + run_torch_xla_benchmark_tests $XLA_DIR +else + # run tests separately. + if [[ "$RUN_PYTHON_TESTS" == "python_tests" ]]; then + run_torch_xla_python_tests $PYTORCH_DIR $XLA_DIR $USE_COVERAGE + elif [[ "$RUN_BENCHMARK_TESTS" == "benchmark_tests" ]]; then + run_torch_xla_benchmark_tests $XLA_DIR + else + run_torch_xla_cpp_tests $PYTORCH_DIR $XLA_DIR $USE_COVERAGE + fi +fi diff --git a/.circleci/docker/Dockerfile b/.github/upstream/Dockerfile similarity index 98% rename from .circleci/docker/Dockerfile rename to .github/upstream/Dockerfile index f0cd196511c..006460c2477 100644 --- a/.circleci/docker/Dockerfile +++ b/.github/upstream/Dockerfile @@ -1,3 +1,4 @@ +# Dockerfile for image used by upstream CI # This requires cuda & cudnn packages pre-installed in the base image. # Other available cuda images are listed at https://hub.docker.com/r/nvidia/cuda ARG base_image="us-central1-docker.pkg.dev/tpu-pytorch-releases/docker/development:3.8_cuda_12.1" diff --git a/.circleci/docker/install_conda.sh b/.github/upstream/install_conda.sh similarity index 100% rename from .circleci/docker/install_conda.sh rename to .github/upstream/install_conda.sh diff --git a/.circleci/docker/install_valgrind.sh b/.github/upstream/install_valgrind.sh similarity index 100% rename from .circleci/docker/install_valgrind.sh rename to .github/upstream/install_valgrind.sh diff --git a/.github/workflows/_build.yml b/.github/workflows/_build.yml deleted file mode 100644 index 789d0579272..00000000000 --- a/.github/workflows/_build.yml +++ /dev/null @@ -1,111 +0,0 @@ -name: xla-buld -on: - workflow_call: - inputs: - gcr-docker-image: - required: true - type: string - description: Base image for builds - ecr-docker-image-base: - required: true - type: string - description: Container registry to upload image to - runner: - required: false - type: string - description: Runner type for the test - default: linux.12xlarge - cuda: - required: false - type: string - description: Whether to build XLA with CUDA - default: 1 - - secrets: - gcloud-service-key: - required: true - description: Secret to access Bazel build cache - - outputs: - docker-image: - value: ${{ jobs.build.outputs.docker-image }} - description: The docker image containing the built PyTorch. -jobs: - build: - runs-on: ${{ inputs.runner }} - timeout-minutes: 240 - outputs: - docker-image: ${{ steps.upload-docker-image.outputs.docker-image }} - env: - ECR_DOCKER_IMAGE_BASE: ${{ inputs.ecr-docker-image-base }} - GCR_DOCKER_IMAGE: ${{ inputs.gcr-docker-image }} - WORKDIR: /var/lib/jenkins/workspace - SCCACHE_BUCKET: ossci-compiler-cache-circleci-v2 - GCLOUD_SERVICE_KEY: ${{ secrets.gcloud-service-key }} - XLA_CUDA: ${{ inputs.cuda }} - BAZEL_JOBS: 16 - steps: - - name: Setup Linux - uses: pytorch/test-infra/.github/actions/setup-linux@main - - name: Setup SSH (Click me for login details) - uses: pytorch/test-infra/.github/actions/setup-ssh@main - with: - github-secret: ${{ secrets.GITHUB_TOKEN }} - instructions: | - Build is done inside the container, to start an interactive session run: - docker exec -it $(docker container ps --format '{{.ID}}') bash - - name: Checkout repo - uses: actions/checkout@v3 - - name: Download docker image from GCR - shell: bash - run: docker pull "${GCR_DOCKER_IMAGE}" - - name: Stage image to ECR - shell: bash - run: | - # This is to stage PyTorch/XLA base image for use in the upstream. - # To allow the upstream workflow to access PyTorch/XLA build images, we - # need to have them in the ECR. This is not expensive, and only pushes it - # if image layers are not present in the repo. - # Note: disable the following 2 lines while testing a new image, so we do not - # push to the upstream. - docker tag "${GCR_DOCKER_IMAGE}" "${ECR_DOCKER_IMAGE_BASE}:v1.1-lite" >/dev/null - docker push "${ECR_DOCKER_IMAGE_BASE}:v1.1-lite" >/dev/null - - name: Start the container - shell: bash - run: | - pid=$(docker run --privileged -t -d -w "$WORKDIR" "${GCR_DOCKER_IMAGE}") - docker exec -u jenkins "${pid}" sudo chown -R jenkins "${WORKDIR}" - docker cp "${GITHUB_WORKSPACE}/." "$pid:$WORKDIR" - echo "pid=${pid}" >> "${GITHUB_ENV}" - - - name: Prepare build env - shell: bash - run: | - echo "declare -x SCCACHE_BUCKET=${SCCACHE_BUCKET}" | docker exec -i "${pid}" sh -c "cat >> env" - echo "declare -x XLA_CUDA=${XLA_CUDA}" | docker exec -i "${pid}" sh -c "cat >> xla_env" - echo "declare -x BAZEL_JOBS=${BAZEL_JOBS}" | docker exec -i "${pid}" sh -c "cat >> xla_env" - echo "declare -x BAZEL_REMOTE_CACHE=1" | docker exec -i "${pid}" sh -c "cat >> xla_env" - echo "${GCLOUD_SERVICE_KEY}" | docker exec -i "${pid}" sh -c "cat >> default_credentials.json" - - - name: Build - shell: bash - run: | - docker exec --privileged -u jenkins "${pid}" bash -c ".circleci/build.sh" - - name: Cleanup build env - shell: bash - run: | - docker exec "${pid}" rm default_credentials.json /tmp/pytorch/xla/default_credentials.json - - - name: Push built docker image to ECR - id: upload-docker-image - shell: bash - run: | - export COMMIT_DOCKER_IMAGE="${ECR_DOCKER_IMAGE_BASE}:latest-${GITHUB_SHA}" - time docker commit "${pid}" "${COMMIT_DOCKER_IMAGE}" - time docker push "${COMMIT_DOCKER_IMAGE}" - echo "docker-image=${COMMIT_DOCKER_IMAGE}" >> "${GITHUB_OUTPUT}" - - - name: Teardown Linux - uses: pytorch/test-infra/.github/actions/teardown-linux@main - if: always() - diff --git a/.github/workflows/_build_plugin.yml b/.github/workflows/_build_plugin.yml index 5f773971430..69b93fd5b81 100644 --- a/.github/workflows/_build_plugin.yml +++ b/.github/workflows/_build_plugin.yml @@ -25,7 +25,7 @@ jobs: GCLOUD_SERVICE_KEY: ${{ secrets.gcloud-service-key }} GOOGLE_APPLICATION_CREDENTIALS: /tmp/default_credentials.json BAZEL_JOBS: 16 - BAZEL_REMOTE_CACHE: 1 + BAZEL_REMOTE_CACHE: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository }} steps: - name: Setup gcloud shell: bash @@ -39,7 +39,7 @@ jobs: shell: bash run: | cd pytorch/xla/infra/ansible - ansible-playbook playbook.yaml -vvv -e "stage=build_plugin arch=amd64 accelerator=cuda src_root=${GITHUB_WORKSPACE}" --skip-tags=fetch_srcs,install_deps + ansible-playbook playbook.yaml -vvv -e "stage=build_plugin arch=amd64 accelerator=cuda cuda_compute_capabilities=5.2,7.5 src_root=${GITHUB_WORKSPACE} cache_suffix=-ci" --skip-tags=fetch_srcs,install_deps - name: Upload wheel uses: actions/upload-artifact@v4 with: diff --git a/.github/workflows/_build_torch_with_cuda.yml b/.github/workflows/_build_torch_with_cuda.yml new file mode 100644 index 00000000000..e9defd40eb5 --- /dev/null +++ b/.github/workflows/_build_torch_with_cuda.yml @@ -0,0 +1,55 @@ +name: build-torch-with-cuda +on: + workflow_call: + inputs: + dev-image: + required: true + type: string + description: Base image for builds + torch-commit: + required: true + type: string + description: torch-commit + runner: + required: false + type: string + description: Runner type for the test + default: linux.12xlarge +jobs: + build: + runs-on: ${{ inputs.runner }} + container: + image: ${{ inputs.dev-image }} + options: "--gpus all --shm-size 16g" + env: + _GLIBCXX_USE_CXX11_ABI: 0 + steps: + # See https://github.com/actions/checkout/issues/1014#issuecomment-1906802802 + - name: Clean up workspace + run: | + ls -la + rm -rvf ${GITHUB_WORKSPACE}/* + - name: Setup CUDA environment + shell: bash + run: | + echo "PATH=$PATH:/usr/local/cuda-12.1/bin" >> $GITHUB_ENV + echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-12.1/lib64" >> $GITHUB_ENV + - name: Check GPU + run: nvidia-smi + - name: Checkout PyTorch Repo + uses: actions/checkout@v4 + with: + repository: pytorch/pytorch + path: pytorch + ref: ${{ inputs.torch-commit }} + submodules: recursive + - name: Build + shell: bash + run: | + cd pytorch + USE_CUDA=1 python setup.py bdist_wheel + - name: Upload wheel + uses: actions/upload-artifact@v4 + with: + name: torch-with-cuda + path: pytorch/dist/*.whl diff --git a/.github/workflows/_build_torch_xla.yml b/.github/workflows/_build_torch_xla.yml index 969fb3b5dc9..56e6b5408c3 100644 --- a/.github/workflows/_build_torch_xla.yml +++ b/.github/workflows/_build_torch_xla.yml @@ -6,6 +6,10 @@ on: required: true type: string description: Base image for builds + torch-commit: + required: true + type: string + description: torch-commit runner: required: false type: string @@ -25,8 +29,14 @@ jobs: GCLOUD_SERVICE_KEY: ${{ secrets.gcloud-service-key }} GOOGLE_APPLICATION_CREDENTIALS: /tmp/default_credentials.json BAZEL_JOBS: 16 - BAZEL_REMOTE_CACHE: 1 + BAZEL_REMOTE_CACHE: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository }} + BUILD_CPP_TESTS: 1 steps: + # See https://github.com/actions/checkout/issues/1014#issuecomment-1906802802 + - name: Clean up workspace + run: | + ls -la + rm -rvf ${GITHUB_WORKSPACE}/* - name: Setup gcloud shell: bash run: | @@ -36,7 +46,8 @@ jobs: with: repository: pytorch/pytorch path: pytorch - # TODO: correct pin + ref: ${{ inputs.torch-commit }} + submodules: recursive - name: Checkout PyTorch/XLA Repo uses: actions/checkout@v4 with: @@ -45,9 +56,14 @@ jobs: shell: bash run: | cd pytorch/xla/infra/ansible - ansible-playbook playbook.yaml -e "stage=build arch=amd64 accelerator=tpu src_root=${GITHUB_WORKSPACE} bundle_libtpu=0" --skip-tags=fetch_srcs,install_deps + ansible-playbook playbook.yaml -vvv -e "stage=build arch=amd64 accelerator=tpu src_root=${GITHUB_WORKSPACE} bundle_libtpu=0 build_cpp_tests=1 git_versioned_xla_build=1 cache_suffix=-ci" --skip-tags=fetch_srcs,install_deps - name: Upload wheel uses: actions/upload-artifact@v4 with: name: torch-xla-wheels path: /dist/*.whl + - name: Upload CPP test binaries + uses: actions/upload-artifact@v4 + with: + name: cpp-test-bin + path: /tmp/test/bin diff --git a/.github/workflows/_docs.yml b/.github/workflows/_docs.yml index ed9a4ab0ea9..378dec9697a 100644 --- a/.github/workflows/_docs.yml +++ b/.github/workflows/_docs.yml @@ -2,10 +2,10 @@ name: xla-docs-build on: workflow_call: inputs: - docker-image: + dev-image: required: true type: string - description: Image to build docs in + description: Base image for builds runner: required: false type: string @@ -15,35 +15,57 @@ on: torchxla-bot-token: required: true jobs: - push-docs: - runs-on: ${{ inputs.runner }} + build-docs: + runs-on: ubuntu-latest timeout-minutes: 45 + container: + image: ${{ inputs.dev-image }} env: - DOCKER_IMAGE: ${{ inputs.docker-image }} - WORKDIR: /var/lib/jenkins/workspace + BRANCH_NAME: ${{ github.ref_name }} steps: - - name: Setup Linux - uses: pytorch/test-infra/.github/actions/setup-linux@main - - name: Setup SSH (Click me for login details) - uses: pytorch/test-infra/.github/actions/setup-ssh@main - with: - github-secret: ${{ secrets.GITHUB_TOKEN }} - instructions: | - Doc builds are done inside container. Interactive session can be started by following: - docker exec -it $(docker container ps --format '{{.ID}}') bash - - name: Download and run docker image from GCR - shell: bash - env: - GITHUB_TORCH_XLA_BOT_TOKEN: ${{ secrets. torchxla-bot-token }} - run: | - echo "DOCKER_IMAGE: ${DOCKER_IMAGE}" - docker pull "${DOCKER_IMAGE}" - pid=$(docker run -e GITHUB_TORCH_XLA_BOT_TOKEN -t -d -w "$WORKDIR" "${DOCKER_IMAGE}") - echo "${GCLOUD_SERVICE_KEY}" | docker exec -i "${pid}" sh -c "cat >> /tmp/pytorch/xla/default_credentials.json" - echo "pid=${pid}" >> "${GITHUB_ENV}" - - name: Build & publish docs - shell: bash - run: docker exec -u jenkins "${pid}" bash -c '.circleci/doc_push.sh' - - name: Teardown Linux - uses: pytorch/test-infra/.github/actions/teardown-linux@main - if: always() + - name: Fetch wheels + uses: actions/download-artifact@v4 + with: + name: torch-xla-wheels + path: /tmp/wheels/ + - name: Install wheels + shell: bash + run: | + pip install /tmp/wheels/*.whl + - name: Checkout PyTorch/XLA Repo + uses: actions/checkout@v4 + with: + path: pytorch/xla + - name: Build docs + shell: bash + run: | + cd pytorch/xla/docs + pip install -r requirements.txt + sphinx-build -b html source build + - name: Checkout GitHub Pages + uses: actions/checkout@v4 + with: + path: gh-pages + ref: gh-pages + token: ${{ secrets.torchxla-bot-token }} + - name: Merge changes + shell: bash + run: | + subdir=${{ env.BRANCH_NAME == 'master' && 'master' || format('{0}/{1}', 'release', env.BRANCH_NAME) }} + mkdir -p gh-pages/$subdir + cp -fR pytorch/xla/docs/build/* gh-pages/$subdir + - name: Upload preview as artifact + uses: actions/upload-artifact@v4 + with: + name: github-pages + path: pytorch/xla/docs/build/ + - name: Deploy + shell: bash + run: | + cd gh-pages + git config user.email "pytorchxla@gmail.com" + git config user.name "torchxlabot2" + git add . -v + git diff --cached --exit-code || git commit -m "Update doc from commit ${{ github.sha }}" + git push origin gh-pages + if: github.event_name == 'push' diff --git a/.github/workflows/_get_torch_commit.yml b/.github/workflows/_get_torch_commit.yml new file mode 100644 index 00000000000..debaecd8194 --- /dev/null +++ b/.github/workflows/_get_torch_commit.yml @@ -0,0 +1,32 @@ +name: get-torch-commit +on: + workflow_call: + outputs: + torch_commit: + description: "torch commit to be used" + value: ${{ jobs.get-commit.outputs.torch_commit }} + +jobs: + get-commit: + runs-on: ubuntu-20.04 + outputs: + torch_commit: ${{ steps.get_torch_commit.outputs.torch_commit }} + steps: + # See https://github.com/actions/checkout/issues/1014#issuecomment-1906802802 + - name: Clean up workspace + run: | + ls -la + rm -rvf ${GITHUB_WORKSPACE}/* + - name: Checkout PyTorch Repo + uses: actions/checkout@v4 + with: + repository: pytorch/pytorch + path: pytorch + submodules: recursive + - id: get_torch_commit + name: Get torch commit + run: | + cd pytorch + torch_commit=$(git rev-parse HEAD) + echo "torch_commit=$torch_commit" >> "$GITHUB_OUTPUT" + diff --git a/.github/workflows/_test.yml b/.github/workflows/_test.yml index 0f9e96e31e5..8a454cc075b 100644 --- a/.github/workflows/_test.yml +++ b/.github/workflows/_test.yml @@ -2,10 +2,10 @@ name: xla-test on: workflow_call: inputs: - docker-image: + dev-image: required: true type: string - description: Image to test on + description: Base image for builds runner: required: false type: string @@ -22,16 +22,12 @@ on: default: 270 description: | Set the maximum (in minutes) how long the workflow should take to finish - disable-pjrt: + timeout-minutes: + install-cuda-plugin: required: false - type: string - default: 0 - description: Whether to disable PJRT tests - test-script: - required: false - type: string - default: test.sh - description: Which test script to run + type: boolean + default: false + description: Whether to install CUDA plugin package secrets: gcloud-service-key: @@ -40,14 +36,15 @@ on: jobs: test: runs-on: ${{ inputs.runner }} + container: + image: ${{ inputs.dev-image }} + options: "${{ inputs.install-cuda-plugin && '--gpus all' || '' }} --shm-size 16g" strategy: fail-fast: false matrix: include: # Use readable strings as they define the workflow titles. - run_benchmark_tests: 'benchmark_tests' - - run_cpp_tests1: 'cpp_tests1' - - run_cpp_tests2: 'cpp_tests2' - run_python_tests: 'python_tests' run_xla_op_tests1: 'xla_op1' - run_python_tests: 'python_tests' @@ -56,63 +53,112 @@ jobs: run_xla_op_tests3: 'xla_op3' - run_python_tests: 'python_tests' run_torch_mp_op_tests: 'torch_mp_op' + - run_cpp_tests: 'cpp_tests' + run_cpp_tests1: 'cpp_tests1' + - run_cpp_tests: 'cpp_tests' + run_cpp_tests2: 'cpp_tests2' timeout-minutes: ${{ inputs.timeout-minutes }} env: - DOCKER_IMAGE: ${{ inputs.docker-image }} - WORKDIR: /var/lib/jenkins/workspace GCLOUD_SERVICE_KEY: ${{ secrets.gcloud-service-key }} + GOOGLE_APPLICATION_CREDENTIALS: /tmp/default_credentials.json USE_COVERAGE: ${{ inputs.collect-coverage && '1' || '0' }} - XLA_SKIP_TORCH_OP_TESTS: ${{ inputs.disable-pjrt }} - XLA_SKIP_MP_OP_TESTS: ${{ inputs.disable-pjrt }} RUN_BENCHMARK_TESTS: ${{ matrix.run_benchmark_tests }} - RUN_CPP_TESTS1: ${{ matrix.run_cpp_tests1 }} - RUN_CPP_TESTS2: ${{ matrix.run_cpp_tests2 }} RUN_PYTHON_TESTS: ${{ matrix.run_python_tests }} RUN_XLA_OP_TESTS1: ${{ matrix.run_xla_op_tests1 }} RUN_XLA_OP_TESTS2: ${{ matrix.run_xla_op_tests2 }} RUN_XLA_OP_TESTS3: ${{ matrix.run_xla_op_tests3 }} RUN_TORCH_MP_OP_TESTS: ${{ matrix.run_torch_mp_op_tests }} + RUN_CPP_TESTS1: ${{ matrix.run_cpp_tests1 }} + RUN_CPP_TESTS2: ${{ matrix.run_cpp_tests2 }} + BAZEL_JOBS: 16 + BAZEL_REMOTE_CACHE: 1 steps: - - name: Setup Linux - uses: pytorch/test-infra/.github/actions/setup-linux@main - - name: Setup SSH (Click me for login details) - uses: pytorch/test-infra/.github/actions/setup-ssh@main + # See https://github.com/actions/checkout/issues/1014#issuecomment-1906802802 + - name: Clean up workspace + run: | + ls -la + rm -rvf ${GITHUB_WORKSPACE}/* + - name: Setup gcloud + shell: bash + run: | + echo "${GCLOUD_SERVICE_KEY}" > $GOOGLE_APPLICATION_CREDENTIALS + - name: Fetch wheels + uses: actions/download-artifact@v4 with: - github-secret: ${{ secrets.GITHUB_TOKEN }} - instructions: | - Tests are done inside the container, to start an interactive session run: - docker exec -it $(docker container ps --format '{{.ID}}') bash - - name: Install gcloud CLI - if: ${{ inputs.collect-coverage }} + name: torch-xla-wheels + path: /tmp/wheels/ + - name: Fetch CPP test binaries + uses: actions/download-artifact@v4 + with: + name: cpp-test-bin + path: /tmp/test/bin + if: ${{ matrix.run_cpp_tests }} + # GitHub Actions doesn't preserve executable permissions + # https://github.com/actions/download-artifact?tab=readme-ov-file#permission-loss + - name: Set CPP test permissions + run: | + chmod +x /tmp/test/bin/* + ls -l /tmp/test/bin + if: ${{ matrix.run_cpp_tests }} + - name: Fetch CUDA plugin + uses: actions/download-artifact@v4 + with: + name: cuda-plugin + path: /tmp/wheels/ + if: ${{ inputs.install-cuda-plugin }} + - name: Setup CUDA environment shell: bash run: | - sudo tee -a /etc/yum.repos.d/google-cloud-sdk.repo << EOM - [google-cloud-cli] - name=Google Cloud CLI - baseurl=https://packages.cloud.google.com/yum/repos/cloud-sdk-el8-x86_64 - enabled=1 - gpgcheck=1 - repo_gpgcheck=0 - gpgkey=https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg - EOM - sudo yum install -y google-cloud-cli - - name: Auth to GCR - if: ${{ inputs.collect-coverage }} + # TODO: Make PJRT_DEVICE=CPU work with XLA_REGISTER_INSTALLED_PLUGINS=1 + echo "XLA_REGISTER_INSTALLED_PLUGINS=1" >> $GITHUB_ENV + + echo "PATH=$PATH:/usr/local/cuda-12.1/bin" >> $GITHUB_ENV + echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-12.1/lib64" >> $GITHUB_ENV + if: ${{ inputs.install-cuda-plugin }} + - name: Check GPU + run: nvidia-smi + if: ${{ inputs.install-cuda-plugin }} + - name: Install wheels shell: bash run: | - echo "${GCLOUD_SERVICE_KEY}" | gcloud auth activate-service-account --key-file=- - - name: Download and run docker image from GCR + pip install /tmp/wheels/*.whl + # TODO: Add these in setup.py + pip install fsspec + pip install rich + + echo "Import check..." + python -c "import torch_xla" + - name: Record PyTorch commit + run: | + # Don't just pipe output in shell because imports may do extra logging + python -c " + import torch_xla.version + with open('$GITHUB_ENV', 'a') as f: + f.write(f'PYTORCH_COMMIT={torch_xla.version.__torch_gitrev__}\n') + " + - name: Checkout PyTorch Repo + uses: actions/checkout@v4 + with: + repository: pytorch/pytorch + path: pytorch + ref: ${{ env.PYTORCH_COMMIT }} + - name: Checkout PyTorch/XLA Repo + uses: actions/checkout@v4 + with: + path: pytorch/xla + - name: Extra CI deps shell: bash run: | - echo "DOCKER_IMAGE: ${DOCKER_IMAGE}" - docker pull "${DOCKER_IMAGE}" - pid=$(docker run --shm-size=16g ${GPU_FLAG:-} -e USE_COVERAGE -e XLA_SKIP_TORCH_OP_TESTS -e XLA_SKIP_MP_OP_TESTS -e RUN_BENCHMARK_TESTS -e RUN_CPP_TESTS1 -e RUN_CPP_TESTS2 -e RUN_PYTHON_TESTS -e RUN_XLA_OP_TESTS1 -e RUN_XLA_OP_TESTS2 -e RUN_XLA_OP_TESTS3 -e RUN_TORCH_MP_OP_TESTS -t -d -w "$WORKDIR" "${DOCKER_IMAGE}") - echo "${GCLOUD_SERVICE_KEY}" | docker exec -i "${pid}" sh -c "cat >> /tmp/pytorch/xla/default_credentials.json" - echo "pid=${pid}" >> "${GITHUB_ENV}" + set -x + + pip install expecttest unittest-xml-reporting + + if [[ ! -z "$RUN_BENCHMARK_TESTS" ]]; then + pip install -r pytorch/xla/benchmarks/requirements.txt + fi - name: Test shell: bash - run: | - docker exec --privileged -u jenkins "${pid}" bash -c '.circleci/${{ inputs.test-script }}' + run: pytorch/xla/.github/scripts/run_tests.sh pytorch/ pytorch/xla/ $USE_COVERAGE - name: Upload coverage results if: ${{ inputs.collect-coverage }} shell: bash @@ -158,8 +204,3 @@ jobs: gsutil cp inc_metadata.json gs://ng3-metrics/ng3-pytorchxla-coverage/incremental/pytorchxla/${CIRCLE_WORKFLOW_ID}/metadata.json fi fi - - - name: Teardown Linux - uses: pytorch/test-infra/.github/actions/teardown-linux@main - if: always() - diff --git a/.github/workflows/_test_requiring_torch_cuda.yml b/.github/workflows/_test_requiring_torch_cuda.yml new file mode 100644 index 00000000000..a3e265e557f --- /dev/null +++ b/.github/workflows/_test_requiring_torch_cuda.yml @@ -0,0 +1,110 @@ +name: xla-test-requiring-torch-cuda +on: + workflow_call: + inputs: + dev-image: + required: true + type: string + description: Base image for builds + runner: + required: false + type: string + description: Runner type for the test + default: linux.12xlarge + collect-coverage: + required: false + type: boolean + description: Set to true to collect coverage information + default: false + timeout-minutes: + required: false + type: number + default: 30 + description: | + Set the maximum (in minutes) how long the workflow should take to finish + timeout-minutes: + +jobs: + test: + runs-on: ${{ inputs.runner }} + container: + image: ${{ inputs.dev-image }} + options: "--gpus all --shm-size 16g" + timeout-minutes: ${{ inputs.timeout-minutes }} + env: + USE_COVERAGE: ${{ inputs.collect-coverage && '1' || '0' }} + BAZEL_JOBS: 16 + BAZEL_REMOTE_CACHE: 1 + steps: + # See https://github.com/actions/checkout/issues/1014#issuecomment-1906802802 + # TODO: need to find a way to reuse these steps. + - name: Clean up workspace + run: | + ls -la + rm -rvf ${GITHUB_WORKSPACE}/* + - name: Fetch torch/torch_xla/torchvision wheels + uses: actions/download-artifact@v4 + with: + name: torch-xla-wheels + path: /tmp/wheels/ + - name: Remove torch wheel built with CUDA disabled + shell: bash + run: | + rm -rf /tmp/wheels/torch-* + - name: Fetch the torch wheel built with CUDA enabled + uses: actions/download-artifact@v4 + with: + name: torch-with-cuda + path: /tmp/wheels/ + - name: Fetch CUDA plugin + uses: actions/download-artifact@v4 + with: + name: cuda-plugin + path: /tmp/wheels/ + - name: Setup CUDA environment + shell: bash + run: | + echo "XLA_REGISTER_INSTALLED_PLUGINS=1" >> $GITHUB_ENV + + echo "PATH=$PATH:/usr/local/cuda-12.1/bin" >> $GITHUB_ENV + echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-12.1/lib64" >> $GITHUB_ENV + - name: Check GPU + run: nvidia-smi + - name: Install wheels + shell: bash + run: | + pip install /tmp/wheels/*.whl + # TODO: Add these in setup.py + pip install fsspec + pip install rich + + echo "Import check..." + python -c "import torch, torch_xla, torchvision" + echo "Import check done." + echo "Check if CUDA is available for PyTorch..." + python -c "import torch; assert torch.cuda.is_available()" + echo "CUDA is available for PyTorch." + - name: Record PyTorch commit + run: | + # Don't just pipe output in shell because imports may do extra logging + python -c " + import torch_xla.version + with open('$GITHUB_ENV', 'a') as f: + f.write(f'PYTORCH_COMMIT={torch_xla.version.__torch_gitrev__}\n') + " + - name: Checkout PyTorch Repo + uses: actions/checkout@v4 + with: + repository: pytorch/pytorch + path: pytorch + ref: ${{ env.PYTORCH_COMMIT }} + - name: Checkout PyTorch/XLA Repo + uses: actions/checkout@v4 + with: + path: pytorch/xla + - name: Test + shell: bash + run: | + set -xue + PJRT_DEVICE=CUDA python pytorch/xla/test/test_operations.py -v + PJRT_DEVICE=CUDA python pytorch/xla/test/dynamo/test_dynamo.py -v diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 38203f57580..1a924f65036 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -19,38 +19,45 @@ concurrency: cancel-in-progress: true jobs: - build: - name: "Build PyTorch/XLA (GPU)" - uses: ./.github/workflows/_build.yml - with: - ecr-docker-image-base: 308535385114.dkr.ecr.us-east-1.amazonaws.com/pytorch/xla_base - gcr-docker-image: gcr.io/tpu-pytorch/xla_base:dev-3.8_cuda_12.1 - cuda: 1 - secrets: - gcloud-service-key: ${{ secrets.GCLOUD_SERVICE_KEY }} + + get-torch-commit: + name: "Get torch commit" + uses: ./.github/workflows/_get_torch_commit.yml build-torch-xla: - name: "Build PyTorch/XLA (TPU)" + name: "Build PyTorch/XLA" uses: ./.github/workflows/_build_torch_xla.yml + needs: get-torch-commit with: dev-image: us-central1-docker.pkg.dev/tpu-pytorch-releases/docker/development:3.10_tpuvm + torch-commit: ${{needs.get-torch-commit.outputs.torch_commit}} secrets: gcloud-service-key: ${{ secrets.GCLOUD_SERVICE_KEY }} + build-torch-with-cuda: + name: "Build PyTorch with CUDA" + uses: ./.github/workflows/_build_torch_with_cuda.yml + needs: get-torch-commit + with: + # note that to build a torch wheel with CUDA enabled, we do not need a GPU runner. + dev-image: us-central1-docker.pkg.dev/tpu-pytorch-releases/docker/development:3.10_cuda_12.1 + torch-commit: ${{needs.get-torch-commit.outputs.torch_commit}} + runner: linux.8xlarge.nvidia.gpu + build-cuda-plugin: name: "Build XLA CUDA plugin" uses: ./.github/workflows/_build_plugin.yml with: - dev-image: us-central1-docker.pkg.dev/tpu-pytorch-releases/docker/development:3.8_cuda_12.1 + dev-image: us-central1-docker.pkg.dev/tpu-pytorch-releases/docker/development:3.10_cuda_12.1 secrets: gcloud-service-key: ${{ secrets.GCLOUD_SERVICE_KEY }} - test-cpu: + test-python-cpu: name: "CPU tests" uses: ./.github/workflows/_test.yml - needs: build + needs: build-torch-xla with: - docker-image: ${{ needs.build.outputs.docker-image }} + dev-image: us-central1-docker.pkg.dev/tpu-pytorch-releases/docker/development:3.10_tpuvm timeout-minutes: 120 collect-coverage: false secrets: @@ -59,28 +66,38 @@ jobs: test-cuda: name: "GPU tests" uses: ./.github/workflows/_test.yml - needs: build + needs: [build-torch-xla, build-cuda-plugin] with: - docker-image: ${{ needs.build.outputs.docker-image }} + dev-image: us-central1-docker.pkg.dev/tpu-pytorch-releases/docker/development:3.10_cuda_12.1 runner: linux.8xlarge.nvidia.gpu timeout-minutes: 300 - collect-coverage: false # TODO(yeounoh) separate from CPU coverage metrics + collect-coverage: false + install-cuda-plugin: true secrets: gcloud-service-key: ${{ secrets.GCLOUD_SERVICE_KEY }} + test-cuda-with-pytorch-cuda-enabled: + name: "GPU tests requiring torch CUDA" + uses: ./.github/workflows/_test_requiring_torch_cuda.yml + needs: [build-torch-with-cuda, build-torch-xla, build-cuda-plugin] + with: + dev-image: us-central1-docker.pkg.dev/tpu-pytorch-releases/docker/development:3.10_cuda_12.1 + runner: linux.8xlarge.nvidia.gpu + timeout-minutes: 300 + collect-coverage: false + test-tpu: name: "TPU tests" uses: ./.github/workflows/_tpu_ci.yml needs: build-torch-xla # Only run this for HEAD and releases - if: github.event_name == 'push' + if: github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'tpuci') push-docs: - name: "Build & publish docs" - if: github.event_name == 'push' && (github.event.ref == 'refs/heads/master' || startsWith(github.event.ref, 'refs/tags/r')) + name: "Build docs" uses: ./.github/workflows/_docs.yml - needs: build + needs: build-torch-xla with: - docker-image: ${{ needs.build.outputs.docker-image }} + dev-image: us-central1-docker.pkg.dev/tpu-pytorch-releases/docker/development:3.10_tpuvm secrets: torchxla-bot-token: ${{ secrets.TORCH_XLA_BOT_TOKEN }} diff --git a/.github/workflows/build_upstream_image.yml b/.github/workflows/build_upstream_image.yml new file mode 100644 index 00000000000..446ad366e54 --- /dev/null +++ b/.github/workflows/build_upstream_image.yml @@ -0,0 +1,40 @@ +name: Build upstream image +on: + push: + branches: + - master + - r[0-9]+.[0-9]+ + paths-ignore: + - 'experimental/torch_xla2/**' + workflow_dispatch: +jobs: + build: + runs-on: linux.12xlarge + timeout-minutes: 30 + env: + ECR_DOCKER_IMAGE_BASE: 308535385114.dkr.ecr.us-east-1.amazonaws.com/pytorch/xla_base + BAZEL_JOBS: 16 + steps: + # See https://github.com/actions/checkout/issues/1014#issuecomment-1906802802 + - name: Clean up workspace + run: | + ls -la + sudo rm -rvf ${GITHUB_WORKSPACE}/* + - name: Setup Linux + uses: pytorch/test-infra/.github/actions/setup-linux@main + - name: Checkout repo + uses: actions/checkout@v3 + - name: Build Docker image + shell: bash + run: | + docker build -t "${ECR_DOCKER_IMAGE_BASE}:v1.2-lite" .github/upstream + - name: Stage image to ECR + shell: bash + run: | + # This is to stage PyTorch/XLA base image for use in the upstream. + # To allow the upstream workflow to access PyTorch/XLA build images, we + # need to have them in the ECR. This is not expensive, and only pushes it + # if image layers are not present in the repo. + # Note: disable the following line while testing a new image, so we do not + # push to the upstream. + docker push "${ECR_DOCKER_IMAGE_BASE}:v1.2-lite" diff --git a/.github/workflows/lintercheck.yml b/.github/workflows/lintercheck.yml index 6598b98da32..b17c608f883 100644 --- a/.github/workflows/lintercheck.yml +++ b/.github/workflows/lintercheck.yml @@ -24,7 +24,7 @@ jobs: if: github.event_name == 'push' && github.event.ref == 'refs/heads/master' shell: bash run: | - TORCH_PIN=./torch_patches/.torch_pin + TORCH_PIN=./.torch_pin if [[ -f "${TORCH_PIN}" ]]; then echo "Please remove ${TORCH_PIN} before landing." exit 1 diff --git a/.github/workflows/torch_xla2.yml b/.github/workflows/torch_xla2.yml index 7c5a88bf430..441addad422 100644 --- a/.github/workflows/torch_xla2.yml +++ b/.github/workflows/torch_xla2.yml @@ -34,10 +34,8 @@ jobs: shell: bash working-directory: experimental/torch_xla2 run: | - pip install pytest absl-py jax[cpu] flatbuffers tensorflow - pip install torch --index-url https://download.pytorch.org/whl/cpu - pip install -r test_requirements.txt - pip install -e . + pip install -r test-requirements.txt + pip install -e .[cpu] - name: Run tests working-directory: experimental/torch_xla2 shell: bash diff --git a/.kokoro/Dockerfile b/.kokoro/Dockerfile index e85930b57d9..f04cd7d7874 100644 --- a/.kokoro/Dockerfile +++ b/.kokoro/Dockerfile @@ -41,7 +41,7 @@ RUN python setup.py install # install torch xla ADD ./ /pytorch/xla WORKDIR /pytorch/xla -RUN cp keystore_content/77422_pytorch_tpu_cloud_build default_credentials.json +# TODO: to reenable kokoro back, please request security key and save in default_credentials.json ARG SCCACHE="$(which sccache)" WORKDIR /pytorch/xla diff --git a/.kokoro/presubmit.cfg b/.kokoro/presubmit.cfg index 3f166e3557e..3b35cde7315 100644 --- a/.kokoro/presubmit.cfg +++ b/.kokoro/presubmit.cfg @@ -7,11 +7,5 @@ build_file: "xla/.kokoro/build_and_run_stablehlo_tests.sh" timeout_mins: 360 before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 77422 - keyname: "pytorch_tpu_cloud_build" - backend: "blade:keystore-fastconfigpush" - } - } -} \ No newline at end of file +# TODO: to reenable kokoro, please setup how to fetch keysore here +} diff --git a/BUILD b/BUILD index 6949f6dc748..5e1c90de84d 100644 --- a/BUILD +++ b/BUILD @@ -3,6 +3,21 @@ load( "if_cuda_is_configured", ) +load("@python//:defs.bzl", "compile_pip_requirements") +load("@python_version_repo//:py_version.bzl", "REQUIREMENTS") + +compile_pip_requirements( + name = "requirements", + extra_args = [ + "--allow-unsafe", + "--build-isolation", + "--rebuild", + ], + requirements_in = "requirements.in", + requirements_txt = REQUIREMENTS, + generate_hashes = True, +) + cc_binary( name = "_XLAC.so", copts = [ @@ -30,3 +45,23 @@ cc_binary( "@xla//xla/stream_executor:cuda_platform", ]), ) + +test_suite( + name = "cpp_tests", + # testonly = True, + tests = [ + "//test/cpp:test_aten_xla_tensor_1", + "//test/cpp:test_aten_xla_tensor_2", + "//test/cpp:test_aten_xla_tensor_3", + "//test/cpp:test_aten_xla_tensor_4", + "//test/cpp:test_aten_xla_tensor_5", + "//test/cpp:test_aten_xla_tensor_6", + "//test/cpp:test_ir", + "//test/cpp:test_lazy", + "//test/cpp:test_replication", + "//test/cpp:test_tensor", + "//test/cpp:test_xla_sharding", + "//torch_xla/csrc/runtime:pjrt_computation_client_test", + "//torch_xla/csrc/runtime:ifrt_computation_client_test", + ], +) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e4d0b161139..97c418a7eca 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,9 +6,58 @@ You are very welcome to pick issues from [good first issue](https://github.com/p If you plan to contribute new features, utility functions or extensions to the core, please first open an issue and discuss the feature with us. Sending a PR without discussion might end up resulting in a rejected PR, because we might be taking the core in a different direction than you might be aware of. -## Building Manually +## Building from source -We recommend you to use our prebuilt Docker image to start your development work. If you want to use VSCode with docker, please refer to this [config](https://github.com/pytorch/xla/tree/master/.devcontainer/tpu-contributor). +We recommend you to use our prebuilt Docker image to start your development work using one of the two following methods. + +### Visual Studio Code Dev Container + +* Create an empty directory (optionally on a remote host via SSH) and open it in VSCode. Then, clone PyTorch and PyTorch/XLA: + + ```bash + git clone --recursive --depth=1 https://github.com/pytorch/pytorch.git + git clone https://github.com/pytorch/xla.git pytorch/xla + # Optional: use git@github.com:pytorch/xla.git instead if you prefer to use SSH with key forwarding + ``` + +* Link (or copy) VSCode configuration to your workspace directory: + + ```bash + ln -s pytorch/xla/.devcontainer/ .devcontainer + ln -s pytorch/xla/contrib/vscode/ .vscode + ln -s pytorch/xla/.style.yapf .style.yapf + ln -s pytorch/xla/.clang-format .clang-format + ``` + +* From VSCode's command menu, run `Reopen in Container` to open your workspace in one of our pre-built Docker containers. Select the correct container config based on your local accelerator (default to `tpu-contributor` if you are not sure). + +* Since you are running as root in this container, change ownership of all files: + + ```bash + chown -R root:root . + ``` + +* Build PyTorch and PyTorch/XLA: + + ```bash + cd pytorch/ + # pytorch/xla requires pytorch wheel to be presented under pytorch/dist + python setup.py bdist_wheel + python setup.py install + cd xla/ + python setup.py develop + # Optional: if you're using TPU, install libtpu + pip install torch_xla[tpu] -f https://storage.googleapis.com/libtpu-releases/index.html + ``` + +* Test your build + + ```bash + python -c 'import torch_xla as xla; print(xla.device())' + # Output: xla:0 + ``` + +### Manually build in Docker container * Setup Development Docker Image @@ -34,6 +83,8 @@ We recommend you to use our prebuilt Docker image to start your development work * Build PyTorch ```Shell + # pytorch/xla requires pytorch wheel to be presented under pytorch/dist + python setup.py bdist_wheel python setup.py develop ``` * Build PyTorch/XLA @@ -42,7 +93,7 @@ We recommend you to use our prebuilt Docker image to start your development work python setup.py develop ``` -### Build PyTorch/XLA from source with GPU support +### Additional steps for GPU Please refer to this [guide](https://github.com/pytorch/xla/blob/master/docs/gpu.md#develop-pytorchxla-on-a-gpu-instance-build-pytorchxla-from-source-with-gpu-support). diff --git a/OP_LOWERING_GUIDE.md b/OP_LOWERING_GUIDE.md index b445a1d8998..535d7cf596c 100644 --- a/OP_LOWERING_GUIDE.md +++ b/OP_LOWERING_GUIDE.md @@ -25,7 +25,7 @@ All file mentioned below lives under the `xla/torch_xla/csrc` folder, with the e 7. `ops/` directory contains all `ir::ops` declaration and definition. Smaller nodes can be put in `ops/ops.h/.cpp`. More complicated nodes can be put into a separate file. All ops inherit from `ir::ops::Node` and provide a way to lower input `ir::Value` to a sequence of `XlaOp`. ## Unit Test -Our CircleCI runs PyTorch native python tests for every change and every day. Those tests will use XLA implementation if we provide a lowering. We usually don’t need to add additional python tests for PyTorch/XLA unless we want to verify some xla behaviors(like dynamic shape) or we skipped the pytorch native test for some reason. The python test should be added to `xla/test/test_operations.py` if it is required. We also need to add CPP tests in `xla/test/cpp/test_aten_xla_tensor.cpp`. This test should call PyTorch c++ API and verify our implementation yields the same result as PyTorch native implementation. We also need to verify if the xla implementation is called when the tensor is a XLA tensor by checking the `aten::op` and `xla::op` counters. +Our CI runs PyTorch native python tests for every change and every day. Those tests will use XLA implementation if we provide a lowering. We usually don’t need to add additional python tests for PyTorch/XLA unless we want to verify some xla behaviors(like dynamic shape) or we skipped the pytorch native test for some reason. The python test should be added to `xla/test/test_operations.py` if it is required. We also need to add CPP tests in `xla/test/cpp/test_aten_xla_tensor.cpp`. This test should call PyTorch c++ API and verify our implementation yields the same result as PyTorch native implementation. We also need to verify if the xla implementation is called when the tensor is a XLA tensor by checking the `aten::op` and `xla::op` counters. ## Tips The process of lowering is breaking down the PyTorch operations into a sequence of XlaOp. To provide a good lowering of the PyTorch operation, one needs to have a good grasp of what XLA is capable of. Reading the XlaOp document and looking into how similar ops is lowered is the best way to achieve that. You can find a minimal Op lowering example in [this pr](https://github.com/pytorch/xla/pull/2969). You can also find a slightly more complicated example with backward lowering in [this pr](https://github.com/pytorch/xla/pull/2972). diff --git a/README.md b/README.md index d1653eb7b53..064297d0332 100644 --- a/README.md +++ b/README.md @@ -26,36 +26,34 @@ started: To install PyTorch/XLA a new TPU VM: ``` -pip install torch~=2.2.0 torch_xla[tpu]~=2.2.0 -f https://storage.googleapis.com/libtpu-releases/index.html +pip install torch~=2.3.0 torch_xla[tpu]~=2.3.0 -f https://storage.googleapis.com/libtpu-releases/index.html ``` To update your existing training loop, make the following changes: ```diff -import torch.multiprocessing as mp ++import torch_xla as xla +import torch_xla.core.xla_model as xm -+import torch_xla.distributed.parallel_loader as pl +import torch_xla.distributed.xla_multiprocessing as xmp def _mp_fn(index): ... + # Move the model paramters to your XLA device -+ model.to(xm.xla_device()) -+ -+ # MpDeviceLoader preloads data to the XLA device -+ xla_train_loader = pl.MpDeviceLoader(train_loader, xm.xla_device()) - -- for inputs, labels in train_loader: -+ for inputs, labels in xla_train_loader: - optimizer.zero_grad() - outputs = model(inputs) - loss = loss_fn(outputs, labels) - loss.backward() -- optimizer.step() -+ -+ # `xm.optimizer_step` combines gradients across replicas -+ xm.optimizer_step() ++ model.to(xla.device()) + + for inputs, labels in train_loader: ++ with xla.step(): ++ # Transfer data to the XLA device. This happens asynchronously. ++ inputs, labels = inputs.to(xla.device()), labels.to(xla.device()) + optimizer.zero_grad() + outputs = model(inputs) + loss = loss_fn(outputs, labels) + loss.backward() +- optimizer.step() ++ # `xm.optimizer_step` combines gradients across replicas ++ xm.optimizer_step(optimizer) if __name__ == '__main__': - mp.spawn(_mp_fn, args=(), nprocs=world_size) @@ -69,8 +67,7 @@ If you're using `DistributedDataParallel`, make the following changes: ```diff import torch.distributed as dist -import torch.multiprocessing as mp -+import torch_xla.core.xla_model as xm -+import torch_xla.distributed.parallel_loader as pl ++import torch_xla as xla +import torch_xla.distributed.xla_multiprocessing as xmp +import torch_xla.distributed.xla_backend @@ -89,15 +86,15 @@ If you're using `DistributedDataParallel`, make the following changes: - model = model.to(rank) - ddp_model = DDP(model, device_ids=[rank]) -+ xla_train_loader = pl.MpDeviceLoader(train_loader, xm.xla_device()) -- for inputs, labels in train_loader: -+ for inputs, labels in xla_train_loader: - optimizer.zero_grad() - outputs = ddp_model(inputs) - loss = loss_fn(outputs, labels) - loss.backward() - optimizer.step() + for inputs, labels in train_loader: ++ with xla.step(): ++ inputs, labels = inputs.to(xla.device()), labels.to(xla.device()) + optimizer.zero_grad() + outputs = ddp_model(inputs) + loss = loss_fn(outputs, labels) + loss.backward() + optimizer.step() if __name__ == '__main__': - mp.spawn(_mp_fn, args=(), nprocs=world_size) @@ -132,31 +129,36 @@ Our comprehensive user guides are available at: PyTorch/XLA releases starting with version r2.1 will be available on PyPI. You can now install the main build with `pip install torch_xla`. To also install the -Cloud TPU plugin, install the optional `tpu` dependencies: +Cloud TPU plugin, install the optional `tpu` dependencies after installing the main build with ``` pip install torch_xla[tpu] -f https://storage.googleapis.com/libtpu-releases/index.html ``` -GPU, XRT (legacy runtime), and nightly builds are available in our public GCS -bucket. +GPU and nightly builds are available in our public GCS bucket. | Version | Cloud TPU/GPU VMs Wheel | | --- | ----------- | -| 2.2 (Python 3.8) | `https://storage.googleapis.com/pytorch-xla-releases/wheels/tpuvm/torch_xla-2.2.0-cp38-cp38-manylinux_2_28_x86_64.whl` | -| 2.2 (Python 3.10) | `https://storage.googleapis.com/pytorch-xla-releases/wheels/tpuvm/torch_xla-2.2.0-cp310-cp310-manylinux_2_28_x86_64.whl` | -| 2.2 (CUDA 12.1 + Python 3.8) | `https://storage.googleapis.com/pytorch-xla-releases/wheels/cuda/12.1/torch_xla-2.2.0-cp38-cp38-manylinux_2_28_x86_64.whl` | -| 2.2 (CUDA 12.1 + Python 3.10) | `https://storage.googleapis.com/pytorch-xla-releases/wheels/cuda/12.1/torch_xla-2.2.0-cp310-cp310-manylinux_2_28_x86_64.whl` | +| 2.3 (Python 3.8) | `https://storage.googleapis.com/pytorch-xla-releases/wheels/tpuvm/torch_xla-2.3.0-cp38-cp38-manylinux_2_28_x86_64.whl` | +| 2.3 (Python 3.10) | `https://storage.googleapis.com/pytorch-xla-releases/wheels/tpuvm/torch_xla-2.3.0-cp310-cp310-manylinux_2_28_x86_64.whl` | +| 2.3 (CUDA 12.1 + Python 3.8) | `https://storage.googleapis.com/pytorch-xla-releases/wheels/cuda/12.1/torch_xla-2.3.0-cp38-cp38-manylinux_2_28_x86_64.whl` | +| 2.3 (CUDA 12.1 + Python 3.10) | `https://storage.googleapis.com/pytorch-xla-releases/wheels/cuda/12.1/torch_xla-2.3.0-cp310-cp310-manylinux_2_28_x86_64.whl` | | nightly (Python 3.8) | `https://storage.googleapis.com/pytorch-xla-releases/wheels/tpuvm/torch_xla-nightly-cp38-cp38-linux_x86_64.whl` | | nightly (Python 3.10) | `https://storage.googleapis.com/pytorch-xla-releases/wheels/tpuvm/torch_xla-nightly-cp310-cp310-linux_x86_64.whl` | | nightly (CUDA 12.1 + Python 3.8) | `https://storage.googleapis.com/pytorch-xla-releases/wheels/cuda/12.1/torch_xla-nightly-cp38-cp38-linux_x86_64.whl` | +You can also add `+yyyymmdd` after `torch_xla-nightly` to get the nightly wheel of a specified date. To get the companion pytorch nightly wheel, replace the `torch_xla` with `torch` on above wheel links. +
older versions | Version | Cloud TPU VMs Wheel | |---------|-------------------| +| 2.2 (Python 3.8) | `https://storage.googleapis.com/pytorch-xla-releases/wheels/tpuvm/torch_xla-2.2.0-cp38-cp38-manylinux_2_28_x86_64.whl` | +| 2.2 (Python 3.10) | `https://storage.googleapis.com/pytorch-xla-releases/wheels/tpuvm/torch_xla-2.2.0-cp310-cp310-manylinux_2_28_x86_64.whl` | +| 2.2 (CUDA 12.1 + Python 3.8) | `https://storage.googleapis.com/pytorch-xla-releases/wheels/cuda/12.1/torch_xla-2.2.0-cp38-cp38-manylinux_2_28_x86_64.whl` | +| 2.2 (CUDA 12.1 + Python 3.10) | `https://storage.googleapis.com/pytorch-xla-releases/wheels/cuda/12.1/torch_xla-2.2.0-cp310-cp310-manylinux_2_28_x86_64.whl` | | 2.1 (XRT + Python 3.10) | `https://storage.googleapis.com/pytorch-xla-releases/wheels/xrt/tpuvm/torch_xla-2.1.0%2Bxrt-cp310-cp310-manylinux_2_28_x86_64.whl` | | 2.1 (Python 3.8) | `https://storage.googleapis.com/pytorch-xla-releases/wheels/tpuvm/torch_xla-2.1.0-cp38-cp38-linux_x86_64.whl` | | 2.0 (Python 3.8) | `https://storage.googleapis.com/tpu-pytorch/wheels/tpuvm/torch_xla-2.0-cp38-cp38-linux_x86_64.whl` | @@ -202,25 +204,29 @@ wheels for `torch` and `torch_xla` at | --- | ----------- | | 2.0 | `https://storage.googleapis.com/tpu-pytorch/wheels/colab/torch_xla-2.0-cp310-cp310-linux_x86_64.whl` | -You can also add `+yyyymmdd` after `torch_xla-nightly` to get the nightly wheel -of a specified date. To get the companion pytorch and torchvision nightly wheel, -replace the `torch_xla` with `torch` or `torchvision` on above wheel links.
### Docker | Version | Cloud TPU VMs Docker | | --- | ----------- | +| 2.3 | `us-central1-docker.pkg.dev/tpu-pytorch-releases/docker/xla:r2.3.0_3.10_tpuvm` | | 2.2 | `us-central1-docker.pkg.dev/tpu-pytorch-releases/docker/xla:r2.2.0_3.10_tpuvm` | | 2.1 | `us-central1-docker.pkg.dev/tpu-pytorch-releases/docker/xla:r2.1.0_3.10_tpuvm` | | 2.0 | `gcr.io/tpu-pytorch/xla:r2.0_3.8_tpuvm` | | 1.13 | `gcr.io/tpu-pytorch/xla:r1.13_3.8_tpuvm` | | nightly python | `us-central1-docker.pkg.dev/tpu-pytorch-releases/docker/xla:nightly_3.10_tpuvm` | +To use the above dockers, please pass `--privileged --net host --shm-size=16G` along. Here is an example: +```bash +docker run --privileged --net host --shm-size=16G -it us-central1-docker.pkg.dev/tpu-pytorch-releases/docker/xla:nightly_3.10_tpuvm /bin/bash +``` +
| Version | GPU CUDA 12.1 Docker | | --- | ----------- | +| 2.3 | `us-central1-docker.pkg.dev/tpu-pytorch-releases/docker/xla:r2.3.0_3.10_cuda_12.1` | | 2.2 | `us-central1-docker.pkg.dev/tpu-pytorch-releases/docker/xla:r2.2.0_3.10_cuda_12.1` | | 2.1 | `us-central1-docker.pkg.dev/tpu-pytorch-releases/docker/xla:r2.1.0_3.10_cuda_12.1` | | nightly | `us-central1-docker.pkg.dev/tpu-pytorch-releases/docker/xla:nightly_3.8_cuda_12.1` | @@ -281,10 +287,10 @@ See the [contribution guide](CONTRIBUTING.md). ## Disclaimer -This repository is jointly operated and maintained by Google, Facebook and a +This repository is jointly operated and maintained by Google, Meta and a number of individual contributors listed in the [CONTRIBUTORS](https://github.com/pytorch/xla/graphs/contributors) file. For -questions directed at Facebook, please send an email to opensource@fb.com. For +questions directed at Meta, please send an email to opensource@fb.com. For questions directed at Google, please send an email to pytorch-xla@googlegroups.com. For all other questions, please open up an issue in this repository [here](https://github.com/pytorch/xla/issues). diff --git a/TROUBLESHOOTING.md b/TROUBLESHOOTING.md index 8f04e683822..22f6d01e374 100644 --- a/TROUBLESHOOTING.md +++ b/TROUBLESHOOTING.md @@ -56,11 +56,7 @@ report sent to us if you have it. ## PyTorch/XLA Debugging Tool -You can enable the PyTorch/XLA debugging tool by setting `PT_XLA_DEBUG=1`, which provides a couple useful debugging features. - -## PyTorch/XLA + Dynamo Debugging Tool - -You can enable the PyTorch/XLA + Dynamo debugging tool by setting `XLA_DYNAMO_DEBUG=1`. +You can enable the PyTorch/XLA debugging tool by setting `PT_XLA_DEBUG_LEVEL=2`, which provides a couple useful debugging features. You can also lower the debug level to `1` to slip the execution analysis. ### Perform A Auto-Metrics Analysis @@ -79,41 +75,44 @@ The debugging tool will analyze every compilation and execution for your model. ``` Compilation Analysis: ================================================================================ Compilation Analysis: Compilation Cause -Compilation Analysis: user mark_step -Compilation Analysis: Graph Info: -Compilation Analysis: Graph Hash: 537d4b0264b029688281412214d252e9 -Compilation Analysis: Number of Graph Inputs: 588 -Compilation Analysis: Number of Graph Outputs: 320 -Compilation Analysis: Python Frame Triggered Execution: -Compilation Analysis: mark_step (/workspaces/dk2/pytorch/xla/torch_xla/core/xla_model.py:840) -Compilation Analysis: broadcast_master_param (/workspaces/dk2/pytorch/xla/torch_xla/core/xla_model.py:1230) -Compilation Analysis: train_imagenet (/workspaces/dk2/pytorch/xla/test/test_train_mp_imagenet.py:261) -Compilation Analysis: _mp_fn (/workspaces/dk2/pytorch/xla/test/test_train_mp_imagenet.py:365) -Compilation Analysis: __call__ (/workspaces/dk2/pytorch/xla/torch_xla/_internal/pjrt.py:176) -Compilation Analysis: _thread_fn (/workspaces/dk2/pytorch/xla/torch_xla/_internal/pjrt.py:70) -Compilation Analysis: run (/usr/local/lib/python3.8/concurrent/futures/thread.py:57) -Compilation Analysis: _worker (/usr/local/lib/python3.8/concurrent/futures/thread.py:80) -Compilation Analysis: .......... +Compilation Analysis: mark_step in parallel loader at step end +Compilation Analysis: Graph Info: +Compilation Analysis: Graph Hash: c74c3b91b855b2b123f833b0d5f86943 +Compilation Analysis: Number of Graph Inputs: 35 +Compilation Analysis: Number of Graph Outputs: 107 +Compilation Analysis: Python Frame Triggered Execution: +Compilation Analysis: mark_step (/workspaces/dk3/pytorch/xla/torch_xla/core/xla_model.py:1055) +Compilation Analysis: next (/workspaces/dk3/pytorch/xla/torch_xla/distributed/parallel_loader.py:44) +Compilation Analysis: __next__ (/workspaces/dk3/pytorch/xla/torch_xla/distributed/parallel_loader.py:32) +Compilation Analysis: train_loop_fn (/workspaces/dk3/pytorch/xla/examples/train_decoder_only_base.py:48) +Compilation Analysis: start_training (/workspaces/dk3/pytorch/xla/examples/train_decoder_only_base.py:65) +Compilation Analysis: (/workspaces/dk3/pytorch/xla/examples/train_decoder_only_base.py:73) Compilation Analysis: -------------------------------------------------------------------------------- Compilation Analysis: ================================================================================ +Post Compilation Analysis: ================================================================================ +Post Compilation Analysis: Graph input size: 1.548000 GB +Post Compilation Analysis: Graph output size: 7.922460 GB +Post Compilation Analysis: Aliased Input size: 1.547871 GB +Post Compilation Analysis: Intermediate tensor size: 12.124478 GB +Post Compilation Analysis: Compiled program size: 0.028210 GB +Post Compilation Analysis: -------------------------------------------------------------------------------- +Post Compilation Analysis: ================================================================================ + Execution Analysis: ================================================================================ Execution Analysis: Execution Cause -Execution Analysis: user mark_step -Execution Analysis: Graph Info: -Execution Analysis: Graph Hash: 537d4b0264b029688281412214d252e9 -Execution Analysis: Number of Graph Inputs: 588 -Execution Analysis: Number of Graph Outputs: 320 -Execution Analysis: Python Frame Triggered Execution: -Execution Analysis: mark_step (/workspaces/dk2/pytorch/xla/torch_xla/core/xla_model.py:840) -Execution Analysis: broadcast_master_param (/workspaces/dk2/pytorch/xla/torch_xla/core/xla_model.py:1230) -Execution Analysis: train_imagenet (/workspaces/dk2/pytorch/xla/test/test_train_mp_imagenet.py:261) -Execution Analysis: _mp_fn (/workspaces/dk2/pytorch/xla/test/test_train_mp_imagenet.py:365) -Execution Analysis: __call__ (/workspaces/dk2/pytorch/xla/torch_xla/_internal/pjrt.py:176) -Execution Analysis: _thread_fn (/workspaces/dk2/pytorch/xla/torch_xla/_internal/pjrt.py:70) -Execution Analysis: run (/usr/local/lib/python3.8/concurrent/futures/thread.py:57) -Execution Analysis: _worker (/usr/local/lib/python3.8/concurrent/futures/thread.py:80) -Execution Analysis: .......... +Execution Analysis: mark_step in parallel loader at step end +Execution Analysis: Graph Info: +Execution Analysis: Graph Hash: c74c3b91b855b2b123f833b0d5f86943 +Execution Analysis: Number of Graph Inputs: 35 +Execution Analysis: Number of Graph Outputs: 107 +Execution Analysis: Python Frame Triggered Execution: +Execution Analysis: mark_step (/workspaces/dk3/pytorch/xla/torch_xla/core/xla_model.py:1055) +Execution Analysis: next (/workspaces/dk3/pytorch/xla/torch_xla/distributed/parallel_loader.py:44) +Execution Analysis: __next__ (/workspaces/dk3/pytorch/xla/torch_xla/distributed/parallel_loader.py:32) +Execution Analysis: train_loop_fn (/workspaces/dk3/pytorch/xla/examples/train_decoder_only_base.py:48) +Execution Analysis: start_training (/workspaces/dk3/pytorch/xla/examples/train_decoder_only_base.py:65) +Execution Analysis: (/workspaces/dk3/pytorch/xla/examples/train_decoder_only_base.py:73) Execution Analysis: -------------------------------------------------------------------------------- Execution Analysis: ================================================================================ ``` @@ -127,7 +126,7 @@ Some common causes of Compilation/Executation are The executation caused by 1-4 are expected, and we want to avoid 5 by either reduce the frequency of accessing tensor values or manually add a `mark_step` before accessing. -Users should expect to see this `Compilation Cause` + `Executation Cause` pairs for first couple steps. After the model stabilize users should expect to only see `Execution Cause`. To use PyTorch/XLA efficiently, we expect the same models code to be run for every step and compilation only happen once for every graph. If you keep seeing `Compilation Cause`, you should try to dump the IR/HLO following [this section](#common-debugging-environment-variables-combinations) and compare the graphs for each step and understand the source of the differences. +Users should expect to see this `Compilation Cause` + `Executation Cause` pairs for first couple steps. After the model stabilize users should expect to only see `Execution Cause`(you can disable execution analysis by `PT_XLA_DEBUG_LEVEL=1`). To use PyTorch/XLA efficiently, we expect the same models code to be run for every step and compilation only happen once for every graph. If you keep seeing `Compilation Cause`, you should try to dump the IR/HLO following [this section](#common-debugging-environment-variables-combinations) and compare the graphs for each step and understand the source of the differences. Following section will explain how to get and understand a more detail metrics report. @@ -192,6 +191,10 @@ import torch_xla.debug.metrics as met met.clear_all() ``` +## PyTorch/XLA + Dynamo Debugging Tool + +You can enable the PyTorch/XLA + Dynamo debugging tool by setting `XLA_DYNAMO_DEBUG=1`. + ## Performance Profiling To profile your workload in depth to understand bottlenecks please check the following resources: * [Official tutorial](https://cloud.google.com/tpu/docs/pytorch-xla-performance-profiling-tpu-vm) @@ -199,6 +202,9 @@ To profile your workload in depth to understand bottlenecks please check the fol * [Sample MNIST training script with profiling](https://github.com/pytorch/xla/blob/master/test/test_profile_mp_mnist.py) * [Utility script for capturing performance profiles](https://github.com/pytorch/xla/blob/master/scripts/capture_profile.py) +## Simple Benchmarking +Take a look at [`examples/train_resnet_benchmark.py`](https://github.com/pytorch/xla/blob/master/examples/train_resnet_benchmark.py) for how to benchmark a PyTorch/XLA model. + ## Known Performance Caveats PyTorch/XLA behaves semantically like regular PyTorch and XLA tensors share the full tensor interface with CPU & GPU tensors. @@ -331,25 +337,6 @@ only be enabled for debugging. by one. This is useful to bypass the long compilation time but overall step time will be a lot slower and memory usage will be higher since all compiler optimizaiton will be skipped. -* ```XLA_USE_BF16```: If set to 1, transforms all the _PyTorch_ _Float_ values into _BiFloat16_ - when sending to the _TPU_ device. Note that when using `XLA_USE_BF16=1` tensor arithmetic will - be done in reduced precision and so tensors will not be accurate if accumulated over time. - For example: - - ``` - # In reduced bfloat16 precision - >>> torch.tensor(4096, dtype=torch.bfloat16) + torch.tensor(1, dtype=torch.bfloat16) - tensor(4096., dtype=torch.bfloat16) - # Whereas in full float32 precision - >>> torch.tensor(4096) + torch.tensor(1) - tensor(4097) - ``` - So to get accurate metrics such as average loss value over many steps, use manual mixed - precision where metrics stay in FP32. - -* ```XLA_USE_F16```: If set to 1, transforms all the _PyTorch_ _Float_ values into _Float16_ - (_PyTorch_ _Half_ type) when sending to devices which supports them. - * ```TF_CPP_LOG_THREAD_ID```: If set to 1, the TF logs will show the thread ID helping with debugging multithreaded processes. diff --git a/WORKSPACE b/WORKSPACE index e4d8a73fdc0..5d0f2a7c931 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -31,6 +31,17 @@ python_configure( name = "local_config_python", python_version = "3", # required to use `python3-config` ) + +################################ PyTorch Setup ################################ + +load("//bazel:dependencies.bzl", "PYTORCH_LOCAL_DIR") + +new_local_repository( + name = "torch", + build_file = "//bazel:torch.BUILD", + path = PYTORCH_LOCAL_DIR, +) + ############################# OpenXLA Setup ############################### # To update OpenXLA to a new revision, @@ -38,6 +49,9 @@ python_configure( # b) get the sha256 hash of the commit by running: # curl -L https://github.com/openxla/xla/archive/.tar.gz | sha256sum # and update the sha256 with the result. + +xla_hash = '98db3e8c8f64dede911fd97605f76aaf6ede1153' + http_archive( name = "xla", patch_args = [ @@ -50,12 +64,42 @@ http_archive( "//openxla_patches:gpu_race_condition.diff", "//openxla_patches:f16_abi_clang.diff", ], - strip_prefix = "xla-1acf05ef0d41181caaf0cd691aa9d453ffc41a73", + strip_prefix = "xla-" + xla_hash, urls = [ - "https://github.com/openxla/xla/archive/1acf05ef0d41181caaf0cd691aa9d453ffc41a73.tar.gz", + "https://github.com/openxla/xla/archive/" + xla_hash + ".tar.gz", ], ) +# Initialize hermetic Python +load("@xla//third_party/py:python_init_rules.bzl", "python_init_rules") + +python_init_rules() + +load("@xla//third_party/py:python_init_repositories.bzl", "python_init_repositories") + +python_init_repositories( + requirements = { + "3.8": "//:requirements_lock_3_8.txt", + "3.9": "//:requirements_lock_3_9.txt", + "3.10": "//:requirements_lock_3_10.txt", + "3.11": "//:requirements_lock_3_11.txt", + }, + local_wheel_workspaces = ["@torch//:WORKSPACE"], + default_python_version = "system", +) + +load("@xla//third_party/py:python_init_toolchains.bzl", "python_init_toolchains") + +python_init_toolchains() + +load("@xla//third_party/py:python_init_pip.bzl", "python_init_pip") + +python_init_pip() + +load("@pypi//:requirements.bzl", "install_deps") + +install_deps() + # For development, one often wants to make changes to the OpenXLA repository as well # as the PyTorch/XLA repository. You can override the pinned repository above with a # local checkout by either: @@ -90,12 +134,3 @@ load("@xla//:workspace0.bzl", "xla_workspace0") xla_workspace0() -################################ PyTorch Setup ################################ - -load("//bazel:dependencies.bzl", "PYTORCH_LOCAL_DIR") - -new_local_repository( - name = "torch", - build_file = "//bazel:torch.BUILD", - path = PYTORCH_LOCAL_DIR, -) diff --git a/benchmarks/benchmark_experiment.py b/benchmarks/benchmark_experiment.py index fb5227a6972..26a56c49f24 100644 --- a/benchmarks/benchmark_experiment.py +++ b/benchmarks/benchmark_experiment.py @@ -22,6 +22,7 @@ def list_experiment_configs(self): "xla": [None, "PJRT", "XRT"], "xla_flags": [None], "dynamo": [None, "inductor", "openxla_eval", "openxla"], + "torch_xla2": [None], # options only apply to torch_xla2 "test": ["eval", "train"], } @@ -30,6 +31,9 @@ def list_experiment_configs(self): config_choices["accelerator"] = list(set(self._args.accelerator)) if self._args.xla: config_choices["xla"] = list(map(parse_none_str, set(self._args.xla))) + if self._args.torch_xla2: + config_choices["torch_xla2"] = list( + map(parse_none_str, set(self._args.torch_xla2))) if self._args.dynamo: config_choices["dynamo"] = list( map(parse_none_str, set(self._args.dynamo))) @@ -66,12 +70,17 @@ def _is_available(self, experiment_config): cfg_accelerator = experiment_config["accelerator"] cfg_xla = experiment_config["xla"] cfg_test = experiment_config["test"] + cfg_torch_xla2 = experiment_config["torch_xla2"] # Check that dynamo refers to an existing backend. if cfg_dynamo is not None and cfg_dynamo not in dynamo.list_backends( exclude_tags=()): return False + # torch_xla2 doesn't support dynamo at this time. + if cfg_dynamo is not None and cfg_torch_xla2: + return False + # Check dynamo backend-specifics constraints. if cfg_dynamo == "inductor": if cfg_accelerator == "tpu" or cfg_xla is not None: @@ -110,22 +119,26 @@ def load_experiment(self, experiment_config): dynamo = experiment_config["dynamo"] test = experiment_config["test"] batch_size = experiment_config.get("batch_size", self._args.batch_size) + torch_xla2 = experiment_config["torch_xla2"] return BenchmarkExperiment( accelerator=accelerator, xla=xla, xla_flags=xla_flags, dynamo=dynamo, + torch_xla2=torch_xla2, test=test, batch_size=batch_size) class BenchmarkExperiment: - def __init__(self, accelerator, xla, xla_flags, dynamo, test, batch_size): + def __init__(self, accelerator, xla, xla_flags, dynamo, torch_xla2, test, + batch_size): self.accelerator = accelerator self.xla = xla self.xla_flags = xla_flags self.dynamo = dynamo + self.torch_xla2 = torch_xla2 self.test = test self.batch_size = batch_size self.accelerator_model = get_accelerator_model(self.accelerator) @@ -138,6 +151,9 @@ def update_process_env(self, process_env): process_env.pop("XRT_TPU_CONFIG", None) process_env.pop("XLA_FLAGS", None) + if self.torch_xla2: + process_env["JAX_PLATFORMS"] = self.accelerator.lower() + if self.xla == "PJRT": process_env["PJRT_DEVICE"] = self.accelerator.upper() elif self.xla == "XRT": @@ -185,6 +201,7 @@ def to_dict(self): d["xla"] = self.xla d["xla_flags"] = self.xla_flags d["dynamo"] = self.dynamo + d["torch_xla2"] = self.torch_xla2 d["test"] = self.test d["batch_size"] = self.batch_size return d diff --git a/benchmarks/benchmark_model.py b/benchmarks/benchmark_model.py index 59a430d3982..62b53e126a0 100644 --- a/benchmarks/benchmark_model.py +++ b/benchmarks/benchmark_model.py @@ -5,6 +5,7 @@ import torch import torch.nn as nn from torch._dynamo.testing import collect_results +from torch.utils import _pytree as pytree from util import cast_to_dtype, move_to_device logger = logging.getLogger(__name__) @@ -110,14 +111,10 @@ def conversion_dtype(self): def prepare_for_experiment(self, dynamo_compilation_opts): self.device = self.benchmark_experiment.get_device() self.dtype = self.conversion_dtype() - if self.dtype is not None: self.module = self.module.to(self.dtype) self.example_inputs = cast_to_dtype(self.example_inputs, self.dtype) - self.module = self.module.to(self.device) - self.example_inputs = move_to_device(self.example_inputs, self.device) - if self.benchmark_experiment.test == "eval": self._prepare_for_eval() elif self.benchmark_experiment.test == "train": @@ -125,6 +122,32 @@ def prepare_for_experiment(self, dynamo_compilation_opts): else: raise NotImplementedError + if self.benchmark_experiment.torch_xla2: + import torch_xla2.export + import torch_xla2 + import jax + import jax.numpy as jnp + device = jax.devices()[0] + if self.benchmark_experiment.torch_xla2 == 'torch_export': + # for torch_xla2, we export model to FX graph and move weights to JAX device + exported = torch.export.export(self.module, self.example_inputs) + weights, jax_func = torch_xla2.export.exported_program_to_jax(exported) + elif self.benchmark_experiment.torch_xla2 == 'extract_jax': + weights, jax_func = torch_xla2.extract_jax(self.module) + else: + raise ValueError("torch_xla2 option unavailable") + weights = pytree.tree_map_only(jnp.ndarray, + lambda x: jax.device_put(x, device), + weights) + jax_func = jax.jit(jax_func) + self.module = lambda *x: jax_func(weights, x) + self.example_inputs = move_to_device(self.example_inputs, device, + self.benchmark_experiment.torch_xla2) + else: + self.module = self.module.to(self.device) + self.example_inputs = move_to_device(self.example_inputs, self.device, + self.benchmark_experiment.torch_xla2) + if self.benchmark_experiment.dynamo: compilation_opts = dynamo_compilation_opts.copy() compilation_opts['backend'] = self.benchmark_experiment.dynamo diff --git a/benchmarks/experiment_runner.py b/benchmarks/experiment_runner.py index 443a4067ac1..11719b476ec 100644 --- a/benchmarks/experiment_runner.py +++ b/benchmarks/experiment_runner.py @@ -103,6 +103,7 @@ def generate_and_run_all_configs(self): # TODO: See if we can pass experiment_cfg to `load_experiment`. benchmark_experiment = self.experiment_loader.load_experiment( experiment_cfg) + benchmark_model = self.model_loader.load_model( model_cfg, benchmark_experiment, dummy=True) @@ -221,7 +222,7 @@ def _default_iter_fn(self, benchmark_experiment, benchmark_model, tracing_time = time.perf_counter() - t_trace_start # Mark step. - self._mark_step(benchmark_experiment) + self._mark_step(benchmark_experiment, output) total_time = time.perf_counter() - total_time_start return output, total_time, tracing_time @@ -284,7 +285,10 @@ def run_once_and_gather_metrics(self, benchmark_experiment, benchmark_model, # Reset state and sync. reset_rng_state(benchmark_experiment) - self._mark_step(benchmark_experiment) + if benchmark_experiment.torch_xla2: + self._mark_step(benchmark_experiment, inputs_list) + else: + self._mark_step(benchmark_experiment) self._synchronize(benchmark_experiment) met.clear_all() dynamo_utils.counters.clear() @@ -307,7 +311,7 @@ def loop(pytorch_profile=None, iter_fn=None): total_timing += timing # Mark step. - self._mark_step(benchmark_experiment) + self._mark_step(benchmark_experiment, output) if pytorch_profile is not None: pytorch_profile.step() @@ -319,8 +323,8 @@ def loop(pytorch_profile=None, iter_fn=None): self._args.profile_cuda_cpu or \ self._args.profile_cuda_cpu_individual_ops enable_xla_profiling = self._args.profile_xla - assert not (enable_pytorch_profiling and enable_pytorch_profiling - ), "More than one profiling path enabled." + assert not (enable_pytorch_profiling and + enable_xla_profiling), "More than one profiling path enabled." if enable_xla_profiling: logdir = self._get_results_dir_path(experiment_config, model_config, @@ -414,9 +418,14 @@ def _prepare_inputs(self, example_inputs, should_randomize_input): inputs_list.append(inputs) return inputs_list - def _mark_step(self, benchmark_experiment): + def _mark_step(self, benchmark_experiment, tensors_to_check=None): if benchmark_experiment.xla: - xm.mark_step() + if benchmark_experiment.torch_xla2: + assert tensors_to_check is not None, "torch_xla2 requires input tensor to block_until_ready" + import jax + jax.block_until_ready(tensors_to_check) + else: + xm.mark_step() def _synchronize(self, benchmark_experiment): if benchmark_experiment.xla: @@ -859,6 +868,12 @@ def __str__(self): action="append", help="Flags to forward to XLA via `XLA_FLAGS` env var.", ) + parser.add_argument( + "--torch-xla2", + choices=["extract_jax", "torch_export"], + action="append", + help="Choose to use torch_xla2 and which mode to use.", + ) parser.add_argument( "--disable-tf32", action="store_true", diff --git a/benchmarks/requirements.txt b/benchmarks/requirements.txt new file mode 100644 index 00000000000..14e2549fec3 --- /dev/null +++ b/benchmarks/requirements.txt @@ -0,0 +1,3 @@ +tabulate +scipy +pandas diff --git a/benchmarks/result_analyzer.py b/benchmarks/result_analyzer.py index 358edc4230a..5b0cf7f4cd3 100644 --- a/benchmarks/result_analyzer.py +++ b/benchmarks/result_analyzer.py @@ -55,6 +55,7 @@ def run_csv(self): "xla": pd.Series(dtype="str"), "xla_flags": pd.Series(dtype="str"), "dynamo": pd.Series(dtype="str"), + "torch_xla2": pd.Series(dtype="str"), "test": pd.Series(dtype="str"), "batch_size": pd.Series(dtype="int"), "repeat": pd.Series(dtype="int"), @@ -116,6 +117,8 @@ def extract_metrics_jsonl(self, file): xla_value = "None" if xla is None else xla dynamo = dataline["experiment"]["dynamo"] dynamo_value = "None" if dynamo is None else dynamo + torch_xla2 = dataline["experiment"]["torch_xla2"] + torch_xla2_value = "None" if torch_xla2 is None else torch_xla2 test = dataline["experiment"]["test"] test_value = "None" if test is None else test outputs_file = dataline["experiment"].get("outputs_file", None) @@ -135,6 +138,7 @@ def extract_metrics_jsonl(self, file): "accelerator_model": dataline["experiment"]["accelerator_model"], "xla": xla_value, "dynamo": dynamo_value, + "torch_xla2": torch_xla2_value, "test": test_value, "outputs_file": outputs_file_value } @@ -175,6 +179,7 @@ def extract_metrics_csv(self, file, metric_df): "xla": dataline["experiment"]["xla"], "xla_flags": dataline["experiment"]["xla_flags"], "dynamo": dataline["experiment"]["dynamo"], + "torch_xla2": dataline["experiment"]["torch_xla2"], "test": dataline["experiment"]["test"], "batch_size": dataline["experiment"]["batch_size"], "repeat": dataline["repeat"], diff --git a/benchmarks/run_benchmark.sh b/benchmarks/run_benchmark.sh index fd8a055bccc..e4e483947d9 100644 --- a/benchmarks/run_benchmark.sh +++ b/benchmarks/run_benchmark.sh @@ -5,7 +5,7 @@ LOGFILE=/tmp/benchmark_test.log # Note [Keep Going] # -# Set the `CONTINUE_ON_ERROR` flag to `true` to make the CircleCI tests continue on error. +# Set the `CONTINUE_ON_ERROR` flag to `true` to make the CI tests continue on error. # This will allow you to see all the failures on your PR, not stopping with the first # test failure like the default behavior. CONTINUE_ON_ERROR="${CONTINUE_ON_ERROR:-0}" diff --git a/benchmarks/torchbench_model.py b/benchmarks/torchbench_model.py index 741463ec65f..838a5014187 100644 --- a/benchmarks/torchbench_model.py +++ b/benchmarks/torchbench_model.py @@ -224,7 +224,7 @@ def _cleanup(self): gc.collect() # If we are using CUDA, clean-up its cache left-over. - if self.benchmark_experiment.accelerator == "cuda": + if self.is_accelerator_cuda(): torch.cuda.empty_cache() def set_up(self): @@ -246,14 +246,16 @@ def set_up(self): benchmark = self.load_benchmark() self.module, self.example_inputs = benchmark.get_module() - + if isinstance(self.example_inputs, + dict) and "input_ids" in self.example_inputs: + self.example_inputs = (self.example_inputs['input_ids'],) self.benchmark_experiment.batch_size = benchmark.batch_size # Move the initialized model to XLA device. if self.benchmark_experiment.xla: # First, move the model and the inputs to CPU. # This avoids having dupplicated data on CUDA. - if self.benchmark_experiment.accelerator == "cuda": + if self.is_accelerator_cuda(): self.module = self.module.to("cpu") self.example_inputs = move_to_device(self.example_inputs, "cpu") self._cleanup() @@ -305,8 +307,9 @@ def load_benchmark(self): # torch.backends.__allow_nonbracketed_mutation_flag = True # torchbench uses `xla` as device instead of `tpu` - if (device := self.benchmark_experiment.accelerator) == 'tpu': - device = str(self.benchmark_experiment.get_device()) + device = ( + str(self.benchmark_experiment.get_device()) + if self.is_accelerator_tpu() else self.benchmark_experiment.accelerator) return self.benchmark_cls()( test=self.benchmark_experiment.test, @@ -330,6 +333,12 @@ def is_inference(self): def is_training(self): return self.benchmark_experiment.test == "train" + def is_accelerator_cuda(self): + return self.benchmark_experiment.accelerator == "cuda" + + def is_accelerator_tpu(self): + return self.benchmark_experiment.accelerator == "tpu" + def use_amp(self): return self.is_training( ) or self.model_name in FORCE_AMP_FOR_FP16_BF16_MODELS @@ -350,23 +359,27 @@ def conversion_dtype(self): def _get_autocast_with_kwargs(self): kwargs = {} - if self.use_amp(): - # Set the default data-type based on the accelerator. - if self.benchmark_experiment.accelerator == "cuda": + # TODO: Should call device specific autocast implementations. + # Specifically, we should be using: + # - torch.cuda.amp.autocast for inductor + # - torch_xla.amp.autocast for PyTorch/XLA experiments. + # PyTorch/XLA autocast does not run with dynamo, though: + # https://github.com/pytorch/xla/issues/6511 + if self.is_accelerator_cuda(): + # For inductor and XLA:CUDA, we use CUDA autocast. + autocast = torch.cuda.amp.autocast kwargs["dtype"] = torch.float16 - else: - # Both CPU and TPU autocast mode defaults to bfloat16. - kwargs["dtype"] = torch.bfloat16 - - if self.benchmark_experiment.xla: - # Should call device specific autocast implementations. - # PyTorch/XLA autocast does not run with dynamo, though: - # https://github.com/pytorch/xla/issues/6511 + elif self.is_accelerator_tpu(): autocast = torch.amp.autocast kwargs["device_type"] = "xla" + kwargs["dtype"] = torch.bfloat16 else: - autocast = torch.cuda.amp.autocast + # Error: AMP is only supported on XLA:CUDA and XLA:TPU. + name = self.model_name + accelerator = self.benchmark_experiment.accelerator + raise RuntimeError(f"Tried to run {name} with AMP on {accelerator}. " + "However, AMP is only supported on cuda and tpu.") else: autocast = contextlib.nullcontext return (autocast, kwargs) diff --git a/benchmarks/util.py b/benchmarks/util.py index ce56ceb4143..8ab1d5a0181 100644 --- a/benchmarks/util.py +++ b/benchmarks/util.py @@ -50,7 +50,7 @@ def reset_rng_state(benchmark_experiment=None): torch.manual_seed(1337) random.seed(1337) np.random.seed(1337) - if benchmark_experiment is not None and benchmark_experiment.xla is not None: + if benchmark_experiment is not None and benchmark_experiment.xla is not None and benchmark_experiment.torch_xla2 is not None: device = benchmark_experiment.get_device() xm.set_rng_state(1337, str(device)) @@ -76,8 +76,15 @@ def is_xla_device_available(devkind): return r.returncode == 0 -def move_to_device(item, device): - return pytree.tree_map_only(torch.Tensor, lambda t: t.to(device), item) +def move_to_device(item, device, torch_xla2=False): + if torch_xla2: + import torch_xla2 + import jax + move_to_device_func = lambda t: jax.device_put( + torch_xla2.tensor.t2j(t), device) + else: + move_to_device_func = lambda t: t.to(device) + return pytree.tree_map_only(torch.Tensor, move_to_device_func, item) def cast_to_dtype(item, dtype): diff --git a/build_util.py b/build_util.py index 78e4bd5e453..487f5116323 100644 --- a/build_util.py +++ b/build_util.py @@ -36,10 +36,6 @@ def bazel_options_from_env() -> Iterable[str]: bazel_flags.append('--remote_default_exec_properties=cache-silo-key=%s' % cache_silo_name) - if check_env_flag('BUILD_CPP_TESTS', default='0'): - bazel_flags.append('//test/cpp:all') - bazel_flags.append('//torch_xla/csrc/runtime:all') - bazel_jobs = os.getenv('BAZEL_JOBS', default='') if bazel_jobs: bazel_flags.append('--jobs=%s' % bazel_jobs) diff --git a/codegen/BUILD b/codegen/BUILD index ab7bbe4c3af..79ae421f920 100644 --- a/codegen/BUILD +++ b/codegen/BUILD @@ -8,6 +8,10 @@ py_binary( "//torch_xla/csrc:aten_xla_type.cpp", "@torch//:torchgen_deps", ], + deps = [ + "@pypi_torch//:pkg", + "@pypi_pyyaml//:pkg", + ], tags = [ "local", "no-remote-exec", diff --git a/codegen/xla_native_functions.yaml b/codegen/xla_native_functions.yaml index 199025dc7e1..de5500a0c5b 100644 --- a/codegen/xla_native_functions.yaml +++ b/codegen/xla_native_functions.yaml @@ -361,6 +361,7 @@ supported: - zero_ - _native_batch_norm_legit - _native_batch_norm_legit.no_stats + - _embedding_bag_forward_only # Note: [functionalization and CompositeExplicitAutograd] # Below are all operators that are "composite" in core, # but require us to explicitly re-enable functionalization in order to use them. diff --git a/configuration.yaml b/configuration.yaml index a2bb9da6de7..1ea15dca81a 100644 --- a/configuration.yaml +++ b/configuration.yaml @@ -122,27 +122,6 @@ variables: XLANativeFunctions::_copy_from. type: bool default_value: true - XLA_USE_BF16: - description: - - Tensor arithmetic will be done in reduced precision and so tensors - will not be accurate if accumulated over time. - type: bool - default_value: false - XLA_USE_F16: - description: - - If set to true, transforms all the PyTorch Float values into Float16 - (PyTorch Half type) when sending to devices which supports them. - type: bool - default_value: false - XLA_USE_32BIT_LONG: - description: - - If set to true, maps PyTorch Long types to XLA 32bit type. On the - versions of the TPU HW at the time of writing, 64bit integer - computations are expensive, so setting this flag might help. It - should be verified by the user that truncating to 32bit values is a - valid operation according to the use of PyTorch Long values in it. - type: bool - default_value: false XLA_IO_THREAD_POOL_SIZE: description: - Number of threads for the IO thread pool in the XLA client. Defaults diff --git a/contrib/vscode/settings.json b/contrib/vscode/settings.json index 59b86e622e7..b09fba227e6 100644 --- a/contrib/vscode/settings.json +++ b/contrib/vscode/settings.json @@ -14,9 +14,19 @@ "coverage-gutters.coverageFileNames": [ "./bazel-out/_coverage/_coverage_report.dat" ], - "lcov.path": [ - "./bazel-out/_coverage/_coverage_report.dat" + "git.detectSubmodules": false, + "[python]": { + "editor.defaultFormatter": "eeyore.yapf", + "editor.formatOnSave": true, + }, + "python.analysis.exclude": [ + "**/third_party", + "**/build", + "**/__pycache__", + "**/.git", ], - "python.formatting.provider": "yapf", - "editor.formatOnSave": true + "[cpp]": { + "editor.defaultFormatter": "xaver.clang-format", + "editor.formatOnSave": true, + } } diff --git a/docs/README.md b/docs/README.md index 33a0ce5bc36..88ab7f44f03 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,25 +1,25 @@ ## Publish documentation for a new release. -CircleCI job `pytorch_xla_linux_debian11_and_push_doc` is specified to run on `release/*` branches, but it was not +CI job `pytorch_xla_linux_debian11_and_push_doc` is specified to run on `release/*` branches, but it was not run on release branches due to "Only build pull requests" setting. Turning off "Only build pull requests" will result in much larger volumes in jobs which is often unnecessary. We're waiting for [this feature request](https://ideas.circleci.com/ideas/CCI-I-215) to be implemented so that we could override this setting on some branches. Before the feature is available on CircleCi side, we'll use a manual process to publish documentation for release. -[Documentation for master branch](http://pytorch.org/xla/master/) is still updated automatically by the CircleCI job. +[Documentation for master branch](http://pytorch.org/xla/master/) is still updated automatically by the CI job. But we'll need to manually commit the new versioned doc and point http://pytorch.org/xla to the documentation of new stable release. -Take 1.5 release as example: +Take 2.3 release as example: ``` -# Build pytorch/pytorch:release/1.5 and pytorch/xla:release/1.5 respectively. +# Build pytorch/pytorch:release/2.3 and pytorch/xla:release/2.3 respectively. # In pytorch/xla/docs ./docs_build.sh git clone -b gh-pages https://github.com/pytorch/xla.git /tmp/xla -cp -r build/* /tmp/xla/release/1.5 +cp -r build/* /tmp/xla/release/2.3 cd /tmp/xla # Update `redirect_url` in index.md git add . -git commit -m "Publish 1.5 documentation." +git commit -m "Publish 2.3 documentation." git push origin gh-pages -``` \ No newline at end of file +``` diff --git a/docs/assets/ci_test_dependency.png b/docs/assets/ci_test_dependency.png new file mode 100644 index 0000000000000000000000000000000000000000..e4b2c397ba0d3b42ac7c665bb39d21af96dd545c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YkYFp--GQQCB!NzCO+hoR9qW2!+Qfet}P z3Bharw?4_0jLZiufDLwmGW7I?GqpAdiOC6;IRB;A$eWdzIEiu7lv&9dUrhdgVd|=+ zV{%A`7+GLeH0}a|#KFj3^DnPtDrM}dnCbFi;rM1LkPBK*Rq!Ih$CeeDrG(K@{1J-q zU+Jo>N60X*P`o$-AFig6&xL4ELD=F9YH|oQ1&?8bCM;gMA=1NI?{V7HHZ3(8AH5d| z!QCtd4*h=+7N72&s2}%4YOvwE2Uj$`gaZeRoOkraj}x*L3Py5obf_8`P`_xp9T0P& zNE8ZwfL;pAFoGT^sgr_`v+q@WEY}7e6o*0N=^8|yI*Ah+r_^Xp;aad5A}nbK_S=7= zqRDs6?;k(9JK1prwk6T$D3^-;jEA5BK+!q*Tbi#* zFWft7c@J5A*g1Ik*uOvF+x)d!NBmT(0v42p4X$r2m((y`PcDYdsp9CNNX{=hUQbO-Tb7277@b^Zy*1>{mBNeH+}^ zLY^L>ul_YPTKlfdA_Pa175^t*{eO(@jBi~Wj}UHbio-{^3*5K=guH*%QUG8Kd%-33 n|2ek*zwEe8{{Qx}fBK79I5*Cwarm__9{kf()m14|wh8?&2_;^n literal 0 HcmV?d00001 diff --git a/docs/assets/ci_test_dependency_gpu.png b/docs/assets/ci_test_dependency_gpu.png new file mode 100644 index 0000000000000000000000000000000000000000..68cd77ec90c689ce3e65737b270c4f149af54bd5 GIT binary patch literal 50628 zcmZ5|1z1#F+wOpb($Wno0>V(zU6LZ*E#S~KbeDoiNq0$icXtfk9m3Ec-Ep?>`+whm z&hgrpd#;(iS3K)k&$HHj--}>Hc_~aZQZx_Oay@tnx7*A-;jQIM*-Xr z9F(QRK&2z(yC4uXNalm6sw=`li>V{N)WX$p-$Q5ocEIX}pio_U-yFD?n5=oukTCh; zu=}unpR;d&QU4EL2^%e$6*-8hgBboi3gp+HK=T!8kat@tVcZNll9|_(M`yO@^a-;B z0^t~ha7?8LDLVoGrhRhD3})3bx5q-sY&8*zLFynzUxIe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K+UCZK>@;TF3W)=MS45cR}_jzJeCx~M2l=&lJ{eF>FRMGNcXljZ%vX@YoI%b9H zavQT^LCV=)_P#wU%HSKP;&a|cojxg;Ot}hMWdHlO`HB#W2hs`JT|bL|F{ESN!SZio zc|fzDO#JoLlNhWn<*zCXG5y(&**X^W?Ilka4cyd}ORTor4jpyG{QVQ}r?KVc*X!iR z^he{zzkqO(H>*CXmYTn+Jr)g7q-#e(p&4QgShpiM94~`~J}%eLdBkV7YWlTs6W6tF zPVQ0u-NDP}ZPREQ)~*sp9+m^^$>d`quz_vQUr`adV7hmSe zKF7;e?CU!^z7=M2o4|F=pjw61MIs@e(u$=fM1k6MiCp6M4`G9Rg{p@s=MCZ>> import torch +>>> init = torch.tensor([0], dtype=torch.int32) +>>> one_value = torch.ones(1, dtype=torch.int32) +>>> +>>> for i in range(10): +... init = init + one_value +... +>>> init +tensor([10], dtype=torch.int32) +``` + +### simple example with `while_loop`: +```bash +# PJRT_DEVICE=TPU python +>>> import torch +>>> import torch_xla +>>> import torch_xla.experimental.fori_loop +>>> from torch_xla.experimental.fori_loop import fori_loop +>>> from torch._higher_order_ops.while_loop import while_loop +>>> import torch_xla.core.xla_model as xm +>>> import torch_xla.core.xla_builder as xb +>>> +>>> device = xm.xla_device() +>>> +>>> def cond_fn(init, limit_value): +... return limit_value[0] >= init[0] +... +>>> def body_fn(init, limit_value): +... one_value = torch.ones(1, dtype=torch.int32, device=device) +... return (torch.add(init, one_value), limit_value.clone()) +... +>>> init = torch.tensor([0], dtype=torch.int32, device=device) +>>> limit_value = torch.tensor([10], dtype=torch.int32, device=device) +>>> res_, limit_value_ = while_loop(cond_fn, body_fn, (init, limit_value)) +>>> res_ +FunctionalTensor(lvl=0, value=\ +tensor([11], device='xla:0', dtype=torch.int32)) +``` + +### simple example with `fori_loop`: +```bash +# PJRT_DEVICE=TPU python +>>> import torch +>>> import torch_xla +>>> import torch_xla.experimental.fori_loop +>>> from torch_xla.experimental.fori_loop import fori_loop +>>> from torch._higher_order_ops.while_loop import while_loop +>>> import torch_xla.core.xla_model as xm +>>> import torch_xla.core.xla_builder as xb +>>> +>>> device = xm.xla_device() +>>> +>>> lower = torch.tensor([2], dtype=torch.int32, device=device) +>>> upper = torch.tensor([52], dtype=torch.int32, device=device) +>>> plus_value = torch.tensor([1], dtype=torch.int32, device=device) +>>> init_val = torch.tensor([1], dtype=torch.int32, device=device) +>>> +>>> def body_fun(*argus): +... plus_value, init_val = argus +... return plus_value, torch.add(plus_value, init_val) +... +>>> _, _, _, res_ = fori_loop(upper, lower, body_fun, plus_value, init_val) +>>> res_ +tensor([51], device='xla:0', dtype=torch.int32) +``` + +For more example and detailed user guide, please read [this test file](https://github.com/pytorch/xla/blob/master/test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py). PyTorch/XLA would include `while_loop` support in 2.3 for simple test case, complex test case and support for `fori_loop` and `scan` would be added after 2.3 diff --git a/docs/fsdpv2.md b/docs/fsdpv2.md index 28d15ec6936..fe9b782a082 100644 --- a/docs/fsdpv2.md +++ b/docs/fsdpv2.md @@ -1,6 +1,6 @@ # Fully Sharded Data Parallel via SPMD -Fully Sharded Data Parallel via SPMD or FSDPv2 is an utility that re-epxresses the famous FSDP algorithm in SPMD. [This](https://github.com/pytorch/xla/blob/master/torch_xla/experimental/spmd_fully_sharded_data_parallel.py) is +Fully Sharded Data Parallel via SPMD or FSDPv2 is an utility that re-expresses the famous FSDP algorithm in SPMD. [This](https://github.com/pytorch/xla/blob/master/torch_xla/experimental/spmd_fully_sharded_data_parallel.py) is an experimental feature that aiming to offer a familiar interface for users to enjoy all the benefits that SPMD brings into the table. The design doc is [here](https://github.com/pytorch/xla/issues/6379). @@ -18,7 +18,7 @@ num_devices = xr.global_runtime_device_count() mesh_shape = (num_devices, 1) device_ids = np.array(range(num_devices)) # To be noted, the mesh must have an axis named 'fsdp', which the weights and activations will be sharded on. -mesh = Mesh(device_ids, mesh_shape, ('fsdp', 'model')) +mesh = xs.Mesh(device_ids, mesh_shape, ('fsdp', 'model')) # Shard the input, and assume x is a 2D tensor. x = xs.mark_sharding(x, mesh, ('fsdp', None)) @@ -31,8 +31,20 @@ loss = output.sum() loss.backward() optim.step() ``` -It is also possible to shard individual layers separately and have an outer wrapper handle any leftover parameters. The autowrapping -feature will come in the future releases. +It is also possible to shard individual layers separately and have an outer wrapper handle any leftover parameters. Here is an example to autowrap each `DecoderLayer`. +```python3 +from torch_xla.distributed.fsdp.wrap import transformer_auto_wrap_policy + +# Apply FSDP sharding on each DecoderLayer layer. +auto_wrap_policy = functools.partial( + transformer_auto_wrap_policy, + transformer_layer_cls={ + decoder_only_model.DecoderLayer + }, +) +model = FSDPv2( + model, mesh=mesh, auto_wrap_policy=auto_wrap_policy) +``` ## Sharding output diff --git a/docs/gpu.md b/docs/gpu.md index c2678164f4e..de1cf807361 100644 --- a/docs/gpu.md +++ b/docs/gpu.md @@ -71,9 +71,12 @@ source ~/.bashrc ### Wheel ``` -pip3 install torch==2.2.0 -pip3 install https://storage.googleapis.com/pytorch-xla-releases/wheels/cuda/12.1/torch_xla-2.2.0-cp38-cp38-manylinux_2_28_x86_64.whl +pip3 install torch==2.3.0 +# GPU whl for python 3.10 + cuda 12.1 +pip3 install https://storage.googleapis.com/pytorch-xla-releases/wheels/cuda/12.1/torch_xla-2.3.0-cp310-cp310-manylinux_2_28_x86_64.whl ``` +Wheels for other Python version and CUDA version can be found [here](https://github.com/pytorch/xla?tab=readme-ov-file#available-docker-images-and-wheels). + ## Run a simple model In order to run below examples, you need to clone the pytorch/xla repo to access the imagenet example(We already clone it in our docker). diff --git a/docs/pallas.md b/docs/pallas.md new file mode 100644 index 00000000000..46c80b79f2e --- /dev/null +++ b/docs/pallas.md @@ -0,0 +1,57 @@ +# Custom Kernels via Pallas + +With the rise of OpenAI [triton](https://openai.com/research/triton), custom kernels become more and more popular in the GPU community, for instance, the introduction of [FlashAttention](https://github.com/Dao-AILab/flash-attention) and [PagedAttention](https://blog.vllm.ai/2023/06/20/vllm.html). In order to provide the feature parity in the TPU world, Google has introduced [Pallas](http://go/jax-pallas) and [Mosaic](http://go/mosaic-tpu). For PyTorch/XLA to continue pushing the performance in TPU, we have to support custom kernels, and the best way is through Pallas and Mosaic. The design doc is [TBA](). + +Let's assume you have a Pallas kernel defined as follow: +```python3 +import jax +from jax.experimental import pallas as pl +import jax.numpy as jnp + +def add_vectors_kernel(x_ref, y_ref, o_ref): + x, y = x_ref[...], y_ref[...] + o_ref[...] = x + y + +@jax.jit +def add_vectors(x: jax.Array, y: jax.Array) -> jax.Array: + return pl.pallas_call(add_vectors_kernel, + out_shape=jax.ShapeDtypeStruct(x.shape, x.dtype) + )(x, y) +``` + +## Adopt the above kernel to be compatible with PyTorch/XLA + +Example usage: +```python3 +q = torch.randn(3, 2, 128, 4).to("xla") +k = torch.randn(3, 2, 128, 4).to("xla") +v = torch.randn(3, 2, 128, 4).to("xla") + +# Adopts any Pallas kernel +from torch_xla.experimental.custom_kernel import make_kernel_from_pallas +pt_kernel = make_kernel_from_pallas(add_vectors, lambda x, y: [(x.shape, x.dtype)]) +output = pt_kernel(q, k) +``` +For simple kernels, the adoption is just as simple as one liner. For more complicated kernels, you can refer to our Flash Attention implementation for details. + +## Use built-in kernels + +Besides manually wrapping external Pallas kernels, there are built-in kernels where the adoptions are done by PyTorch/XLA already. + +Example usage: +```python3 +# Use built-in kernels +from torch_xla.experimental.custom_kernel import flash_attention +output = flash_attention(q, k, v) +``` + +You can just use it like any other torch.ops. + +## HuggingFace Llama 3 Example +We have a fork of HF Llama 3 to demonstrate a potential integration [here](https://github.com/pytorch-tpu/transformers/tree/alanwaketan/flash_attention). + +## Dependencies +The Pallas integration depends on JAX to function. However, not every JAX version is compatible with your installed PyTorch/XLA. To install the proper JAX: +```bash +pip install torch_xla[pallas] -f https://storage.googleapis.com/jax-releases/jax_nightly_releases.html -f https://storage.googleapis.com/jax-releases/jaxlib_nightly_releases.html +``` diff --git a/docs/requirements.txt b/docs/requirements.txt index 26f491f6c15..0d0f871b154 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,6 +1,6 @@ mistune==0.8.4 -sphinx==2.4.4 +sphinx==5.3.0 docutils==0.16 -Jinja2<3.1 +Jinja2==3.1.3 m2r -e git+https://github.com/pytorch/pytorch_sphinx_theme.git#egg=pytorch_sphinx_theme diff --git a/docs/spmd.md b/docs/spmd.md index 5d6e554092d..00e384e496c 100644 --- a/docs/spmd.md +++ b/docs/spmd.md @@ -297,7 +297,7 @@ checkpointing directly to any fsspec-compatible filesystem, including GCS. Example usage of the CheckpointManager is below: ```python -from torch_xla.experimental.distributed_checkpoint import CheckpointManager +from torch_xla.experimental.distributed_checkpoint import CheckpointManager, prime_optimizer # Create a CheckpointManager to checkpoint every 10 steps into GCS. chkpt_mgr = CheckpointManager('gs://my-bucket/my-experiment', 10) @@ -307,9 +307,13 @@ tracked_steps = chkpt_mgr.all_steps() if tracked_steps: # Choose the highest step best_step = max(tracked_steps) - state_dict = {'model': model.state_dict()} + # Before restoring the checkpoint, the optimizer state must be primed + # to allow state to be loaded into it. + prime_optimizer(optim) + state_dict = {'model': model.state_dict(), 'optim': optim.state_dict()} chkpt_mgr.restore(best_step, state_dict) model.load_state_dict(state_dict['model']) + optim.load_state_dict(state_dict['optim']) # Call `save` or `save_async` every step within the train loop. These methods # return True when a checkpoint is taken. @@ -320,6 +324,18 @@ for step, data in enumerate(dataloader): print(f'Checkpoint taken at step {step}') ``` +##### Restoring Optimizer State + +In distributed checkpointing, the state_dicts are loaded in-place, and only the +required shards of the checkpoint are loaded. Since optimizer states are lazily +created, the state isn't present until the first `optimizer.step` call, and +attempts to load an unprimed optimizer will fail. + +The utility method `prime_optimizer` is provided for this: it runs a fake train +step by setting all gradients to zero and calling `optimizer.step`. *This is a +destructive method and will touch both model parameters and optimizer state*, +so it should only be called just prior to restoration. + ### Process Groups To use `torch.distributed` APIs such as distributed checkpointing, a process group is required. In SPMD mode, the `xla` backend is not supported since the @@ -410,11 +426,11 @@ The SPMD API is general enough to express both data parallelism and model parall num_devices = xr.global_runtime_device_count() # Assume data is 4d and 0th dimension is the batch dimension -mesh_shape = (num_devices, 1, 1, 1) -input_mesh = xs.Mesh(device_ids, mesh_shape, ('B', 'C', 'W', 'H')) -partition_spec = range(num_devices) +mesh_shape = (num_devices,) +input_mesh = xs.Mesh(device_ids, mesh_shape, ('Data')) +partition_spec = ('data', None, None, None) -# Shard the batch dimension +# Shard the input's batch dimension along the `data` axis, no sharding along other dimensions xs.mark_sharding(input_tensor, input_mesh, partition_spec) ``` @@ -424,9 +440,9 @@ PyTorch/XLA’s MpDeviceLoader supports input batch sharding, which also loads t num_devices = xr.global_runtime_device_count() # Assume data is 4d and 0th dimension is the batch dimension -mesh_shape = (num_devices, 1, 1, 1) -input_mesh = xs.Mesh(device_ids, mesh_shape, ('B', 'C', 'W', 'H')) -partition_spec = range(num_devices) +mesh_shape = (num_devices) +input_mesh = xs.Mesh(device_ids, mesh_shape, ('Data')) +partition_spec = ('data', None, None, None) # Use MpDeviceLoader to load data in background train_loader = pl.MpDeviceLoader( @@ -444,10 +460,13 @@ PyTorch’s FSDP is data parallel + sharded model parameters at 0th dimension. U ```python for name, param in model.named_parameters(): - shape = (num_devices,) + (1,) * (len(param.shape) - 1) - mesh = xs.Mesh(device_ids, shape) - xs.mark_sharding(param, mesh, range(len(param.shape))) + shape = (num_devices,) + mesh = xs.Mesh(device_ids, shape, ('fsdp')) + partition_spec = [None] * len(param.shape) + partition_spec[0] = 'fsdp' + xs.mark_sharding(param, mesh, partition_spec) ``` +PyTorch/XLA also provided a convenient wrapper for the FSDP with SPMD, please take a look at this [user guide](https://github.com/pytorch/xla/blob/master/docs/fsdpv2.md). ### Running Resnet50 example with SPMD @@ -470,6 +489,7 @@ Note that I used a batch size 4 times as large since I am running it on a TPU v4 We provide a `shard placement visualization debug tool` for PyTorch/XLA SPMD user on TPU/GPU/CPU with single-host/multi-host: you could use `visualize_tensor_sharding` to visualize sharded tensor, or you could use `visualize_sharding` to visualize sharing string. Here are two code examples on TPU single-host(v4-8) with `visualize_tensor_sharding` or `visualize_sharding`: - Code snippet used `visualize_tensor_sharding` and visualization result: + ```python import rich @@ -482,7 +502,9 @@ from torch_xla.distributed.spmd.debugging import visualize_tensor_sharding generated_table = visualize_tensor_sharding(t, use_color=False) ``` ![alt_text](assets/spmd_debug_1.png "visualize_tensor_sharding example on TPU v4-8(single-host)") + - Code snippet used `visualize_sharding` and visualization result: + ```python from torch_xla.distributed.spmd.debugging import visualize_sharding sharding = '{devices=[2,2]0,1,2,3}' @@ -498,11 +520,13 @@ We are introducing a new PyTorch/XLA SPMD feature, called ``auto-sharding``, [RF PyTorch/XLA auto-sharding can be enabled by one of the following: - Setting envvar `XLA_SPMD_AUTO=1` - Calling the SPMD API in the beginning of your code: + ```python import torch_xla.runtime as xr xr.use_spmd(auto=True) ``` - Calling `pytorch.distributed._tensor.distribute_module` with `auto-policy` and `xla`: + ```python import torch_xla.runtime as xr from torch.distributed._tensor import DeviceMesh, distribute_module diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 00000000000..1ad0018c981 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,17 @@ +## Overview +This repo aims to provide some basic examples of how to run an existing pytorch model with PyTorch/XLA. `train_resnet_base.py` is a minimal trainer to run ResNet50 with fake data on a single device. `train_decoder_only_base.py` is similar to `train_resnet_base.py` but with a decoder only model. + +Other examples will import the `train_resnet_base` or `train_decoder_only_base` and demonstrate how to enable different features(distributed training, profiling, dynamo etc) on PyTorch/XLA.The objective of this repository is to offer fundamental examples of executing an existing PyTorch model utilizing PyTorch/XLA. + +## Setup +Follow our [README](https://github.com/pytorch/xla#getting-started) to install latest release of torch_xla. Check out this [link](https://github.com/pytorch/xla#python-packages) for torch_xla at other versions. To install the nightly torchvision(required for the resnet) you can do + +```shell +pip install --no-deps --pre torchvision -i https://download.pytorch.org/whl/nightly/cu118 +``` + +## Run the example +You can run all models directly. Only environment you want to set is `PJRT_DEVICE`. +``` +PJRT_DEVICE=TPU python fsdp/train_decoder_only_fsdp_v2.py +``` diff --git a/examples/data_parallel/README.md b/examples/data_parallel/README.md new file mode 100644 index 00000000000..2be94bce14e --- /dev/null +++ b/examples/data_parallel/README.md @@ -0,0 +1,2 @@ +## Recommendation +Please consider using `train_resnet_spmd_data_parallel.py` since it uses SPMD internally and are very likely yield better perfomrance. diff --git a/examples/data_parallel/train_resnet_ddp.py b/examples/data_parallel/train_resnet_ddp.py new file mode 100644 index 00000000000..898983a714b --- /dev/null +++ b/examples/data_parallel/train_resnet_ddp.py @@ -0,0 +1,30 @@ +import sys +import os +example_folder = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0]))) +sys.path.append(example_folder) +from train_resnet_base import TrainResNetBase + +import torch.distributed as dist +from torch.nn.parallel import DistributedDataParallel as DDP +import torch.optim as optim +import torch_xla.distributed.xla_multiprocessing as xmp + + +class TrainResNetDDP(TrainResNetBase): + + def __init__(self): + super().__init__() + dist.init_process_group('xla', init_method='xla://') + self.model = DDP( + self.model, gradient_as_bucket_view=True, broadcast_buffers=False) + self.optimizer = optim.SGD(self.model.parameters(), weight_decay=1e-4) + + +def _mp_fn(index): + ddp = TrainResNetDDP() + ddp.start_training() + + +if __name__ == '__main__': + print('consider using train_resnet_spmd_data_parallel.py instead to get better performance') + xmp.spawn(_mp_fn, args=()) diff --git a/examples/data_parallel/train_resnet_spmd_data_parallel.py b/examples/data_parallel/train_resnet_spmd_data_parallel.py new file mode 100644 index 00000000000..3a5eaca39a5 --- /dev/null +++ b/examples/data_parallel/train_resnet_spmd_data_parallel.py @@ -0,0 +1,49 @@ +import sys +import os +example_folder = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0]))) +sys.path.append(example_folder) +from train_resnet_base import TrainResNetBase + +import numpy as np + +import torch +import torch_xla.distributed.xla_multiprocessing as xmp +import torch_xla.core.xla_model as xm +import torch_xla.distributed.spmd as xs +import torch_xla.distributed.parallel_loader as pl +import torch_xla.utils.utils as xu +from torch_xla import runtime as xr + +# Enable the SPMD +xr.use_spmd() + + +# More detailed examaple can be found in https://github.com/pytorch/xla/blob/master/test/spmd/test_train_spmd_imagenet.py +# Check out our user guide in https://github.com/pytorch/xla/blob/master/docs/spmd.md +class TrainResNetXLASpmdDDP(TrainResNetBase): + + def __init__(self): + super().__init__() + # Shard along batch dimension only + num_devices = xr.global_runtime_device_count() + device_ids = np.arange(num_devices) + mesh_shape = (num_devices,) + mesh = xs.Mesh(device_ids, mesh_shape, ('data',)) + # scale the batch size with num_devices since there will be only one + # process that handles all runtime devices. + self.batch_size *= num_devices + + train_loader = xu.SampleGenerator( + data=(torch.zeros(self.batch_size, 3, self.img_dim, self.img_dim), + torch.zeros(self.batch_size, dtype=torch.int64)), + sample_count=self.train_dataset_len // self.batch_size) + self.train_device_loader = pl.MpDeviceLoader( + train_loader, + self.device, + # Shard the input's batch dimension along the `data` axis, no sharding along other dimensions + input_sharding=xs.ShardingSpec(mesh, ('data', None, None, None))) + + +if __name__ == '__main__': + spmd_ddp = TrainResNetXLASpmdDDP() + spmd_ddp.start_training() diff --git a/examples/data_parallel/train_resnet_xla_ddp.py b/examples/data_parallel/train_resnet_xla_ddp.py new file mode 100644 index 00000000000..4ac99904422 --- /dev/null +++ b/examples/data_parallel/train_resnet_xla_ddp.py @@ -0,0 +1,25 @@ +import sys +import os +example_folder = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0]))) +sys.path.append(example_folder) +from train_resnet_base import TrainResNetBase + +import torch_xla.distributed.xla_multiprocessing as xmp +import torch_xla.core.xla_model as xm + + +class TrainResNetXLADDP(TrainResNetBase): + + def run_optimizer(self): + # optimizer_step will call `optimizer.step()` and all_reduce the gradident + xm.optimizer_step(self.optimizer) + + +def _mp_fn(index): + xla_ddp = TrainResNetXLADDP() + xla_ddp.start_training() + + +if __name__ == '__main__': + print('consider using train_resnet_spmd_data_parallel.py instead to get better performance') + xmp.spawn(_mp_fn, args=()) diff --git a/examples/debug/train_resnet_benchmark.py b/examples/debug/train_resnet_benchmark.py new file mode 100644 index 00000000000..50afe7f807f --- /dev/null +++ b/examples/debug/train_resnet_benchmark.py @@ -0,0 +1,49 @@ +import sys +import os +example_folder = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0]))) +sys.path.append(example_folder) +from train_resnet_base import TrainResNetBase + +import itertools +import time + +import torch_xla +import torch_xla.core.xla_model as xm + + +# This example aims to provide a simple way to benchmark torch_xla. Ideally device execution +# time should be greater than the tracing time so tracing time can be overlapped perfectlly. +# If that's not the case try to increase the batch size which will increase the device execution +# time and keep tracing time the same. +class TrainResNetBenchmark(TrainResNetBase): + + def train_loop_fn(self, loader, epoch): + self.model.train() + loader = itertools.islice(loader, self.num_steps) + for step, (data, target) in enumerate(loader): + tracing_start_time = time.time() + self.optimizer.zero_grad() + output = self.model(data) + loss = self.loss_fn(output, target) + loss.backward() + self.run_optimizer() + tracing_end_time = time.time() + # for releases < 2.3 uses `xm.mark_step()`. + # Couple things to note + # 1. sync itself is not blocking, it will schedule a device execution and return. + # 2. In TrainResNetBase we uses MpDeviceLoader which calls `mark_step` for every batch. + # We don't have to manually call `sync` here if we don't want to wait for execution to finish. + torch_xla.sync() + # Do not call this function every step unless you are benchmarking. It will block the main process + # and torch_xla won't be able to overlap the tracing of the next step with the device + # execution of the current step. For e2e benchmarking, call `wait_device_ops` once at the end. + xm.wait_device_ops() + device_execution_end_time = time.time() + print( + f'Step: {step}, Tracing time: {tracing_end_time - tracing_start_time}s, E2E time: {device_execution_end_time - tracing_start_time}s' + ) + + +if __name__ == '__main__': + benchmark = TrainResNetBenchmark() + benchmark.start_training() diff --git a/examples/debug/train_resnet_profile.py b/examples/debug/train_resnet_profile.py new file mode 100644 index 00000000000..158c138dba7 --- /dev/null +++ b/examples/debug/train_resnet_profile.py @@ -0,0 +1,30 @@ +import os +import sys +example_folder = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0]))) +sys.path.append(example_folder) +from train_resnet_base import TrainResNetBase + +import torch_xla.debug.profiler as xp + +# check https://github.com/pytorch/xla/blob/master/TROUBLESHOOTING.md#environment-variables +os.environ["XLA_IR_DEBUG"] = "1" +os.environ["XLA_HLO_DEBUG"] = "1" + +if __name__ == '__main__': + base = TrainResNetBase() + profile_port = 9012 + # you can also set profile_logdir to a gs bucket, for example + # profile_logdir = "gs://your_gs_bucket/profile" + profile_logdir = "/tmp/profile/" + duration_ms = 30000 + assert profile_logdir.startswith('gs://') or os.path.exists(profile_logdir) + server = xp.start_server(profile_port) + # Ideally you want to start the profile tracing after the initial compilation, for example + # at step 5. + xp.trace_detached( + f'localhost:{profile_port}', profile_logdir, duration_ms=duration_ms) + base.start_training() + # You can view the profile at tensorboard by + # 1. pip install tensorflow tensorboard-plugin-profile + # 2. tensorboard --logdir /tmp/profile/ --port 6006 + # For more detail plase take a look at https://cloud.google.com/tpu/docs/pytorch-xla-performance-profiling-tpu-vm diff --git a/examples/decoder_only_model.py b/examples/decoder_only_model.py new file mode 100644 index 00000000000..f335428d0af --- /dev/null +++ b/examples/decoder_only_model.py @@ -0,0 +1,227 @@ +from dataclasses import dataclass +from typing import Optional +import math + +import torch +import torch.nn.functional as F +from torch import nn + + +@dataclass +class DecoderOnlyConfig: + hidden_size: int = 1024 + num_hidden_layers: int = 2 + num_attention_heads: int = 8 + num_key_value_heads: int = 4 + intermediate_size = 64 * 1024 + vocab_size = 3200 + use_flash_attention = False + + +def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor: + """ + This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch, + num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim) + """ + batch, num_key_value_heads, slen, head_dim = hidden_states.shape + if n_rep == 1: + return hidden_states + hidden_states = hidden_states[:, :, + None, :, :].expand(batch, num_key_value_heads, + n_rep, slen, head_dim) + return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, + head_dim) + + +class RMSNorm(nn.Module): + + def __init__(self, hidden_size, eps=1e-6): + """ + RMSNorm is equivalent to LlamaRMSNorm + """ + super().__init__() + self.weight = nn.Parameter(torch.ones(hidden_size)) + self.variance_epsilon = eps + + def forward(self, hidden_states): + input_dtype = hidden_states.dtype + hidden_states = hidden_states.to(torch.float32) + variance = hidden_states.pow(2).mean(-1, keepdim=True) + hidden_states = hidden_states * torch.rsqrt(variance + + self.variance_epsilon) + return self.weight * hidden_states.to(input_dtype) + + +# 1. no kv_chche +# 2. no rotary embedding +# 3. no attention_mask +class GroupQueryAttention(nn.Module): + """Stripped-down version of the LlamaAttention""" + + def __init__(self, config: DecoderOnlyConfig): + super().__init__() + self.config = config + + self.hidden_size = config.hidden_size + self.num_heads = config.num_attention_heads + self.head_dim = self.hidden_size // self.num_heads + self.num_key_value_heads = config.num_key_value_heads + self.num_key_value_groups = self.num_heads // self.num_key_value_heads + + self.q_proj = nn.Linear( + self.hidden_size, self.num_heads * self.head_dim, bias=False) + self.k_proj = nn.Linear( + self.hidden_size, self.num_key_value_heads * self.head_dim, bias=False) + self.v_proj = nn.Linear( + self.hidden_size, self.num_key_value_heads * self.head_dim, bias=False) + self.o_proj = nn.Linear( + self.num_heads * self.head_dim, self.hidden_size, bias=False) + self.flash_attention_impl = None + + def forward( + self, + hidden_states: torch.Tensor, + ) -> torch.Tensor: + + bsz, q_len, _ = hidden_states.size() + # [B, S, H] -> [B, S, n_head * head_dim] + query_states = self.q_proj(hidden_states) + # [B, S, H] -> [B, S, n_kv_head * head_dim] + key_states = self.k_proj(hidden_states) + # [B, S, H] -> [B, S, n_kv_head * head_dim] + value_states = self.v_proj(hidden_states) + + # [B, S, n_head * head_dim] -> [B, n_head, S, head_dim] + query_states = query_states.view(bsz, q_len, self.num_heads, + self.head_dim).transpose(1, 2) + # [B, S, n_kv_head * head_dim] -> [B, n_kv_head, S, head_dim] + key_states = key_states.view(bsz, q_len, self.num_key_value_heads, + self.head_dim).transpose(1, 2) + # [B, S, n_kv_head * head_dim] -> [B, n_kv_head, S, head_dim] + value_states = value_states.view(bsz, q_len, self.num_key_value_heads, + self.head_dim).transpose(1, 2) + + # [B, n_kv_head, S, head_dim] -> [B, n_head, S, head_dim] + key_states = repeat_kv(key_states, self.num_key_value_groups) + # [B, n_kv_head, S, head_dim] -> [B, n_head, S, head_dim] + value_states = repeat_kv(value_states, self.num_key_value_groups) + + if not self.config.use_flash_attention: + # [B, n_head, S, head_dim] @ T([B, n_head, S, head_dim]) -> [B, n_head, S, S] + attn_weights = torch.einsum('bnsh,bnkh->bnsk', query_states, + key_states) / math.sqrt(self.head_dim) + + # upcast attention to fp32 + attn_weights = nn.functional.softmax( + attn_weights, dim=-1, dtype=torch.float32).to(query_states.dtype) + + # [B, n_head, S, S] @ T([B, n_head, S, head_dim]) -> [B, n_head, S, head_dim] + attn_output = torch.einsum('bnsk,bnkh->bnsh', attn_weights, value_states) + else: + assert self.flash_attention_impl != None + # [B, n_head, S, head_dim], [B, n_head, S, head_dim], [B, n_head, S, head_dim] + # -> [B, n_head, S, head_dim] + attn_output = self.flash_attention_impl(query_states, key_states, + value_states) + + # [B, n_head, S, head_dim] -> [B * S * n_head * head_dim] + attn_output = attn_output.transpose(1, 2).contiguous() + # [B * S * n_head * head_dim] -> [B, S, H] + attn_output = attn_output.reshape(bsz, q_len, self.hidden_size) + + # [B, S, H] -> [B, S, H] + attn_output = self.o_proj(attn_output) + + return attn_output + + +class MLP(nn.Module): + """Stripped-down version of the LlamaMLP""" + + def __init__(self, config: DecoderOnlyConfig): + super().__init__() + self.config = config + + self.hidden_size = config.hidden_size + self.intermediate_size = config.intermediate_size + self.gate_proj = nn.Linear( + self.hidden_size, self.intermediate_size, bias=False) + self.up_proj = nn.Linear( + self.hidden_size, self.intermediate_size, bias=False) + self.down_proj = nn.Linear( + self.intermediate_size, self.hidden_size, bias=False) + self.act_fn = F.silu + + def forward(self, x): + # [B, S, H] -> [B, S, I] + up_proj = self.up_proj(x) + # [B, S, H] -> [B, S, I] + gate_proj = self.act_fn(self.gate_proj(x)) + # ([B, S, I] * [B, S, I]) -> [B, S, H] + down_proj = self.down_proj(gate_proj * up_proj) + return down_proj + + +class DecoderLayer(nn.Module): + + def __init__(self, config: DecoderOnlyConfig): + super().__init__() + self.hidden_size = config.hidden_size + self.self_attn = (GroupQueryAttention(config=config)) + self.mlp = MLP(config) + self.input_layernorm = RMSNorm(config.hidden_size) + self.post_attention_layernorm = RMSNorm(config.hidden_size) + + def forward( + self, + hidden_states: torch.Tensor, + **kwargs, + ) -> torch.FloatTensor: + residual = hidden_states + + hidden_states = self.input_layernorm(hidden_states) + + # Self Attention + hidden_states = self.self_attn(hidden_states=hidden_states,) + hidden_states = residual + hidden_states + + # Fully Connected + residual = hidden_states + hidden_states = self.post_attention_layernorm(hidden_states) + hidden_states = self.mlp(hidden_states) + hidden_states = residual + hidden_states + + return hidden_states + + +# 1. no gradient_checkpointing +# 2. no padding_idx +# 3. no kv cache +class DecoderOnlyModel(nn.Module): + + def __init__(self, config: DecoderOnlyConfig): + super(DecoderOnlyModel, self).__init__() + self.vocab_size = config.vocab_size + self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size) + self.layers = nn.ModuleList( + [DecoderLayer(config) for _ in range(config.num_hidden_layers)]) + self.norm = RMSNorm(config.hidden_size) + self.output = nn.Linear(config.hidden_size, self.vocab_size, bias=False) + + def forward( + self, + input_ids: torch.LongTensor = None, + ) -> torch.Tensor: + inputs_embeds = self.embed_tokens(input_ids) + + # embed positions + hidden_states = inputs_embeds + + # decoder layers + for idx, decoder_layer in enumerate(self.layers): + layer_outputs = decoder_layer(hidden_states,) + hidden_states = layer_outputs + + hidden_states = self.norm(hidden_states) + # [B, S, H] -> [B, S, V] + return self.output(hidden_states) diff --git a/examples/flash_attention/train_decoder_only_flash_attention.py b/examples/flash_attention/train_decoder_only_flash_attention.py new file mode 100644 index 00000000000..442c27240f6 --- /dev/null +++ b/examples/flash_attention/train_decoder_only_flash_attention.py @@ -0,0 +1,33 @@ +import sys +import os +example_folder = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0]))) +sys.path.append(example_folder) +from train_decoder_only_base import TrainDecoderOnlyBase + +import math + + +def apply_xla_flash_attention(query_states, key_states, value_states): + from torch_xla.experimental.custom_kernel import flash_attention + + # q, k, v should all have the shape [B, n_head, S, head_dim] + head_dim = query_states.size()[-1] + query_states = query_states / math.sqrt(head_dim) + # Our simplified version of decoder only model does not use any mask. + attn_output = flash_attention( + query_states, key_states, value_states, causal=False) + return attn_output + + +class TrainDecoderOnlyFlashAttention(TrainDecoderOnlyBase): + + def __init__(self): + super().__init__() + self.config.use_flash_attention = True + for layer in self.model.layers: + layer.self_attn.flash_attention_impl = apply_xla_flash_attention + + +if __name__ == '__main__': + fa = TrainDecoderOnlyFlashAttention() + fa.start_training() diff --git a/examples/flash_attention/train_decoder_only_flash_attention_fsdp_v2.py b/examples/flash_attention/train_decoder_only_flash_attention_fsdp_v2.py new file mode 100644 index 00000000000..387ad7aed51 --- /dev/null +++ b/examples/flash_attention/train_decoder_only_flash_attention_fsdp_v2.py @@ -0,0 +1,36 @@ +import sys +import os +example_fsdp_folder = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0]))) + '/fsdp' +sys.path.append(example_fsdp_folder) +from train_decoder_only_fsdp_v2 import TrainDecoderOnlyFSDPv2 + +import math + +from torch_xla import runtime as xr + +def apply_xla_flash_attention_with_spmd(query_states, key_states, value_states): + from torch_xla.experimental.custom_kernel import flash_attention + + # q, k, v should all have the shape [B, n_head, S, head_dim] + head_dim = query_states.size()[-1] + query_states = query_states / math.sqrt(head_dim) + + # Our simplified version of decoder only model does not use any mask. + # flash_attention will use the global_mesh set in the TrainDecoderOnlyFSDPv2. + attn_output = flash_attention( + query_states, key_states, value_states, causal=False, partition_spec=('fsdp', None, None, None)) + return attn_output + +class TrainDecoderOnlyFlashAttentionFSDPv2(TrainDecoderOnlyFSDPv2): + def __init__(self): + super().__init__() + + self.config.use_flash_attention = True + for layer in self.model.layers: + layer.self_attn.flash_attention_impl = apply_xla_flash_attention_with_spmd + +if __name__ == '__main__': + # Enable the SPMD + xr.use_spmd() + fa_fsdp = TrainDecoderOnlyFlashAttentionFSDPv2() + fa_fsdp.start_training() diff --git a/examples/fsdp/README.md b/examples/fsdp/README.md new file mode 100644 index 00000000000..761ae64e16d --- /dev/null +++ b/examples/fsdp/README.md @@ -0,0 +1,2 @@ +## Recommendation +Please consider using `train_decoder_only_fsdp_v2.py` since it uses SPMD internally and are very likely yield better perfomrance. diff --git a/examples/fsdp/train_decoder_only_fsdp_v2.py b/examples/fsdp/train_decoder_only_fsdp_v2.py new file mode 100644 index 00000000000..589bb2c3827 --- /dev/null +++ b/examples/fsdp/train_decoder_only_fsdp_v2.py @@ -0,0 +1,63 @@ +import sys +import os +example_folder = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0]))) +sys.path.append(example_folder) +import decoder_only_model +from train_decoder_only_base import TrainDecoderOnlyBase + +import functools + +import torch +import numpy as np +import torch_xla.distributed.spmd as xs +import torch_xla.utils.utils as xu +import torch_xla.distributed.parallel_loader as pl +from torch_xla.experimental.spmd_fully_sharded_data_parallel import SpmdFullyShardedDataParallel as FSDPv2 +from torch_xla import runtime as xr +from torch_xla.distributed.fsdp.wrap import transformer_auto_wrap_policy + +# checkout our doc at https://github.com/pytorch/xla/blob/master/docs/fsdpv2.md +class TrainDecoderOnlyFSDPv2(TrainDecoderOnlyBase): + + def __init__(self): + super().__init__() + # Define the mesh following common SPMD practice + num_devices = xr.global_runtime_device_count() + mesh_shape = (num_devices, 1) + device_ids = np.array(range(num_devices)) + # To be noted, the mesh must have an axis named 'fsdp', which the weights and activations will be sharded on. + mesh = xs.Mesh(device_ids, mesh_shape, ('fsdp', 'model')) + xs.set_global_mesh(mesh) + + # Shard the input(data parallel). + # Scale the batch size with num_devices since there will be only one + # process that handles all runtime devices. + self.batch_size *= num_devices + train_loader = xu.SampleGenerator( + data=(torch.zeros(self.batch_size, self.seq_len, dtype=torch.int64), + torch.zeros(self.batch_size, self.seq_len, dtype=torch.int64)), + sample_count=self.train_dataset_len // self.batch_size) + self.train_device_loader = pl.MpDeviceLoader( + train_loader, + self.device, + # Shard the input's batch dimension along the `fsdp` axis, no sharding along other dimensions + input_sharding=xs.ShardingSpec(mesh, ('fsdp', None))) + + # Apply FSDP sharding on each DecoderLayer layer. + auto_wrap_policy = functools.partial( + transformer_auto_wrap_policy, + transformer_layer_cls={ + decoder_only_model.DecoderLayer + }, + ) + # FSDPv2 will use the global mesh set above + self.model = FSDPv2( + self.model, auto_wrap_policy=auto_wrap_policy) + self.optimizer = torch.optim.Adam(self.model.parameters(), lr=0.0001) + + +if __name__ == '__main__': + # Enable the SPMD + xr.use_spmd() + base = TrainDecoderOnlyFSDPv2() + base.start_training() diff --git a/examples/fsdp/train_resnet_fsdp_auto_wrap.py b/examples/fsdp/train_resnet_fsdp_auto_wrap.py new file mode 100644 index 00000000000..a7dc5679d00 --- /dev/null +++ b/examples/fsdp/train_resnet_fsdp_auto_wrap.py @@ -0,0 +1,56 @@ +import sys +import os +example_folder = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0]))) +sys.path.append(example_folder) +from train_resnet_base import TrainResNetBase +from functools import partial + +import torch +import torchvision +import torch.optim as optim +import torch_xla.distributed.xla_multiprocessing as xmp +import torch_xla.core.xla_model as xm +from torch_xla.distributed.fsdp import XlaFullyShardedDataParallel as FSDP, checkpoint_module +from torch_xla.distributed.fsdp.wrap import (size_based_auto_wrap_policy, + transformer_auto_wrap_policy) + +class TrainResNetXLAFSDP(TrainResNetBase): + + def __init__(self): + super().__init__() + # auto_wrap_policy can be either size_based or type_based + auto_wrap_policy = "size_based" + auto_wrap_min_num_params = 1e6 + if auto_wrap_policy == "size_based": + # auto-wrap all sub-modules with a certain number of parameters (default 1e6) + auto_wrap_policy = partial( + size_based_auto_wrap_policy, min_num_params=auto_wrap_min_num_params) + elif auto_wrap_policy == "type_based": + # auto-wrap all sub-modules in torchvision ResNet's BasicBlock or Bottleneck + # or torchvision transformer's EncoderBlock as an example + # (transformer_auto_wrap_policy wraps all sub-modules in transformer_layer_cls) + auto_wrap_policy = partial( + transformer_auto_wrap_policy, + transformer_layer_cls={ + torchvision.models.resnet.BasicBlock, + torchvision.models.resnet.Bottleneck, + torchvision.models.vision_transformer.EncoderBlock, + }) + else: + raise Exception(f"Invalid auto-wrap policy: {auto_wrap_policy}") + self.model = FSDP( + self.model, + compute_dtype=torch.float32, + pin_layout_in_collective_ops=True, + auto_wrap_policy=auto_wrap_policy) + self.optimizer = optim.SGD(self.model.parameters(), weight_decay=1e-4) + + +def _mp_fn(index): + xla_fsdp = TrainResNetXLAFSDP() + xla_fsdp.start_training() + + +if __name__ == '__main__': + print('consider using train_decoder_only_fsdp_v2.py instead to get better performance') + xmp.spawn(_mp_fn, args=()) diff --git a/examples/train_decoder_only_base.py b/examples/train_decoder_only_base.py new file mode 100644 index 00000000000..cd99a4303a5 --- /dev/null +++ b/examples/train_decoder_only_base.py @@ -0,0 +1,73 @@ +from decoder_only_model import DecoderOnlyConfig, DecoderOnlyModel + +from torch_xla import runtime as xr +import torch_xla.utils.utils as xu +import torch_xla.core.xla_model as xm +import torch_xla.distributed.parallel_loader as pl + +import time +import itertools + +import torch +import torch_xla +import torch.optim as optim +import torch.nn as nn + + +class TrainDecoderOnlyBase(): + + def __init__(self): + self.config = DecoderOnlyConfig() + self.batch_size = 16 + self.seq_len = 512 + self.num_steps = 300 + self.num_epochs = 1 + self.train_dataset_len = 1200000 # Roughly the size of Imagenet dataset. + # For the purpose of this example, we are going to use fake data. + train_loader = xu.SampleGenerator( + data=(torch.zeros(self.batch_size, self.seq_len, dtype=torch.int64), + torch.zeros(self.batch_size, self.seq_len, dtype=torch.int64)), + sample_count=self.train_dataset_len // self.batch_size) + + self.device = torch_xla.device() + self.train_device_loader = pl.MpDeviceLoader(train_loader, self.device) + self.model = DecoderOnlyModel(self.config).to(self.device) + self.optimizer = torch.optim.Adam(self.model.parameters(), lr=0.0001) + self.loss_fn = nn.CrossEntropyLoss() + + def _train_update(self, step, loss, tracker, epoch): + print(f'epoch: {epoch}, step: {step}, loss: {loss}, rate: {tracker.rate()}') + + def run_optimizer(self): + self.optimizer.step() + + def train_loop_fn(self, loader, epoch): + tracker = xm.RateTracker() + self.model.train() + loader = itertools.islice(loader, self.num_steps) + for step, (data, target) in enumerate(loader): + self.optimizer.zero_grad() + logits = self.model(data) + loss = self.loss_fn( + logits.view(-1, self.config.vocab_size), target.view(-1)) + loss.backward() + self.run_optimizer() + tracker.add(self.batch_size) + if step % 10 == 0: + xm.add_step_closure( + self._train_update, args=(step, loss, tracker, epoch)) + + def start_training(self): + + for epoch in range(1, self.num_epochs + 1): + xm.master_print('Epoch {} train begin {}'.format( + epoch, time.strftime('%l:%M%p %Z on %b %d, %Y'))) + self.train_loop_fn(self.train_device_loader, epoch) + xm.master_print('Epoch {} train end {}'.format( + epoch, time.strftime('%l:%M%p %Z on %b %d, %Y'))) + xm.wait_device_ops() + + +if __name__ == '__main__': + base = TrainDecoderOnlyBase() + base.start_training() diff --git a/examples/train_resnet_amp.py b/examples/train_resnet_amp.py new file mode 100644 index 00000000000..ae541705d71 --- /dev/null +++ b/examples/train_resnet_amp.py @@ -0,0 +1,35 @@ +from train_resnet_base import TrainResNetBase + +import itertools + +import torch_xla.distributed.xla_multiprocessing as xmp +import torch_xla.core.xla_model as xm +from torch_xla.amp import autocast + + +# For more details check https://github.com/pytorch/xla/blob/master/docs/amp.md +class TrainResNetXLAAMP(TrainResNetBase): + + def train_loop_fn(self, loader, epoch): + tracker = xm.RateTracker() + self.model.train() + loader = itertools.islice(loader, self.num_steps) + for step, (data, target) in enumerate(loader): + self.optimizer.zero_grad() + # Enables autocasting for the forward pass + with autocast(xm.xla_device()): + output = self.model(data) + loss = self.loss_fn(output, target) + # TPU amp uses bf16 hence gradient scaling is not necessary. If runnign with XLA:GPU + # check https://github.com/pytorch/xla/blob/master/docs/amp.md#amp-for-xlagpu. + loss.backward() + self.run_optimizer() + tracker.add(self.batch_size) + if step % 10 == 0: + xm.add_step_closure( + self._train_update, args=(step, loss, tracker, epoch)) + + +if __name__ == '__main__': + xla_amp = TrainResNetXLAAMP() + xla_amp.start_training() diff --git a/examples/train_resnet_base.py b/examples/train_resnet_base.py new file mode 100644 index 00000000000..b66780d5cd9 --- /dev/null +++ b/examples/train_resnet_base.py @@ -0,0 +1,71 @@ +from torch_xla import runtime as xr +import torch_xla.utils.utils as xu +import torch_xla.core.xla_model as xm +import torch_xla.distributed.parallel_loader as pl + +import time +import itertools + +import torch +import torch_xla +import torchvision +import torch.optim as optim +import torch.nn as nn + + +class TrainResNetBase(): + + def __init__(self): + self.img_dim = 224 + self.batch_size = 128 + self.num_steps = 300 + self.num_epochs = 1 + self.train_dataset_len = 1200000 # Roughly the size of Imagenet dataset. + # For the purpose of this example, we are going to use fake data. + train_loader = xu.SampleGenerator( + data=(torch.zeros(self.batch_size, 3, self.img_dim, self.img_dim), + torch.zeros(self.batch_size, dtype=torch.int64)), + sample_count=self.train_dataset_len // self.batch_size // + xr.world_size()) + + self.device = torch_xla.device() + self.train_device_loader = pl.MpDeviceLoader(train_loader, self.device) + self.model = torchvision.models.resnet50().to(self.device) + self.optimizer = optim.SGD(self.model.parameters(), weight_decay=1e-4) + self.loss_fn = nn.CrossEntropyLoss() + + def _train_update(self, step, loss, tracker, epoch): + print(f'epoch: {epoch}, step: {step}, loss: {loss}, rate: {tracker.rate()}') + + def run_optimizer(self): + self.optimizer.step() + + def train_loop_fn(self, loader, epoch): + tracker = xm.RateTracker() + self.model.train() + loader = itertools.islice(loader, self.num_steps) + for step, (data, target) in enumerate(loader): + self.optimizer.zero_grad() + output = self.model(data) + loss = self.loss_fn(output, target) + loss.backward() + self.run_optimizer() + tracker.add(self.batch_size) + if step % 10 == 0: + xm.add_step_closure( + self._train_update, args=(step, loss, tracker, epoch)) + + def start_training(self): + + for epoch in range(1, self.num_epochs + 1): + xm.master_print('Epoch {} train begin {}'.format( + epoch, time.strftime('%l:%M%p %Z on %b %d, %Y'))) + self.train_loop_fn(self.train_device_loader, epoch) + xm.master_print('Epoch {} train end {}'.format( + epoch, time.strftime('%l:%M%p %Z on %b %d, %Y'))) + xm.wait_device_ops() + + +if __name__ == '__main__': + base = TrainResNetBase() + base.start_training() diff --git a/experimental/torch_xla2/README.md b/experimental/torch_xla2/README.md index f30be7ff1da..dc5a1fdffce 100644 --- a/experimental/torch_xla2/README.md +++ b/experimental/torch_xla2/README.md @@ -4,7 +4,8 @@ Currently this is only source-installable. Requires Python version >= 3.10. -### NOTE: +### NOTE: + Please don't install torch-xla from instructions in https://github.com/pytorch/xla/blob/master/CONTRIBUTING.md . In particular, the following are not needed: @@ -18,71 +19,71 @@ TorchXLA2 and torch-xla have different installation instructions, please follow the instructions below from scratch (fresh venv / conda environment.) -### 1. Install dependencies +### 1. Installing `torch_xla2` -#### 1.0 (optional) Make a virtualenv / conda env, and activate it. +The following instructions assume you are in the `torch_xla2` directory: -```bash -conda create --name python=3.10 -conda activate ``` -Or, -```bash -python -m venv create my_venv -source my_venv/bin/activate +$ git clone https://github.com/pytorch/xla.git +$ cd xla/experimental/torch_xla2 ``` -#### 1.1 Install torch CPU, even if your device has GPU or TPU: -```bash -pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu -``` +#### 1.0 (recommended) Make a virtualenv / conda env -Or, follow official instructions in [pytorch.org](https://pytorch.org/get-started/locally/) to install for your OS. +If you are using VSCode, then [you can create a new environment from +UI](https://code.visualstudio.com/docs/python/environments). Select the +`dev-requirements.txt` when asked to install project dependencies. -#### 1.2 Install Jax for either GPU or TPU +Otherwise create a new environment from the command line. -If you are using Google Cloud TPU, then ```bash -pip install jax[tpu] -f https://storage.googleapis.com/jax-releases/libtpu_releases.html -``` - -If you are using a machine with NVidia GPU: +# Option 1: venv +python -m venv create my_venv +source my_venv/bin/activate -```bash -pip install --upgrade "jax[cuda12_pip]" -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html -``` +# Option 2: conda +conda create --name python=3.10 +conda activate -If you are using a CPU-only machine: -```bash -pip install --upgrade "jax[cpu]" +# Either way, install the dev requirements. +pip install -r dev-requirements.txt ``` -Or, follow the official instructions in https://jax.readthedocs.io/en/latest/installation.html to install for your OS or Device. +Note: `dev-requirements.txt` will install the CPU-only version of PyTorch. -#### 1.3 Install this package +#### 1.1 Install this package +If you want to install torch_xla2 without the jax dependency and use the jax dependency from torch_xla: ```bash +pip install torch_xla[pallas] -f https://storage.googleapis.com/jax-releases/jax_nightly_releases.html -f https://storage.googleapis.com/jax-releases/jaxlib_nightly_releases.html pip install -e . ``` -#### 1.4 (optional) verify installation by running tests +Otherwise, install `torch_xla2` from source for your platform: +```bash +pip install -e .[cpu] +pip install -e .[cuda] +pip install -e .[tpu] -f https://storage.googleapis.com/libtpu-releases/index.html +``` + +#### 1.2 (optional) verify installation by running tests ```bash -pip install -r test_requirements.txt +pip install -r test-requirements.txt pytest test ``` - ## Run a model Now let's execute a model under torch_xla2. We'll start with a simple 2-layer model it can be in theory any instance of `torch.nn.Module`. ```python +import torch +import torch.nn as nn +import torch.nn.functional as F -import torch_xla2 -from torch import nn class MyModel(nn.Module): def __init__(self): @@ -101,8 +102,8 @@ class MyModel(nn.Module): m = MyModel() # Execute this model using torch -inputs = (torch.randn(3, 3, 28, 28), ) -print(m(*inputs)) +inputs = torch.randn(3, 3, 28, 28) +print(m(inputs)) ``` This model `m` contains 2 parts: the weights that is stored inside of the model @@ -114,6 +115,7 @@ to `XLA` devices. This can be accomplished with `torch_xla2.tensor.move_to_devic We need move both the weights and the input to xla devices: ```python +import torch_xla2 from torch.utils import _pytree as pytree from torch_xla2.tensor import move_to_device @@ -121,7 +123,7 @@ inputs = move_to_device(inputs) new_state_dict = pytree.tree_map_only(torch.Tensor, move_to_device, m.state_dict()) m.load_state_dict(new_state_dict, assign=True) -res = m(*inputs) +res = m(inputs) print(type(res)) # outputs XLATensor2 ``` @@ -164,5 +166,3 @@ from torch_xla2.extra import jax_jit model_func_jitted = jax_jit(model_func) print(model_func_jitted(new_state_dict, inputs)) ``` - - diff --git a/experimental/torch_xla2/dev-requirements.txt b/experimental/torch_xla2/dev-requirements.txt index 4a32310fbda..208f70d5fef 100644 --- a/experimental/torch_xla2/dev-requirements.txt +++ b/experimental/torch_xla2/dev-requirements.txt @@ -1,9 +1,3 @@ -absl-py==2.0.0 -flatbuffers==23.5.26 -jax==0.4.23 -jaxlib==0.4.23 -pytest -tensorflow -torch==2.2.1+cpu -immutabledict -sentencepiece \ No newline at end of file +-f https://download.pytorch.org/whl/torch +torch==2.3.0+cpu +ruff~=0.3.5 diff --git a/experimental/torch_xla2/docs/dispatch.png b/experimental/torch_xla2/docs/dispatch.png new file mode 100644 index 0000000000000000000000000000000000000000..fcdd5e9e58a39032593fd3090fe1881d433e9a4f GIT binary patch literal 150015 zcmb5W1yq&W+9<4ugoHGrp6|Q=-Q$k2#!wbBp80eVASWY^b?fe}YuBz}Nj!rqT)T#%cJ11YRWuavjdAzs zAo%CHor1W?wSs=q^=sECuSvk4C^~6xC85@lDownbI~2p9MMB3Bd5%`!`jy~E*ym@6 z{Xu!T93+wNAN}p`2g1%iK8s|bTBZ_sEc*^GMcM1GC9_JM`)4-%P}f~Tt2 zoR2u+;&?G2d0rl*+!TWjiI>z}OL8nYKS=5<8Ioiiskb0xK!VAUBC$67NZZ4fToP0y zl{5?ZulLvkLZl7;qS$pLG$w#-8tA0wZ}68BX$mv>!VRZhRhDm8Ocf-H<}!f`y>Wzf ztA8v8(UuUT3yom@!4Y2V;H;rL{VsuM{=zb7yy3o)vyZluB4u81iKglz?=+lSvPy@- zW4s;m;;E7N0Nc}|CZ#_J{DT$-?*USJ9ReQE0K`cn$r$i$WPPG3;Vh*-w7@lyN3wkT z0wxuNeT_>4IbIr&Cz4+{l=u(SbkbfAV5;8YR#HcXQ!)cI4Z(74MTLLdVM9P67CKt22~)}`bF2X@7+V*^AYL3hsgD}94gq5^?kPK{I)#bsav3vTXc zay|c>D}ef-*;=cA0k1w&ip zUk|{xhoWHH=bER{xLz^TK;Nv?Xkrn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{ h2T1+@2_{G4-`?#UsQvQQI0yd7OFwyBB>C*+{|C7a3XA{% literal 0 HcmV?d00001 diff --git a/experimental/torch_xla2/docs/fixing_op_info_test.md b/experimental/torch_xla2/docs/fixing_op_info_test.md new file mode 100644 index 00000000000..03624f9487e --- /dev/null +++ b/experimental/torch_xla2/docs/fixing_op_info_test.md @@ -0,0 +1,211 @@ +# How to fix an op info test. + +## What is OpInfo test + +PyTorch created a list of python objects (OpInfo) to keep +track how to test each op. This is useful to us because it +ensures that the ops we implement produces the same results +pytorch would produce. + +Context: +* https://dev-discuss.pytorch.org/t/opinfos-in-pytorch-1-10/253 +* https://github.com/pytorch/pytorch/issues/54261 + + +## How to fix one + +### Remove one op from skiplist + +Open [test/test_ops.py](../test/test_ops.py) with your +favorite text editor. +Remove one line from the `skiplist` set. + +i.e. + +```bash +(base) hanq-macbookpro:torch_xla2 hanq$ git diff +diff --git a/experimental/torch_xla2/test/test_ops.py b/experimental/torch_xla2/test/test_ops.py +index 72a39ae85..2a156cbce 100644 +--- a/experimental/torch_xla2/test/test_ops.py ++++ b/experimental/torch_xla2/test/test_ops.py +@@ -15,7 +15,6 @@ skiplist = { + "_native_batch_norm_legit", + "_segment_reduce", + "_upsample_bilinear2d_aa", +- "addbmm", + "addmm", + "addmv", + "addr", +``` + +### Run test to see what failure + +Error gotten: + +``` +E RuntimeError: ('No lowering found for\n\nTo execute this test, run the following from the base repo dir:\n python test/test_ops.py -k test_reference_eager_addbmm_cpu_int64\n\nThis message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0', 'aten::addbmm') +``` + +From here we have 2 strategies for fixing this test: + +1. Add an implementation to `aten::addbmm` operator using Jax ops. Or, +2. Add an implementation `aten::addbmm` operator using torch ops (this commonly known as "decompositions"). + +Either way works for torch_xla2. For ops that are not "Core Aten" sometimes we implement in torch ops with the goal of +upstreaming this decomposition to [pytorch decompositon](https://github.com/pytorch/pytorch/blob/main/torch/_decomp/decompositions.py) +so other projects can benefit from it. + +For illustration purposes, let's implement this op in Jax. + +(NOTE: this doesn't stop us from upstreaming a decomposition later if we want) + +### First Impl + +To implement this op using jax ops, we first find what +is the exact semantics in this page: +https://pytorch.org/docs/stable/generated/torch.addbmm.html + +From it's math formula: we can implement it as follows. + +``` ++@op(torch.ops.aten.addbmm.default) ++def _aten_addbmm(input, batch1, batch2, *, beta=1, alpha=1): ++ ++ mm = jnp.einsum('bxy, byz -> xz', batch1, batch2) ++ return beta * input + alpha * mm +``` + +Now running test again: + +``` +python test/test_ops.py -k test_reference_eager_addbmm_cpu_int64 +``` + +(NOTE: the exact test command is printed out when we run +`pytest test/test_ops.py` so we can only run the failed test instead of running all tests.) + +We now see this error: + +``` +FAIL: test_reference_eager_addbmm_cpu_int64 (__main__.TestOpInfoCPU) [torch_xla2_diff:0.001] +---------------------------------------------------------------------- +Traceback (most recent call last): + File "/Users/hanq/git/qihqi/torch_xla/experimental/torch_xla2/test/test_ops.py", line 654, in run_export_and_compare + diff_output( + File "/Users/hanq/git/qihqi/torch_xla/experimental/torch_xla2/test/test_ops.py", line 617, in diff_output + testcase.assertTrue( +AssertionError: False is not true +``` + +This is telling me that our implementation did not produce +the same result as the ops in PyTorch. + +To debug this, let's figure out what exact input caused this. +We can achieve this by setting a break point [here](https://github.com/pytorch/xla/blob/master/experimental/torch_xla2/test/test_ops.py#L644), right before the diff. Here we can +inspect values of `res` and `res2`, as well as the `sample_input`. + +The sample input we get is +``` +SampleInput(input=tensor([[-3, -3, 9, 8, -8, -3, -4, 2, 2, 2], + [-5, 1, -9, 9, 1, -5, 6, 1, -4, -5], + [-2, -1, 5, -2, -3, 0, 5, -4, 9, -6], + [-1, -7, 6, 3, 8, 3, 8, 9, -5, 7], + [-3, -4, -9, 9, 7, -3, -8, 2, 5, -3]]), args=(tensor([[[-2, 4, -2, 5, 8], + [-6, -2, 5, 7, 7], + [-8, -3, 2, 5, -3], + [-4, 7, 0, -9, 8], + [ 3, 9, -9, -2, 0]], + + [[-7, 1, -3, 7, -4], + [ 3, 5, 4, 6, 5], + [-2, 8, 3, 5, 7], + [ 8, -2, -8, 2, 0], + [ 6, 1, -8, 8, 0]], + + [[ 2, -1, -5, -8, -9], + [ 5, 0, -4, -1, -6], + [-6, 2, -5, -2, -5], + [-5, -3, -5, -4, 9], + [-3, 4, -9, -9, 7]], + + [[ 2, 5, -7, -3, 8], + [-5, -7, -8, -4, 4], + [-4, -6, -3, 0, 6], + [ 8, 0, -3, -8, 2], + [-4, 3, -9, -6, 7]], + + [[ 2, 1, -6, 2, 8], + [ 2, 6, 4, 1, 8], + [-9, 9, -5, 8, 3], + [-5, 0, -2, 4, 0], + [ 5, 8, -4, 9, 7]]]), tensor([[[-1, -8, 3, 5, -8, 2, -5, 0, -9, -5], + [-4, -7, 2, 2, 1, -9, 2, 7, -1, -1], + [ 1, 8, -6, -4, -6, -8, -7, -9, 7, 4], + [-4, 1, -9, 3, 4, 6, 0, -2, -2, -7], + [ 5, 5, 0, 8, -3, 7, -7, 8, 3, 5]], + + [[ 8, -4, -9, 9, 5, 0, 5, 0, -5, 5], + [-5, -3, -2, 8, 1, -2, 4, -7, 5, 3], + [-4, 4, 1, -4, -8, 2, -5, 2, 9, -7], + [ 9, 6, -8, -3, 3, 1, 4, 6, -5, -4], + [-2, 1, 5, 5, 2, 6, 7, -3, -7, 3]], + + [[ 9, -8, 5, -3, -1, 2, -9, -5, -1, -3], + [-3, 3, -9, -7, -9, -8, 1, -3, 7, -2], + [ 8, -1, 8, -8, -7, 4, 8, 8, 5, -7], + [-1, 6, -8, 7, -1, -5, -8, 6, -2, 8], + [-5, -5, 8, 6, 0, 1, 3, -2, -3, -9]], + + [[ 7, -2, 6, -8, -5, 3, 2, -1, -5, 8], + [-6, -4, 3, 9, -9, -8, -7, 3, 9, 0], + [ 1, 3, 4, 4, -5, -2, -4, -2, 3, -7], + [-6, 9, 5, -1, 7, 7, 8, -3, -8, 0], + [-1, -6, -3, 3, 3, -8, -4, 9, -5, 7]], + + [[-5, -3, -9, 6, -1, -7, 9, -8, 1, -8], + [-8, -8, -2, -5, -7, -8, 1, 0, 0, -6], + [ 7, -5, 2, 2, 0, -9, -5, -7, 1, 8], + [-4, 0, 9, 6, -1, -6, 6, -6, -2, -1], + [ 7, 3, 0, 1, 1, -9, 5, -8, -1, -7]]])), kwargs={'beta': 0.6, 'alpha': 0.2}, broadcasts_input=False, name='') +``` + +And the `res` from torch is + +``` +tensor([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) +``` + +So few observation is: +1. Input tensor are of type int64 +2. alpha and beta are both floats. + +So one can suspect that it has to do with rounding. +Reading the doc more carefully, we can find this sentence + + For inputs of type FloatTensor or DoubleTensor, arguments beta and alpha must be real numbers, otherwise they should be integers. + +So likely torch first casted the float alpha and beta to integer, which yields 0, then used them in math to get a matrix with all zeros. + +### Second Impl + +```python ++@op(torch.ops.aten.addbmm.default) ++def _aten_addbmm(input, batch1, batch2, *, beta=1, alpha=1): ++ alpha = jnp.array(alpha).astype(batch1.dtype) ++ beta = jnp.array(beta).astype(batch1.dtype) ++ mm = jnp.einsum('bxy, byz -> xz', batch1, batch2) ++ return jax.lax.cond(beta == 0, ++ lambda: alpha * mm, ++ lambda: beta*input + alpha*mm) ++ +``` + +Adding type casts makes the tests passes. + +### Submit +Now, let's remove the pdb and prints we added, and submit the fix as a PR: https://github.com/pytorch/xla/pull/6993 + diff --git a/experimental/torch_xla2/docs/how_it_works.md b/experimental/torch_xla2/docs/how_it_works.md new file mode 100644 index 00000000000..e4098ca0096 --- /dev/null +++ b/experimental/torch_xla2/docs/how_it_works.md @@ -0,0 +1,134 @@ +How it works +============ + + +## Tensor subclass and eager mode + +The class `XLATensor2` is a `torch.Tensor` subclass +that overrides `__torch_dispatch__`. + +It roughly looks like this (with some details removed): + +The complete class impl is at [tensor.py](../torch_xla2/tensor.py). + +```python +class XLATensor2(torch.Tensor): + + @staticmethod + def __new__(cls, elem): + return torch.Tensor._make_wrapper_subclass( + cls, + shape, + dtype=dtype, + device='meta', + requires_grad=False, + ) + + def __init__(self, elem: jax.Array): + super().__init__() + self._elem = elem + + __torch_function__ = torch._C._disabled_torch_function_impl + + @classmethod + def __torch_dispatch__(cls, func, types, args=(), kwargs=None): + # here assumes ALL tensors in args / kwargs are + # instances of XLATensor2 + args, kwargs = unwrap((args, kwargs)) + jax_func = some_registry[func] + res = jax_func(*args, **kwargs) + return wrap(res) + +def wrap(tree): + # wrap jax.Array with XLATensor2 + return pytree.tree_map_only( + jax.Array, XLATensor2, tree) + +def unwrap(tree): + # get jax.Array out ofXLATensor2 + return pytree.tree_map_only( + XLATensor2, lambda x: x._elem, tree) +``` + +In other words, assuming that we have a function +that takes `jax.Array` as input and returns `jax.Array` +but otherwise implement the same semantics +as a `ATen` op; then, using this tensor we would +be able to route the call to this jax function. + +[_ops.py](../torch_xla2/_ops.py) files defines some of those ops. + +Let's take `aten::add` as example: + +```python +@op(torch.ops.aten.add) +def _aten_add(x, y, *, alpha=1): + """if isinstance(x, jnp.ndarray) and isinstance(y, jnp.ndarray): + + assert x.dtype == y.dtype, (x.dtype, y.dtype) + """ + return x + y * alpha +``` + +The `@op` decorator just puts this function into `some_registry` dictionary. + +`_aten_add` has same signature as `torch.ops.aten.add` but takes `jax.Array` as +input. + +![](dispatch.png) + + +## fx Interpreter and dynamo mode + +Now, assuming we have this `some_registry` dict with key core Aten ops, +and value the equivalent python Jax functions. We can also build a `fx.Interpreter` +subclass that executes the jax function given a `fx.GraphModule`. + + +```python +class JaxInterpreter(torch.fx.Interpreter): + + def call_function(self, target, args: Tuple, kwargs: Dict) -> Any: + if not isinstance(target, + (torch._ops.OpOverloadPacket, torch._ops.OpOverload)): + return super().call_function(target, args, kwargs) + + op = some_registry[target] + return op.func(*args, **kwargs) +``` + +There is no wrapping and unwrapping needed because `args` and `kwargs` are +already `jax.Array`'s. + +Using this interpreter we can build a dynamo backend: + +```python +def backend(fxgraph): + + def tojit(*args, *kwargs): + return JaxInterpreter(fxgraph).run(*args, **kwargs) + jitted = jax.jit(to_jit) + + def f(*torchtensor): + jaxarrays = unwrap(torchtensors) + res = jitted(jax_array) + return wrap(res) + + return f +``` + +The inner function `tojit` is a function that takes and returns +`jax.Array`'s. So it's suitable to be jitted with `jax.jit`. + +`f` is returned callable that takes `XLATensor2`; so can interop with +other torch codes. + +## nn.Modules and state management + +See [README.md](../README.md) for using `torch.func.functional_call` to +make `nn.Module`s interact well with `jax.jit`. + +See [Examples](../examples/README.md) for training using torch's optimizers or jax's +optimizers. + +[def]: dispatch.png \ No newline at end of file diff --git a/experimental/torch_xla2/docs/ops_registry.md b/experimental/torch_xla2/docs/ops_registry.md new file mode 100644 index 00000000000..c0e68f42fc4 --- /dev/null +++ b/experimental/torch_xla2/docs/ops_registry.md @@ -0,0 +1,40 @@ +# Ops Registry + +## Background + +In the [How it works](how_it_works.md) doc, we mentioned 2 important pieces: + +1. A mechanism to route `ATen` ops to implementation written in + Jax or in PyTorch, and + +2. The ops themselves. + + +Ops Registry is there to help us to organize the ops themselves. + +An op implementation can written in terms of Jax, or in other PyTorch ops. +The latter is also known as "decompositions". For decompositions, +one need to be careful of not introducing circular dependencies. + +Here we simply store the operator implementations in a dictionary, +which key the torch / Aten callable that we wish to override, and +value an instance of `Operator` class. + +`Operator` class has this schema: + +```python +@dataclasses.dataclass +class Operator: + torch_op: TorchCallable + func: Union[TorchCallable, JaxCallable] + is_jax_function: bool + is_user_defined: bool + needs_env: bool +``` + +The `torch_op` is the corresponding torch callable, and `func` the implementation. `is_jax_function` is True if `func` is implemented using Jax, False if `func` is implemented using other torch ops. We can use this information to decide how to call it. + +If `needs_env` is true, `func` will recieve an extra kwarg with name `env`. +This will be the "Environment" in which this op operate on. In particular, +the environment will contain the Jax random number generator key, that might be useful for ops like `aten::rand`. + diff --git a/experimental/torch_xla2/examples/basic_training.py b/experimental/torch_xla2/examples/basic_training.py index 5d3f5a734c5..29e55700a32 100644 --- a/experimental/torch_xla2/examples/basic_training.py +++ b/experimental/torch_xla2/examples/basic_training.py @@ -10,7 +10,11 @@ from torch.utils import _pytree as pytree import torchvision import torchvision.transforms as transforms -import torch_xla2 +import torch_xla2.tensor + + +xla_env = torch_xla2.tensor.Environment(0) +mode = xla_env.mode() # PyTorch TensorBoard support from torch.utils.tensorboard import SummaryWriter @@ -80,6 +84,7 @@ def forward(self, x): model = GarmentClassifier() +model = xla_env.to_xla(model) loss_fn = torch.nn.CrossEntropyLoss() @@ -96,13 +101,6 @@ def forward(self, x): print('Total loss for this batch: {}'.format(loss.item())) # Optimizers specified in the torch.optim package - -# NEW: Move model to XLA device -state_dict = model.state_dict() -state_dict = pytree.tree_map_only(torch.Tensor, - torch_xla2.tensor.move_to_device, state_dict) -model.load_state_dict(state_dict, strict=False, assign=True) - optimizer = torch.optim.SGD(model.parameters(), lr=0.001, momentum=0.9) def train_one_epoch(epoch_index, tb_writer): @@ -115,14 +113,14 @@ def train_one_epoch(epoch_index, tb_writer): for i, data in enumerate(training_loader): # Every data instance is an input + label pair # NEW: Move model to XLA device - data = pytree.tree_map_only(torch.Tensor, - torch_xla2.tensor.move_to_device, data) + data = xla_env.to_xla(data) inputs, labels = data # Zero your gradients for every batch! optimizer.zero_grad() # Make predictions for this batch + outputs = model(inputs) # Compute the loss and its gradients @@ -169,14 +167,11 @@ def train_one_epoch(epoch_index, tb_writer): # Disable gradient computation and reduce memory consumption. with torch.no_grad(): for i, vdata in enumerate(validation_loader): - # NOTE: move to XLA device - vinputs, vlabels = pytree.tree_map_only( - torch.Tensor, - torch_xla2.tensor.move_to_device, - vdata) - voutputs = model(vinputs) # call model's forward - vloss = loss_fn(voutputs, vlabels) - running_vloss += vloss + # NOTE: move to XLA device + vinputs, vlabels = xla_env.to_xla(vdata) + voutputs = model(vinputs) # call model's forward + vloss = loss_fn(voutputs, vlabels) + running_vloss += vloss avg_vloss = running_vloss / (i + 1) print('LOSS train {} valid {}'.format(avg_loss, avg_vloss)) diff --git a/experimental/torch_xla2/examples/basic_training_jax.py b/experimental/torch_xla2/examples/basic_training_jax.py index 3941fcdf8fe..ae6efdf4856 100644 --- a/experimental/torch_xla2/examples/basic_training_jax.py +++ b/experimental/torch_xla2/examples/basic_training_jax.py @@ -8,7 +8,7 @@ import torchvision import torchvision.transforms as transforms import torch_xla2 -import torch_xla2.extra +import torch_xla2.interop import jax import optax import numpy as np @@ -91,7 +91,7 @@ def forward(self, x): def jax_loss(weights, data, label): pred = jax_func(weights, data) - loss = torch_xla2.extra.call_torch(loss_fn, pred, label) + loss = torch_xla2.interop.call_torch(loss_fn, pred, label) return loss grad_fn = jax.jit(jax.value_and_grad(jax_loss)) @@ -155,12 +155,6 @@ def train_one_epoch(jax_weights, opt_state, epoch_index, tb_writer): # Make sure gradient tracking is on, and do a pass over the data model.train(True) - # NEW: Move model to XLA device - state_dict = model.state_dict() - state_dict = pytree.tree_map_only(torch.Tensor, - torch_xla2.tensor.move_to_device, state_dict) - model.load_state_dict(state_dict, strict=False, assign=True) - avg_loss, opt_state = train_one_epoch(jax_weights, opt_state, epoch_number, writer) running_vloss = 0.0 @@ -174,7 +168,7 @@ def train_one_epoch(jax_weights, opt_state, epoch_index, tb_writer): vinputs, vlabels = pytree.tree_map_only(torch.Tensor, torch_xla2.tensor.t2j, vdata) voutputs = jax_func(jax_weights, (vinputs, )) # call model's forward - vloss = torch_xla2.extra.call_torch(loss_fn, voutputs, vlabels) + vloss = torch_xla2.interop.call_torch(loss_fn, voutputs, vlabels) running_vloss += vloss avg_vloss = running_vloss / (i + 1) diff --git a/experimental/torch_xla2/examples/eager_mode.py b/experimental/torch_xla2/examples/eager_mode.py index 358ee6256c6..755f24b0d2b 100644 --- a/experimental/torch_xla2/examples/eager_mode.py +++ b/experimental/torch_xla2/examples/eager_mode.py @@ -1,10 +1,9 @@ - -from torch_xla2.tensor import move_to_device import torch_xla2 from torch import nn from torch.nn import functional as F import torch -from torch.utils import _pytree as pytree + +xla_env = torch_xla2.default_env() class MyModel(nn.Module): @@ -22,21 +21,21 @@ def forward(self, x): return x m = MyModel() +m = xla_env.to_xla(m) # Execute this model using torch inputs = (torch.randn(3, 3, 28, 28), ) +inputs = xla_env.to_xla(inputs) -inputs, state_dict = pytree.tree_map_only(torch.Tensor, move_to_device, (inputs, m.state_dict())) -m.load_state_dict(state_dict, strict=False, assign=True) print(m(*inputs)) print('---=====') -from torch_xla2.extra import jax_jit +from torch_xla2.interop import jax_jit @jax_jit def model_func(param, inputs): return torch.func.functional_call(m, param, inputs) -print(model_func(state_dict, inputs)) +print(model_func(m.state_dict(), inputs)) diff --git a/experimental/torch_xla2/examples/lightning_training.py b/experimental/torch_xla2/examples/lightning_training.py new file mode 100644 index 00000000000..b09f00d9473 --- /dev/null +++ b/experimental/torch_xla2/examples/lightning_training.py @@ -0,0 +1,77 @@ +import os, torch, torch.nn as nn, torch.utils.data as data, torchvision as tv +import lightning as L + +encoder = nn.Sequential(nn.Linear(28 * 28, 128), nn.ReLU(), nn.Linear(128, 3)) +decoder = nn.Sequential(nn.Linear(3, 128), nn.ReLU(), nn.Linear(128, 28 * 28)) + +class LitAutoEncoder(L.LightningModule): + def __init__(self, encoder, decoder): + super().__init__() + self.encoder, self.decoder = encoder, decoder + + def training_step(self, batch, batch_idx): + x, y = batch + x = x.view(x.size(0), -1) + z = self.encoder(x) + x_hat = self.decoder(z) + loss = nn.functional.mse_loss(x_hat, x) + self.log("train_loss", loss) + return loss + + def configure_optimizers(self): + return torch.optim.Adam(self.parameters(), lr=1e-3) + +dataset = tv.datasets.MNIST(".", download=True, transform=tv.transforms.ToTensor()) + +# Lightning will automatically use all available GPUs! +trainer = L.Trainer() +# trainer.fit(LitAutoEncoder(encoder, decoder), data.DataLoader(dataset, batch_size=64)) + +# ==== above is the lightning example from +# https://lightning.ai/pytorch-lightning + +import torch_xla2 +from torch_xla2.interop import jax_view, torch_view +import jax +import optax + +class JaxTrainer: + + def __init__(self): + pass + + def torch_opt_to_jax_opt(self, torch_opt): + # TODO: Can convert optimizer instead of using a jax one + return optax.adam(0.001) + + def fit(self, lightning_mod, data_loader): + + xla_env = torch_xla2.default_env() + + def lightning_mod_loss( + weights: jax.Array, data: jax.Array, batch_id): + """returns loss""" + weights, data = torch_view((weights, data)) + lightning_mod.load_state_dict(weights, assign=True) + with xla_env: + loss = lightning_mod.training_step(data, batch_id) + return jax_view(loss) + + jax_weights = jax_view(xla_env.to_xla(lightning_mod.state_dict())) + jax_optimizer = self.torch_opt_to_jax_opt( + lightning_mod.configure_optimizers()) + opt_state = jax_optimizer.init(jax_weights) + grad_fn = jax.jit(jax.value_and_grad(lightning_mod_loss)) + + for bid in range(3): + for item in data_loader: + xla_data = jax_view(xla_env.to_xla(item)) + loss, grads = grad_fn(jax_weights, xla_data, bid) + updates, opt_state = jax_optimizer.update(grads, opt_state) + jax_weights = optax.apply_updates(jax_weights, updates) + print('current_loss', loss) + + +print('-----------------') +trainer_jax = JaxTrainer() +trainer_jax.fit(LitAutoEncoder(encoder, decoder), data.DataLoader(dataset, batch_size=64)) diff --git a/experimental/torch_xla2/pyproject.toml b/experimental/torch_xla2/pyproject.toml index d0d2a42dec8..14b77ad0216 100644 --- a/experimental/torch_xla2/pyproject.toml +++ b/experimental/torch_xla2/pyproject.toml @@ -2,29 +2,29 @@ requires = ["hatchling"] build-backend = "hatchling.build" - [project] version = "0.0.1" name = "torch_xla2" dependencies = [ "absl-py", - "flatbuffers", + "immutabledict", "pytest", - "tensorflow", - - # Note: Exclude these because otherwise on pip install . - # pip will install libs from pypi which is the GPU version - # of these libs. - # We most likely need CPU version of torch and TPU version of - # jax. So it's best for users to install them by hand - # See more at README.md - # "jax>=0.4.24", - # "jaxlib>=0.4.24", - # "torch", + "tensorflow-cpu", + # Developers should install `dev-requirements.txt` first + "torch>=2.2.1", ] - requires-python = ">=3.10" license = {file = "LICENSE"} +[project.optional-dependencies] +cpu = ["jax[cpu]>=0.4.24", "jax[cpu]"] +# Add libtpu index `-f https://storage.googleapis.com/libtpu-releases/index.html` +tpu = ["jax[cpu]>=0.4.24", "jax[tpu]"] +cuda = ["jax[cpu]>=0.4.24", "jax[cuda12]"] + [tool.pytest.ini_options] addopts="-n auto" + +[tool.ruff] +line-length = 80 +indent-width = 2 diff --git a/experimental/torch_xla2/test-requirements.txt b/experimental/torch_xla2/test-requirements.txt new file mode 100644 index 00000000000..1deead455a1 --- /dev/null +++ b/experimental/torch_xla2/test-requirements.txt @@ -0,0 +1,5 @@ +-r dev-requirements.txt +pytest +pytest-xdist +sentencepiece +expecttest diff --git a/experimental/torch_xla2/test/gemma/test_gemma.py b/experimental/torch_xla2/test/gemma/test_gemma.py index bd0bb21dbb1..4d91bc6f9b0 100644 --- a/experimental/torch_xla2/test/gemma/test_gemma.py +++ b/experimental/torch_xla2/test/gemma/test_gemma.py @@ -74,7 +74,7 @@ def test_gemma(self): weights, jax_func = torch_xla2.extract_jax(model) inputs_jax = pytree.tree_map_only( - torch.Tensor, torch_xla2.tensor.move_to_device, inputs) + torch.Tensor, torch_xla2.tensor.t2j, inputs) import jax print(jax.jit(jax_func)(weights, inputs_jax)) diff --git a/experimental/torch_xla2/test/llama/test_llama.py b/experimental/torch_xla2/test/llama/test_llama.py index dae7bf0cc5c..083116ab89e 100644 --- a/experimental/torch_xla2/test/llama/test_llama.py +++ b/experimental/torch_xla2/test/llama/test_llama.py @@ -1,8 +1,5 @@ -import unittest -import jax import torch -from torch._functorch.make_functional import make_functional_with_buffers -from torch_xla2 import tensor, ops # pylint: disable=unused-import +from torch_xla2 import tensor # pylint: disable=unused-import import torch_xla2 from .. import test_base diff --git a/experimental/torch_xla2/test/moe/__init__.py b/experimental/torch_xla2/test/moe/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/experimental/torch_xla2/test/moe/model.py b/experimental/torch_xla2/test/moe/model.py new file mode 100644 index 00000000000..9249ac9dce0 --- /dev/null +++ b/experimental/torch_xla2/test/moe/model.py @@ -0,0 +1,260 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. + +# This source code is licensed under the license found in the +# LICENSE file in the root directory of this source tree. +from dataclasses import dataclass +from typing import Optional + +import torch +import torch.nn as nn +from torch import Tensor +from torch.nn import functional as F + + +def find_multiple(n: int, k: int) -> int: + if n % k == 0: + return n + return n + k - (n % k) + +@dataclass +class ModelArgs: + block_size: int = 2048 + vocab_size: int = 32000 + n_layer: int = 32 + n_head: int = 32 + dim: int = 4096 + intermediate_size: int = None + n_local_heads: int = -1 + head_dim: int = 64 + rope_base: float = 10000 + norm_eps: float = 1e-5 + num_experts: int = 8 + num_activated_experts: int = 2 + + def __post_init__(self): + if self.n_local_heads == -1: + self.n_local_heads = self.n_head + if self.intermediate_size is None: + hidden_dim = 4 * self.dim + n_hidden = int(2 * hidden_dim / 3) + self.intermediate_size = find_multiple(n_hidden, 256) + self.head_dim = self.dim // self.n_head + + @classmethod + def from_name(cls, name: str): + if name in transformer_configs: + return cls(**transformer_configs[name]) + # fuzzy search + config = [config for config in transformer_configs if config in str(name).upper() or config in str(name)] + assert len(config) == 1, name + return cls(**transformer_configs[config[0]]) + + +transformer_configs = { + "Mixtral-8x7B-v0.1": dict(block_size=32768, n_layer=32, n_head=32, n_local_heads=8, dim=4096, intermediate_size=14336, rope_base=1000000.0, num_experts=8, num_activated_experts=2), +} + +class KVCache(nn.Module): + def __init__(self, max_batch_size, max_seq_length, n_heads, head_dim, dtype=torch.bfloat16): + super().__init__() + cache_shape = (max_batch_size, n_heads, max_seq_length, head_dim) + self.register_buffer('k_cache', torch.zeros(cache_shape, dtype=dtype)) + self.register_buffer('v_cache', torch.zeros(cache_shape, dtype=dtype)) + + def update(self, input_pos, k_val, v_val): + # input_pos: [S], k_val: [B, H, S, D] + assert input_pos.shape[0] == k_val.shape[2] + + k_out = self.k_cache + v_out = self.v_cache + k_out[:, :, input_pos] = k_val + v_out[:, :, input_pos] = v_val + + return k_out, v_out + +class Transformer(nn.Module): + def __init__(self, config: ModelArgs) -> None: + super().__init__() + self.config = config + + self.tok_embeddings = nn.Embedding(config.vocab_size, config.dim) + self.layers = nn.ModuleList(TransformerBlock(config) for _ in range(config.n_layer)) + self.norm = RMSNorm(config.dim, eps=config.norm_eps) + self.output = nn.Linear(config.dim, config.vocab_size, bias=False) + + self.freqs_cis: Optional[Tensor] = None + self.mask_cache: Optional[Tensor] = None + self.max_batch_size = -1 + self.max_seq_length = -1 + + def setup_caches(self, max_batch_size, max_seq_length): + if self.max_seq_length >= max_seq_length and self.max_batch_size >= max_batch_size: + return + head_dim = self.config.dim // self.config.n_head + max_seq_length = find_multiple(max_seq_length, 8) + self.max_seq_length = max_seq_length + self.max_batch_size = max_batch_size + for b in self.layers: + b.attention.kv_cache = KVCache(max_batch_size, max_seq_length, self.config.n_local_heads, head_dim) + + self.freqs_cis = precompute_freqs_cis(self.config.block_size, self.config.dim // self.config.n_head, self.config.rope_base) + self.causal_mask = torch.tril(torch.ones(self.max_seq_length, self.max_seq_length, dtype=torch.bool)) + + def forward(self, idx: Tensor, input_pos: Optional[Tensor] = None) -> Tensor: + assert self.freqs_cis is not None, "Caches must be initialized first" + mask = self.causal_mask[None, None, input_pos] + freqs_cis = self.freqs_cis[input_pos] + x = self.tok_embeddings(idx) + + for i, layer in enumerate(self.layers): + x = layer(x, input_pos, freqs_cis, mask) + x = self.norm(x) + logits = self.output(x) + return logits + + @classmethod + def from_name(cls, name: str): + return cls(ModelArgs.from_name(name)) + + +class TransformerBlock(nn.Module): + def __init__(self, config: ModelArgs) -> None: + super().__init__() + self.attention = Attention(config) + self.block_sparse_moe = MOEFeedForward(config) + self.ffn_norm = RMSNorm(config.dim, config.norm_eps) + self.attention_norm = RMSNorm(config.dim, config.norm_eps) + + def forward(self, x: Tensor, input_pos: Tensor, freqs_cis: Tensor, mask: Tensor) -> Tensor: + h = x + self.attention(self.attention_norm(x), freqs_cis, mask, input_pos) + out = h + self.block_sparse_moe(self.ffn_norm(h)) + return out + + +class Attention(nn.Module): + def __init__(self, config: ModelArgs): + super().__init__() + assert config.dim % config.n_head == 0 + + total_head_dim = (config.n_head + 2 * config.n_local_heads) * config.head_dim + # key, query, value projections for all heads, but in a batch + self.wqkv = nn.Linear(config.dim, total_head_dim, bias=False) + self.wo = nn.Linear(config.dim, config.dim, bias=False) + self.kv_cache = None + + self.n_head = config.n_head + self.head_dim = config.head_dim + self.n_local_heads = config.n_local_heads + self.dim = config.dim + self._register_load_state_dict_pre_hook(self.load_hook) + + def load_hook(self, state_dict, prefix, *args): + if prefix + "wq.weight" in state_dict: + wq = state_dict.pop(prefix + "wq.weight") + wk = state_dict.pop(prefix + "wk.weight") + wv = state_dict.pop(prefix + "wv.weight") + state_dict[prefix + "wqkv.weight"] = torch.cat([wq, wk, wv]) + + def forward(self, x: Tensor, freqs_cis: Tensor, mask: Tensor, input_pos: Optional[Tensor] = None) -> Tensor: + bsz, seqlen, _ = x.shape + + kv_size = self.n_local_heads * self.head_dim + q, k, v = self.wqkv(x).split([self.dim, kv_size, kv_size], dim=-1) + + q = q.view(bsz, seqlen, self.n_head, self.head_dim) + k = k.view(bsz, seqlen, self.n_local_heads, self.head_dim) + v = v.view(bsz, seqlen, self.n_local_heads, self.head_dim) + + q = apply_rotary_emb(q, freqs_cis) + k = apply_rotary_emb(k, freqs_cis) + + q, k, v = map(lambda x: x.transpose(1, 2), (q, k, v)) + + if self.kv_cache is not None: + k, v = self.kv_cache.update(input_pos, k, v) + + k = k.repeat_interleave(self.n_head // self.n_local_heads, dim=1) + v = v.repeat_interleave(self.n_head // self.n_local_heads, dim=1) + y = F.scaled_dot_product_attention(q, k, v, attn_mask=mask, dropout_p=0.0) + + y = y.transpose(1, 2).contiguous().view(bsz, seqlen, self.dim) + + y = self.wo(y) + return y + + +class ConditionalFeedForward(nn.Module): + def __init__(self, config): + super().__init__() + self.w1 = nn.Parameter(torch.empty(config.num_experts, config.intermediate_size, config.dim)) + self.w2 = nn.Parameter(torch.empty(config.num_experts, config.dim, config.intermediate_size)) + self.w3 = nn.Parameter(torch.empty(config.num_experts, config.intermediate_size, config.dim)) + + def forward(self, x: Tensor, expert_indices: Tensor) -> Tensor: + w1_weights = self.w1[expert_indices] # [T, A, D, D] + w3_weights = self.w3[expert_indices] # [T, A, D, D] + w2_weights = self.w2[expert_indices] # [T, A, D, D] + x1 = F.silu(torch.einsum('ti,taoi -> tao', x, w1_weights)) + x3 = torch.einsum('ti, taoi -> tao', x, w3_weights) + expert_outs = torch.einsum('tao, taio -> tai', (x1 * x3), w2_weights) + return expert_outs + + +class MOEFeedForward(nn.Module): + def __init__(self, config) -> None: + super().__init__() + self.gate = nn.Linear(config.dim, config.num_experts, bias=False) + self.cond_ffn = ConditionalFeedForward(config) + self.dim = config.dim + self.num_activated_experts = config.num_activated_experts + def forward(self, x: Tensor) -> Tensor: + x = x.view(-1, self.dim) + # T = num_tokens, E = num_experts, D = hidden dim, A = activated experts + # x: [T, D] + scores = self.gate(x) # [T, E] + expert_weights = F.softmax(scores, dim=-1) + expert_weights, expert_indices = torch.topk(expert_weights, self.num_activated_experts, dim=-1) # [T, A], [T, A] + expert_weights /= expert_weights.sum(dim=-1, keepdim=True) # [T, A] + expert_outs = self.cond_ffn(x, expert_indices) + return torch.einsum('tai,ta -> ti', expert_outs, expert_weights) + + +class RMSNorm(nn.Module): + def __init__(self, dim: int, eps: float = 1e-5): + super().__init__() + self.eps = eps + self.weight = nn.Parameter(torch.ones(dim)) + + def _norm(self, x): + return x * torch.rsqrt(torch.mean(x * x, dim=-1, keepdim=True) + self.eps) + + def forward(self, x: Tensor) -> Tensor: + output = self._norm(x.float()).type_as(x) + return output * self.weight + + +def precompute_freqs_cis( + seq_len: int, n_elem: int, base: int = 10000 +) -> Tensor: + freqs = 1.0 / (base ** (torch.arange(0, n_elem, 2)[: (n_elem // 2)].float() / n_elem)) + t = torch.arange(seq_len, device=freqs.device) + freqs = torch.outer(t, freqs) + freqs_cis = torch.polar(torch.ones_like(freqs), freqs) + cache = torch.stack([freqs_cis.real, freqs_cis.imag], dim=-1) + return cache.to(dtype=torch.bfloat16) + + +def apply_rotary_emb(x: Tensor, freqs_cis: Tensor) -> Tensor: + xshaped = x.float().reshape(*x.shape[:-1], -1, 2) + freqs_cis = freqs_cis.view(1, xshaped.size(1), 1, xshaped.size(3), 2) + x_out2 = torch.stack( + [ + xshaped[..., 0] * freqs_cis[..., 0] - xshaped[..., 1] * freqs_cis[..., 1], + xshaped[..., 1] * freqs_cis[..., 0] + xshaped[..., 0] * freqs_cis[..., 1], + ], + -1, + ) + + x_out2 = x_out2.flatten(3) + return x_out2.type_as(x) diff --git a/experimental/torch_xla2/test/moe/moe_test.py b/experimental/torch_xla2/test/moe/moe_test.py new file mode 100644 index 00000000000..f8d4a22e3f2 --- /dev/null +++ b/experimental/torch_xla2/test/moe/moe_test.py @@ -0,0 +1,75 @@ +import torch_xla2 +import torch_xla2.interop +import torch +import unittest +import jax + + +from test.moe import model + + +class TestMoe(unittest.TestCase): + + def _make_tiny_config(self): + return model.ModelArgs( + block_size = 128, + vocab_size = 32000, + n_layer = 4, + n_head = 4, + dim = 128, + intermediate_size = None, + n_local_heads = -1, + head_dim = 32, + rope_base = 10000, + norm_eps = 1e-5, + num_experts = 8, + num_activated_experts = 2, + ) + + def _random_init(self, model): + new_state_dict = {} + + for k, v in model.state_dict().items(): + new_state_dict[k] = torch.randn_like(v) + + model.load_state_dict(new_state_dict, assign=True) + return model + + + + def test_moe_layer(self): + model_args = self._make_tiny_config() + + moe_layer = model.MOEFeedForward(model_args) + moe_layer = self._random_init(moe_layer) + seqlen = 32 + x = torch.randn((seqlen, model_args.dim)) + res = moe_layer(x) + + env = torch_xla2.default_env() + model_xla = env.to_xla(moe_layer) + x_xla = env.to_xla(x) + with jax.default_matmul_precision('float32'): + res_xla = model_xla(x_xla) + res2 = torch_xla2.tensor.j2t(res_xla._elem) + print('max diff', torch.max((res - res2).abs())) + + self.assertTrue( + torch.allclose(res2, res, atol=1e-2)) + + # test can jit + + def f(weights, x): + return torch.func.functional_call(moe_layer, weights, (x, )) + + fjitted = torch_xla2.interop.jax_jit(f) + weights_xla = env.to_xla(moe_layer.state_dict()) + + print(fjitted(weights_xla, x_xla)) + + + + + +if __name__ == '__main__': + unittest.main() diff --git a/experimental/torch_xla2/test/test_context.py b/experimental/torch_xla2/test/test_context.py index 1a75a7d23d0..a6bcda5113a 100644 --- a/experimental/torch_xla2/test/test_context.py +++ b/experimental/torch_xla2/test/test_context.py @@ -1,20 +1,22 @@ import unittest import torch -import torch_xla2 from torch_xla2 import tensor +xla_env = tensor.Environment(0) + class TestContext(unittest.TestCase): + def test_mode_context_manager(self): - with torch_xla2.mode(): + with xla_env: x = torch.full((3, 3), -1) self.assertIsInstance(x, tensor.XLATensor2) y = x.abs() self.assertIsInstance(y, tensor.XLATensor2) @staticmethod - @torch_xla2.mode() + @xla_env def _test_mode_decorator(): x = torch.full((3, 3), -1) y = x.abs() diff --git a/experimental/torch_xla2/test/test_core_aten_ops.py b/experimental/torch_xla2/test/test_core_aten_ops.py index 357e41c9101..c11884fa370 100644 --- a/experimental/torch_xla2/test/test_core_aten_ops.py +++ b/experimental/torch_xla2/test/test_core_aten_ops.py @@ -1,7 +1,6 @@ import unittest import torch -from torch_xla2 import ops_registry from torch_xla2 import tensor from . import test_base @@ -34,12 +33,13 @@ def run_export_and_compare(testcase, rtol=1e-5, equal_nan=True, ignore_indices=False): + with testcase.subTest("torch_eval"): res = func(*args, **kwargs) with testcase.subTest("torch_xla2_eval"): - args2, kwargs2 = pytree.tree_map_only(torch.Tensor, tensor.move_to_device, - (args, kwargs)) - res2 = func(*args2, **kwargs2) + args2, kwargs2 = testcase.env.to_xla((args, kwargs)) + with testcase.env: + res2 = func(*args2, **kwargs2) res2 = pytree.tree_map_only(tensor.XLATensor2, lambda t: t.torch(), res2) # import pdb; pdb.set_trace() with testcase.subTest("torch_xla2_diff:" + str(atol)): @@ -61,11 +61,11 @@ class TestCoreAtenOps(unittest.TestCase): @classmethod def setUpClass(cls): super().setUpClass() - ops_registry.print_missing_ops() def setUp(self): super().setUp() torch.manual_seed(0) + self.env = tensor.Environment(0) def test_aten_abs_0(self): args = (torch.randn((10, 10)).to(torch.float32),) @@ -2109,7 +2109,7 @@ def test_aten_logit_0(self): def test_aten_logit_1(self): args = (torch.randn((10, 10)).to(torch.float16),) kwargs = dict() - run_export_and_compare(self, torch.ops.aten.logit, args, kwargs) + run_export_and_compare(self, torch.ops.aten.logit, args, kwargs, atol=0.01,) def test_aten_logit_2(self): args = (torch.randint(0, 10, (10, 10)).to(torch.int32),) @@ -2697,6 +2697,117 @@ def test_aten_native_layer_norm_0(self): kwargs = dict() run_export_and_compare(self, torch.ops.aten.native_layer_norm, args, kwargs) + def test_aten_native_batch_norm_legit(self): + batch = 3 + channel = 2 + args = ( + torch.randn((batch,channel,2,2)).to(torch.float32), + torch.ones(channel), + torch.zeros(channel), + torch.zeros(channel), + torch.ones(channel), + False, + 0.5, + 1, + ) + kwargs = dict() + run_export_and_compare(self, torch.ops.aten._native_batch_norm_legit, args, kwargs) + + def test_aten_native_batch_norm_legit_none(self): + batch = 3 + channel = 2 + args = ( + torch.randn((batch,channel,4,4)).to(torch.float32), + None, + None, + torch.ones(channel), + torch.zeros(channel), + False, + 0.5, + 1, + ) + kwargs = dict() + run_export_and_compare(self, torch.ops.aten._native_batch_norm_legit, args, kwargs) + + def test_aten_native_batch_norm_legit_training_none(self): + batch = 3 + channel = 2 + args = ( + torch.randn((batch,channel,4,3)).to(torch.float32), + None, + None, + torch.zeros(channel), + torch.ones(channel), + True, + 0.2, + 2e-5, + ) + kwargs = dict() + run_export_and_compare(self, torch.ops.aten._native_batch_norm_legit, args, kwargs) + + def test_aten_native_batch_norm_legit_no_training(self): + batch = 3 + channel = 2 + args = ( + torch.randn((batch,channel,4,3)).to(torch.float32), + torch.ones(channel), + torch.zeros(channel), + torch.zeros(channel), + torch.ones(channel), + 0.2, + 2e-5, + ) + kwargs = dict() + run_export_and_compare(self, torch.ops.aten._native_batch_norm_legit_no_training, args, kwargs) + + def test_aten_native_batch_norm_training(self): + batch = 3 + channel = 2 + args = ( + torch.randn((batch,channel,4,3)).to(torch.float32), + torch.ones(channel), + torch.zeros(channel), + torch.zeros(channel), + torch.ones(channel), + True, + 0.1, + 1e-5, + ) + kwargs = dict() + run_export_and_compare(self, torch.ops.aten.native_batch_norm, args, kwargs) + + def test_aten_native_batch_norm_training_none(self): + batch = 3 + channel = 2 + args = ( + torch.randn((batch,channel,4,3)).to(torch.float32), + None, + None, + torch.zeros(channel), + torch.ones(channel), + True, + 0.1, + 1e-5, + ) + kwargs = dict() + run_export_and_compare(self, torch.ops.aten.native_batch_norm, args, kwargs) + + def test_aten_native_batch_norm_eval(self): + batch = 3 + channel = 2 + args = ( + torch.randn((batch,channel,4,3)).to(torch.float32), + torch.ones(channel), + torch.zeros(channel), + torch.zeros(channel), + torch.ones(channel), + False, + 0.2, + 2e-5, + ) + kwargs = dict() + run_export_and_compare(self, torch.ops.aten.native_batch_norm, args, kwargs) + def test_aten_ne_Scalar_0(self): args = ( torch.randint(0, 10, (10, 10)).to(torch.int32), @@ -3639,8 +3750,9 @@ def test_aten__softmax_1(self): def _compare_sorted_result(self, args): res = torch.ops.aten.sort(*args) with self.subTest("torch_xla2_eval"): - args2 = pytree.tree_map_only(torch.Tensor, tensor.move_to_device, args) - res2 = torch.ops.aten.sort(*args2) + args2 = self.env.to_xla(args) + with self.env: + res2 = torch.ops.aten.sort(*args2) # The second argument is the sorted index. These might not be # identical from torch vs. jax; but both can be correct diff --git a/experimental/torch_xla2/test/test_exports.py b/experimental/torch_xla2/test/test_exports.py index 81e91452c02..ce465324a4c 100644 --- a/experimental/torch_xla2/test/test_exports.py +++ b/experimental/torch_xla2/test/test_exports.py @@ -34,33 +34,109 @@ def setUp(self): def test_interpolate(self): + # Check Accuracy arg = (torch.randn(3, 3, 200, 200),) model = Interpolate() - ans = model(*arg) with torch.no_grad(): exported = torch.export.export(model, arg) - weights, func = torch_xla2.export.exported_program_to_jax(exported) - argj = tensor.t2j(arg[0]) - ans2 = jax.jit(func)(weights, (argj,))[0] - ans2 = tensor.j2t(ans2) - self.assertTrue(torch.allclose(ans, ans2, atol=1e-3)) + weights, func = torch_xla2.export.exported_program_to_jax(exported) + argj = tensor.t2j(arg[0]) + ans2 = jax.jit(func)(weights, (argj,))[0] + ans2 = tensor.j2t(ans2) + self.assertTrue(torch.allclose(ans, ans2, atol=1e-3)) + + # Convert to StableHLO + stablehlo = torch_xla2.export.exported_program_to_stablehlo(exported) + module_str = str(stablehlo.mlir_module()) + self.assertIn("func.func public @main", module_str) + self.assertIn("func.func private @clip(%arg0: tensor<500xf32>", module_str) + self.assertIn("stablehlo.minimum", module_str) def test_constant(self): + # Check Accuracy arg = (torch.randn(10, 10),) model = TensorConstant() - ans = model(*arg) with torch.no_grad(): exported = torch.export.export(model, arg) - weights, func = torch_xla2.export.exported_program_to_jax(exported) - argj = tensor.t2j(arg[0]) - ans2 = jax.jit(func)(weights, (argj,))[0] - ans2 = tensor.j2t(ans2) - self.assertTrue(torch.allclose(ans, ans2, atol=1e-5)) + + weights, func = torch_xla2.export.exported_program_to_jax(exported) + argj = tensor.t2j(arg[0]) + ans2 = jax.jit(func)(weights, (argj,))[0] + ans2 = tensor.j2t(ans2) + self.assertTrue(torch.allclose(ans, ans2, atol=1e-5)) + + # Convert to StableHLO + stablehlo = torch_xla2.export.exported_program_to_stablehlo(exported) + module_str = str(stablehlo.mlir_module()) + self.assertIn("func.func public @main", module_str) + self.assertIn("stablehlo.divide", module_str) + + def test_interpolate_dynamic(self): + # Export with dynamic dimension constraints on both min and max + arg = (torch.randn(3, 3, 200, 200),) + model = Interpolate() + ans = model(*arg) + dynamic_shapes = ({0: torch.export.Dim("b", min=3, max=10)},) + + with torch.no_grad(): + exported = torch.export.export(model, arg, dynamic_shapes=dynamic_shapes) + stablehlo = torch_xla2.export.exported_program_to_stablehlo(exported) + module_str = str(stablehlo.mlir_module()) + + # Look for dynamic shape artifacts + self.assertIn("func.func public @main(%arg0: tensor", module_str) + self.assertIn("stablehlo.dynamic_broadcast_in_dim", module_str) + self.assertIn("stablehlo.dynamic_gather", module_str) + + def test_export_dtypes(self): + DTYPE_TO_MLIR_STR = { + # NO_MAPPING : jnp.float0 (signless scalar int) + torch.bool : "i1", + # NO_MAPPING : "i4" + torch.int8 : "i8", + torch.int16 : "i16", + torch.int32 : "i32", + torch.int64 : "i64", + torch.long : "i64", + # NO_MAPPING : "ui4" + torch.uint8 : "ui8", + torch.uint16 : "ui16", + torch.uint32 : "ui32", + torch.uint64 : "ui64", + # NO_MAPPING : "f8E4M3B11FNUZ" + torch.float8_e4m3fn : "f8E4M3FN", + # NO_MAPPING : f8E4M3FNUZ + torch.float8_e5m2 : "f8E5M2", + # NO_MAPPING : f8E5M2FNUZ + torch.bfloat16 : "bf16", + torch.half : "f16", + torch.float16 : "f16", + torch.float32 : "f32", + torch.float64 : "f64", + torch.double : "f64", + torch.complex64 : "complex", + torch.complex128 : "complex", + None : None, + } + + model = TensorConstant() + for torch_dtype in torch_xla2.tensor.TORCH_DTYPE_TO_JAX.keys(): + if torch_dtype == None: + ## TODO: Figure out what the None mapping should be, seems like: + ## torch.tensor(dtype=None) maps to f32 + ## jnp.tensor(dtype=None) maps to f64 + continue + arg = (torch.randn(10).to(torch_dtype),) + with torch.no_grad(): + exported = torch.export.export(model, arg) + stablehlo = torch_xla2.export.exported_program_to_stablehlo(exported) + module_str = str(stablehlo.mlir_module()) + self.assertIn(DTYPE_TO_MLIR_STR[torch_dtype], module_str) if __name__ == '__main__': diff --git a/experimental/torch_xla2/test/test_extra.py b/experimental/torch_xla2/test/test_extra.py deleted file mode 100644 index 768488d6a99..00000000000 --- a/experimental/torch_xla2/test/test_extra.py +++ /dev/null @@ -1,64 +0,0 @@ -import unittest -import torch -import torch.nn.functional as F -import jax -import jax.numpy as jnp -import torch_xla2 -from torch_xla2 import tensor, extra - - -class ExtraTest(unittest.TestCase): - - def setUp(self): - torch.manual_seed(0) - - def test_standard_callable(self): - def f(a, b): - return torch.add(a, b) - - a = jnp.ones((10, )) - b = jnp.ones((10, )) - - c = extra.jax_view(f)(a, b) - self.assertTrue(jnp.allclose(c, a + b)) - - def f2(a, b): - return jnp.add(a, b) - - a = tensor.move_to_device(torch.ones((10, ))) - b = tensor.move_to_device(torch.ones((10, ))) - c2 = extra.torch_view(f2)(a, b) - - self.assertTrue(jnp.allclose(c2._elem, c)) - - - - def test_fori_loop(self): - a = tensor.move_to_device(torch.ones((10, 10))) - - def body(i, c): - return c + a[i] - - init_val = tensor.move_to_device(torch.zeros(10)) - res = extra.fori_loop(0, 10, body, init_val) - expect = torch.ones(10) * 10 - self.assertTrue(torch.allclose(tensor.j2t(res._elem), expect)) - - def test_jax_jit(self): - - # functions that acts on torch tensor - def f(a, b): - return torch.sin(a) + torch.cos(b) - - fjitted = extra.jax_jit(f) - a = torch.rand((10, 10)) - b = torch.rand((10, 10)) - aj = tensor.move_to_device(a) - bj = tensor.move_to_device(b) - res = f(a, b) - res2 = fjitted(aj, bj) - self.assertTrue(torch.allclose(res, tensor.j2t(res2._elem))) - - -if __name__ == '__main__': - unittest.main() diff --git a/experimental/torch_xla2/test/test_functions.py b/experimental/torch_xla2/test/test_functions.py index 76e842d6fdd..2d624b25b5b 100644 --- a/experimental/torch_xla2/test/test_functions.py +++ b/experimental/torch_xla2/test/test_functions.py @@ -3,12 +3,14 @@ from absl.testing import parameterized import torch import torch_xla2 -import torch_xla2.functions import torch_xla2.tensor class TestTorchFunctions(parameterized.TestCase): + def setUp(self): + self.env = torch_xla2.tensor.Environment(0) + @parameterized.named_parameters( ('tensor_2d', lambda: torch.tensor([[0.1, 1.2], [2.2, 3.1], [4.9, 5.2]])), ('tensor_1d', lambda: torch.tensor([0, 1],)), @@ -32,7 +34,7 @@ class TestTorchFunctions(parameterized.TestCase): def test_tensor_constructor(self, func: Callable[[], torch.Tensor]): expected = func() - with torch_xla2.functions.XLAFunctionMode(): + with self.env: actual = func() self.assertIsInstance(actual, torch_xla2.tensor.XLATensor2) diff --git a/experimental/torch_xla2/test/test_mutations.py b/experimental/torch_xla2/test/test_mutations.py index 2f9ddca975b..50d78aa0fae 100644 --- a/experimental/torch_xla2/test/test_mutations.py +++ b/experimental/torch_xla2/test/test_mutations.py @@ -6,46 +6,43 @@ class TestMutations(TestCase): - def test_add(self): - x = torch.tensor([1, 2, 3], dtype=torch.int32) - y = torch.tensor([4, 5, 6], dtype=torch.int32) + def setUp(self): + self.env = torch_xla2.tensor.Environment(0) - x = torch_xla2.tensor.move_to_device(x) - y = torch_xla2.tensor.move_to_device(y) - x.add_(y) - xt = torch_xla2.tensor.j2t(x._elem) - self.assertEqual(xt, torch.tensor([5, 7, 9], dtype=torch.int32)) + def test_add(self): + with self.env: + x = torch.tensor([1, 2, 3], dtype=torch.int32) + y = torch.tensor([4, 5, 6], dtype=torch.int32) + x.add_(y) + xt = torch_xla2.tensor.j2t(x._elem) + self.assertEqual(xt, torch.tensor([5, 7, 9], dtype=torch.int32)) def test_sub(self): - x = torch.tensor([1, 2, 3], dtype=torch.int32) - y = torch.tensor([4, 5, 6], dtype=torch.int32) - - x = torch_xla2.tensor.move_to_device(x) - y = torch_xla2.tensor.move_to_device(y) - x.sub_(y) - xt = torch_xla2.tensor.j2t(x._elem) - self.assertEqual(xt, torch.tensor([-3, -3, -3], dtype=torch.int32)) + with self.env: + x = torch.tensor([1, 2, 3], dtype=torch.int32) + y = torch.tensor([4, 5, 6], dtype=torch.int32) + x.sub_(y) + xt = torch_xla2.tensor.j2t(x._elem) + self.assertEqual(xt, torch.tensor([-3, -3, -3], dtype=torch.int32)) def test_mul(self): - x = torch.tensor([1, 2, 3], dtype=torch.int32) - y = torch.tensor([4, 5, 6], dtype=torch.int32) + with self.env: + x = torch.tensor([1, 2, 3], dtype=torch.int32) + y = torch.tensor([4, 5, 6], dtype=torch.int32) - x = torch_xla2.tensor.move_to_device(x) - y = torch_xla2.tensor.move_to_device(y) - x.mul_(y) - xt = torch_xla2.tensor.j2t(x._elem) - self.assertEqual(xt, torch.tensor([4, 10, 18], dtype=torch.int32)) + x.mul_(y) + xt = torch_xla2.tensor.j2t(x._elem) + self.assertEqual(xt, torch.tensor([4, 10, 18], dtype=torch.int32)) def test_div(self): - x = torch.tensor([1, 2, 3], dtype=torch.int32) - y = torch.tensor([4, 5, 6], dtype=torch.int32) - - x = torch_xla2.tensor.move_to_device(x) - y = torch_xla2.tensor.move_to_device(y) - x.div_(y) - xt = torch_xla2.tensor.j2t(x._elem) - self.assertEqual(xt, - torch.tensor([1. / 4, 2. / 5, 3. / 6], dtype=torch.float)) + with self.env: + x = torch.tensor([1, 2, 3], dtype=torch.int32) + y = torch.tensor([4, 5, 6], dtype=torch.int32) + + x.div_(y) + xt = torch_xla2.tensor.j2t(x._elem) + self.assertEqual(xt, + torch.tensor([1. / 4, 2. / 5, 3. / 6], dtype=torch.float)) if __name__ == '__main__': diff --git a/experimental/torch_xla2/test/test_ops.py b/experimental/torch_xla2/test/test_ops.py index ed14e636e5c..1e10706f100 100644 --- a/experimental/torch_xla2/test/test_ops.py +++ b/experimental/torch_xla2/test/test_ops.py @@ -8,26 +8,13 @@ from torch.utils import _pytree as pytree from torch_xla2 import tensor + skiplist = { "__getitem__", "__rmatmul__", "__rpow__", - "_native_batch_norm_legit", "_segment_reduce", "_upsample_bilinear2d_aa", - "addbmm", - "addmm", - "addmv", - "addr", - "all", - "allclose", - "amax", - "amin", - "aminmax", - "angle", - "any", - "argmax", - "argmin", "argsort", "as_strided", "as_strided_scatter", @@ -210,7 +197,6 @@ "nansum", "narrow_copy", "narrow", - "native_batch_norm", "native_layer_norm", "new_empty", "new_empty_strided", @@ -570,6 +556,7 @@ "special.xlog1py", "split", "split_with_sizes", + "split_with_sizes_copy", "sqrt", "square", "stack", @@ -636,10 +623,10 @@ def run_export_and_compare(testcase, with testcase.subTest("torch_eval"): res = func(sample_input.input, *sample_input.args, **sample_input.kwargs) with testcase.subTest("torch_xla2_eval"): - input2, args2, kwargs2 = pytree.tree_map_only( - torch.Tensor, tensor.move_to_device, - (sample_input.input, sample_input.args, sample_input.kwargs)) - res2 = func(input2, *args2, **kwargs2) + input2, args2, kwargs2 = testcase.env.to_xla(( + sample_input.input, sample_input.args, sample_input.kwargs)) + with testcase.env: + res2 = func(input2, *args2, **kwargs2) res2 = pytree.tree_map_only(tensor.XLATensor2, lambda t: t.torch(), res2) with testcase.subTest("torch_xla2_diff:" + str(atol)): if ignore_indices and isinstance(res, tuple) and len(res) == 2: @@ -664,6 +651,9 @@ class TestOpInfo(TestCase): def setUpClass(cls): print('op_db size: ', len(op_db), 'testing: ', len(ops_to_test)) + def setUp(self): + self.env = tensor.Environment(0) + @ops(ops_to_test, allowed_dtypes=(torch.float32, torch.long)) def test_reference_eager(self, device, dtype, op): sample_inputs = op.sample_inputs(device, dtype) diff --git a/experimental/torch_xla2/test/test_symbolic_shapes.py b/experimental/torch_xla2/test/test_symbolic_shapes.py new file mode 100644 index 00000000000..42e9778893a --- /dev/null +++ b/experimental/torch_xla2/test/test_symbolic_shapes.py @@ -0,0 +1,92 @@ +import unittest +import torch +import jax +import torch_xla2 + +class AddOne(torch.nn.Module): + + def __init__(self): + super().__init__() + + def forward(self, a): + return a + 1 + +class ConcatAddModel(torch.nn.Module): + def __init__(self): + super().__init__() + + def forward(self, a, b): + a = torch.concat([a, a], dim=0) + return a + b + +class SymbolicShapeTest(unittest.TestCase): + """Test possible symbolic shape computations that upstream torch export can + emit. Seems to be currently limited to a few binary math operations where one + operand is a symbolic variable/expr and the other is a constant integer. + """ + + def setUp(self): + torch.manual_seed(0) + + def test_constraints_min_max(self): + """Test a model with basic min/max dimension restrictions + """ + + # Arg shapes are a=s0{<=10}, b=s0*2 + model = AddOne() + args = (torch.rand(5),) + sym_a = torch.export.Dim("a", min=3, max=10) + dynamic_shapes = ({0: sym_a},) + + with torch.no_grad(): + exported = torch.export.export(model, args=args, dynamic_shapes=dynamic_shapes) + stablehlo = torch_xla2.export.exported_program_to_stablehlo(exported) + module_str = str(stablehlo.mlir_module()) + + self.assertRegex(module_str, r"stablehlo.constant.*3") + self.assertRegex(module_str, r"shape_assertion.*s[0-9]+ >= 3") + self.assertRegex(module_str, r"stablehlo.constant.*10") + self.assertRegex(module_str, r"shape_assertion.*s[0-9]+ <= 10") + + def test_constraints_multiply(self): + """Test a model with a slightly more complex constraint, where the input + shapes are determined by an equation of the other, in this case input shapes + are s0{<=10} and s0*2. + """ + # Arg shapes are a=s0{<=10}, b=s0*2 + model = ConcatAddModel() + args = (torch.rand(2),torch.rand(4)) + sym_a = torch.export.Dim("a", max=10) + sym_b = sym_a*2 + dynamic_shapes = ({0: sym_a}, {0: sym_b}) + + with torch.no_grad(): + exported = torch.export.export(model, args=args, dynamic_shapes=dynamic_shapes) + stablehlo = torch_xla2.export.exported_program_to_stablehlo(exported) + module_str = str(stablehlo.mlir_module()) + + self.assertRegex(module_str, r"stablehlo.constant.*10") + self.assertRegex(module_str, r"shape_assertion.*s[0-9]+ <= 10") + self.assertRegex(module_str, r"stablehlo.constant.*2") + self.assertRegex(module_str, r"shape_assertion.*2\*s[0-9]+") + + def test_constraint_indirection(self): + """Test a model where none of the shapes are directly symbolic variables + but all are expressions of symints that don't appear directly in the model. + """ + + # Arg shapes are b=s0{<=10}*2 + args = (torch.randn(10, 10),) + model = AddOne() + sym_a = torch.export.Dim("a", max=10) + sym_b = sym_a*2 + dynamic_shapes = ({0: sym_b},) + + with torch.no_grad(): + exported = torch.export.export(model, args=args, dynamic_shapes=dynamic_shapes) + stablehlo = torch_xla2.export.exported_program_to_stablehlo(exported) + module_str = str(stablehlo.mlir_module()) + + self.assertRegex(module_str, r"shape_assertion.*s[0-9]+ <= 10") + self.assertRegex(module_str, r"shape_assertion.*2\*s[0-9]+") + diff --git a/experimental/torch_xla2/test/test_unbounded_dynamism.py b/experimental/torch_xla2/test/test_unbounded_dynamism.py new file mode 100644 index 00000000000..0cd800cb1a7 --- /dev/null +++ b/experimental/torch_xla2/test/test_unbounded_dynamism.py @@ -0,0 +1,662 @@ +import re +import sys +import unittest + +import numpy as np +import torch +from torch.export import Dim, export +from torch_xla2.export import exported_program_to_stablehlo as exp2shlo + +## This file is copied from `xla/test/stablehlo/test_unbounded_dynamism.py` +## To test that torch_xla2 has identical behavior. +## The only differences in this test files are that torch_xla2 export preserves +## argument order more often than torch_xla export. +## +## This broke ~5 tests, for example: test_bmm_dynamic_out_dim +## args = ( +## torch.rand((8, 128, 256)), +## torch.rand((8, 256, 3)), +## ) +## dynamic_shapes = ((None, {2: Dim("dim")}),) +## ... +## torch_xla_regex = r'%arg.: tensor<8x256x\?xf32>.*%arg.: tensor<8x128x256xf32>.*->.*tensor<8x128x\?xf32>' +## torch_xla2_regex = r'%arg.: tensor<8x128x256xf32>.*%arg.: tensor<8x256x\?xf32>.*->.*tensor<8x128x\?xf32>' + +# Shim to run tests +class ExportAdapter(): + def __init__(self, export): + self.export = export + + def get_stablehlo_text(self): + return self.export.mlir_module() + +def exported_program_to_stablehlo(exported): + return ExportAdapter(exp2shlo(exported)) + +def wrap_func_as_nn_module(f): + class M(torch.nn.Module): + def __init__(self): + super().__init__() + + def forward(self, *args): + return f(*args) + return M().eval() + +class UnboundedDynamismExportTest(unittest.TestCase): + + def test_add(self): + args = (torch.rand((10, 197, 768)), torch.rand((10, 197, 768))) + dynamic_shapes = (({0: Dim("dim")}, {0: Dim("dim")}),) + m = wrap_func_as_nn_module(torch.ops.aten.add.Tensor) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search( + r'tensor<\?x197x768xf32>.*tensor<\?x197x768xf32>.*->.*tensor<\?x197x768xf32>', + shlo_text) is not None) + + def test_add_scalar(self): + args = (torch.rand((10, 197, 768)), 0.345) + dynamic_shapes = (({0: Dim("dim")}, None),) + m = wrap_func_as_nn_module(torch.ops.aten.add.Tensor) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search(r'tensor<\?x197x768xf32>.*->.*tensor<\?x197x768xf32>', + shlo_text) is not None) + + def test_addmm(self): + args = (torch.rand((5)), torch.rand((10, 5)), torch.rand((5, 5))) + dynamic_shapes = ((None, {0: Dim("dim")}, None),) + m = wrap_func_as_nn_module(torch.ops.aten.addmm.default) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search(r'tensor<\?x5xf32>.*->.*tensor<\?x5xf32>', shlo_text) + is not None) + + def test_bmm(self): + args = ( + torch.rand((24, 197, 64)), + torch.rand((24, 64, 197)), + ) + dynamic_shapes = (({0: Dim("dim")}, {0: Dim("dim")}),) + m = wrap_func_as_nn_module(torch.ops.aten.bmm.default) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search( + r'%arg.: tensor<\?x197x64xf32>.*%arg.: tensor<\?x64x197xf32>.*->.*tensor<\?x197x197xf32>', + shlo_text) is not None) + + def test_bmm_dynamic_out_dim(self): + args = ( + torch.rand((8, 128, 256)), + torch.rand((8, 256, 3)), + ) + dynamic_shapes = ((None, {2: Dim("dim")}),) + m = wrap_func_as_nn_module(torch.ops.aten.bmm.default) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search( + r'%arg.: tensor<8x128x256xf32>.*%arg.: tensor<8x256x\?xf32>.*->.*tensor<8x128x\?xf32>', + shlo_text) is not None) + + def test_bmm_dynamic_reduction_dim(self): + args = ( + torch.rand((8, 128, 3)), + torch.rand((8, 3, 256)), + ) + dynamic_shapes = (({2: Dim("dim")}, {1: Dim("dim")}),) + m = wrap_func_as_nn_module(torch.ops.aten.bmm.default) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search( + r'%arg.: tensor<8x128x\?xf32>.*%arg.: tensor<8x\?x256xf32>.*->.*tensor<8x128x256xf32>', + shlo_text) is not None) + + def test_cat(self): + args = (torch.rand((10, 1, 768)), torch.rand((10, 196, 768))) + dynamic_shapes = (({0: Dim("dim")}, {0: Dim("dim")}),) + m = wrap_func_as_nn_module( + lambda x, y: torch.ops.aten.cat.default([x, y], 1)) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search( + r'%arg.: tensor<\?x1x768xf32>.*%arg.: tensor<\?x196x768xf32>.*->.*tensor<\?x197x768xf32>', + shlo_text) is not None) + + def test_conv(self): + args = ( + torch.rand((10, 3, 224, 224)), + torch.rand((5, 3, 16, 16)), + torch.rand((5)), + ) + dynamic_shapes = (({0: Dim("dim")}, None, None),) + m = wrap_func_as_nn_module( + lambda x, y, z: torch.ops.aten.convolution.default( + x, + y, + z, + [16, 16], + [0, 0], + [1, 1], + False, + [0, 0], + 1, + )) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search(r'tensor<\?x3x224x224xf32>.*->.*tensor<\?x5x14x14xf32>', + shlo_text) is not None) + + def test_conv1d(self): + args = ( + torch.rand((3, 1, 800)), + torch.rand((512, 1, 10)), + ) + dynamic_shapes = (({0: Dim("dim")}, None),) + # dynamic_shapes = None + m = wrap_func_as_nn_module(lambda x, y: torch.ops.aten.convolution.default( + x, + y, + None, + [5], + [0], + [1], + False, + [0], + 1, + )) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search(r'tensor<\?x1x800xf32>.*->.*tensor<\?x512x159xf32>', + shlo_text) is not None) + + def test_cumsum(self): + args = (torch.rand((10, 5)), 1) + dynamic_shapes = (({0: Dim("dim")}, None),) + m = wrap_func_as_nn_module(torch.ops.aten.cumsum.default) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search(r'tensor<\?x5xf32>.*->.*tensor<\?x5xf32>', shlo_text) + is not None) + + def test_div(self): + args = (torch.rand((10, 12, 197)), torch.rand((10, 12, 197))) + dynamic_shapes = (({0: Dim("dim")}, {0: Dim("dim")}),) + m = wrap_func_as_nn_module(torch.ops.aten.div.Tensor) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search( + r'tensor<\?x12x197xf32>.*tensor<\?x12x197xf32>.*->.*tensor<\?x12x197xf32>', + shlo_text) is not None) + + def test_div_scalar(self): + args = (torch.rand((10, 12, 197)), 8.0) + dynamic_shapes = (({0: Dim("dim")}, None),) + m = wrap_func_as_nn_module(torch.ops.aten.div.Tensor) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search(r'tensor<\?x12x197xf32>.*->.*tensor<\?x12x197xf32>', + shlo_text) is not None) + + def test_gelu(self): + args = (torch.rand((3, 5)),) + dynamic_shapes = (({0: Dim("dim")},),) + m = wrap_func_as_nn_module(torch.ops.aten.gelu) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search(r'tensor<\?x5xf32>.*->.*tensor<\?x5xf32>', shlo_text) + is not None) + + def test_embedding(self): + + class M(torch.nn.Module): + + def forward(self, x, y): + res = torch.ops.aten.embedding.default(x, y) + return res + + args = (torch.rand((20, 768)), torch.randint(0, 15, + (3, 10)).to(torch.int64)) + dynamic_shapes = (None, {0: Dim("dim")}) + m = M() + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search(r"%arg.: tensor<\?x10xi64>.*->.*tensor<\?x10x768xf32>", + shlo_text) is not None) + + def test_mean(self): + + class M(torch.nn.Module): + + def forward(self, x): + return torch.mean(x, -1, keepdim=True) + + args = (torch.rand((10, 197, 768)),) + dynamic_shapes = ({0: Dim("dim")},) + m = M() + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search(r"%arg.: tensor<\?x197x768xf32>.*->.*tensor<\?x197x1xf32>", + shlo_text) is not None) + + def test_mul(self): + args = (torch.rand((10, 2, 768)), torch.rand((10, 2, 768))) + dynamic_shapes = (({0: Dim("dim")}, {0: Dim("dim")}),) + m = wrap_func_as_nn_module(torch.ops.aten.mul.Tensor) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search( + r'tensor<\?x2x768xf32>.*tensor<\?x2x768xf32>.*->.*tensor<\?x2x768xf32>', + shlo_text) is not None) + + def test_mul_scalar(self): + args = (torch.rand((10, 2, 768)), 0.125) + dynamic_shapes = (({0: Dim("dim")}, None),) + m = wrap_func_as_nn_module(torch.ops.aten.mul.Tensor) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search(r'tensor<\?x2x768xf32>.*->.*tensor<\?x2x768xf32>', shlo_text) + is not None) + + def test_ne_scalar(self): + + class M(torch.nn.Module): + + def forward(self, x): + return torch.ops.aten.ne.Scalar(x, 1).to(torch.int32) + + args = (torch.rand((3, 5)).to(torch.int64),) + dynamic_shapes = ({0: Dim("dim")},) + m = M() + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search(r"%arg.: tensor<\?x5xi64>.*->.*tensor<\?x5xi32>", shlo_text) + is not None) + + def test_var(self): + + class M(torch.nn.Module): + + def forward(self, x): + return torch.var(x, -1, keepdim=True, correction=0) + + args = (torch.rand((10, 197, 768)),) + dynamic_shapes = ({0: Dim("dim")},) + m = M() + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search(r"%arg.: tensor<\?x197x768xf32>.*->.*tensor<\?x197x1xf32>", + shlo_text) is not None) + + def test_native_group_norm(self): + + class M2(torch.nn.Module): + + def __init__(self): + super().__init__() + self.layer_norm = torch.nn.GroupNorm( + num_groups=512, num_channels=512, affine=True) + + def forward(self, x): + x = self.layer_norm(x) + return x + + args = (torch.rand((10, 512, 159)),) + dynamic_shapes = ({0: Dim("dim")},) + m = M2() + out1 = m(*args) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search(r"%arg.: tensor<\?x512x159xf32>.*->.*tensor<\?x512x159xf32>", + shlo_text) is not None) + + def test_native_layer_norm(self): + + class M(torch.nn.Module): + + def forward(self, x, weight, bias): + return torch.ops.aten.native_layer_norm.default(x, [768], weight, bias, + 1e-12)[0] + + args = ( + torch.rand((10, 197, 768)), + torch.rand((768)), + torch.rand((768)), + ) + dynamic_shapes = ({0: Dim("dim")}, None, None) + m = M() + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search(r"%arg.: tensor<\?x197x768xf32>.*->.*tensor<\?x197x768xf32>", + shlo_text) is not None) + + def test_permute(self): + args = (torch.rand((10, 197, 12, 64)),) + dynamic_shapes = (({0: Dim("dim")},),) + m = wrap_func_as_nn_module( + lambda x: torch.ops.aten.permute.default(x, [0, 2, 1, 3])) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search( + r"%arg.: tensor<\?x197x12x64xf32>.*->.*tensor<\?x12x197x64xf32>", + shlo_text) is not None) + + def test_select(self): + args = (torch.rand((10, 197, 768)), 1, 0) + dynamic_shapes = (({0: Dim("dim")}, None, None),) + m = wrap_func_as_nn_module(torch.ops.aten.select.int) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search(r"%arg.: tensor<\?x197x768xf32>.*->.*tensor<\?x768xf32>", + shlo_text) is not None) + + def test_slice(self): + args = (torch.rand((10, 3, 224, 224)), 0, 0, 9223372036854775807) + dynamic_shapes = (({0: Dim("dim")}, None, None, None),) + m = wrap_func_as_nn_module(torch.ops.aten.slice.Tensor) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search( + r"%arg.: tensor<\?x3x224x224xf32>.*->.*tensor<\?x3x224x224xf32>", + shlo_text) is not None) + + def test_slice_2(self): + args = (torch.rand((10, 3, 224, 224)), 1, 0, 2) + dynamic_shapes = (({0: Dim("dim")}, None, None, None),) + m = wrap_func_as_nn_module(torch.ops.aten.slice.Tensor) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search( + r"%arg.: tensor<\?x3x224x224xf32>.*->.*tensor<\?x2x224x224xf32>", + shlo_text) is not None) + + def test_softmax(self): + args = (torch.rand((10, 12, 197, 197)), -1, False) + dynamic_shapes = (({0: Dim("dim")}, None, None),) + m = wrap_func_as_nn_module(torch.ops.aten._softmax.default) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search( + r"%arg.: tensor<\?x12x197x197xf32>.*->.*tensor<\?x12x197x197xf32>", + shlo_text) is not None) + + def test_sub(self): + args = (torch.rand((10, 1, 1, 10)), torch.rand((10, 1, 1, 10))) + dynamic_shapes = (({0: Dim("dim")}, {0: Dim("dim")}),) + m = wrap_func_as_nn_module(torch.ops.aten.sub.Tensor) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search( + r'tensor<\?x1x1x10xf32>.*tensor<\?x1x1x10xf32>.*->.*tensor<\?x1x1x10xf32>', + shlo_text) is not None) + + def test_softmax_reduce_on_dynamic_dim(self): + args = (torch.rand((1, 8, 128, 3)), -1, False) + dynamic_shapes = (({3: Dim("dim")}, None, None),) + m = wrap_func_as_nn_module(torch.ops.aten._softmax.default) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search(r"%arg.: tensor<1x8x128x\?xf32>.*->.*tensor<1x8x128x\?xf32>", + shlo_text) is not None) + + @unittest.skip("Converted StableHLO contains i1 dtype, not expected.") + def test_index(self): + args = (torch.rand((2, 10)), torch.arange(5)) + dynamic_shapes = ((None, {0: Dim("dim")}),) + m = wrap_func_as_nn_module( + lambda x, y: torch.ops.aten.index.Tensor(x, [None, y])) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search( + r"%arg.: tensor<\?xi64>.*%arg.: tensor<2x10xf32>.*->.*tensor<2x\?xf32>", + shlo_text) is not None) + + def test_sub_scalar(self): + args = (1.0, torch.rand((10, 1, 1, 10))) + dynamic_shapes = ((None, {0: Dim("dim")}),) + m = wrap_func_as_nn_module(torch.ops.aten.sub.Tensor) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search(r'tensor<\?x1x1x10xf32>.*->.*tensor<\?x1x1x10xf32>', + shlo_text) is not None) + + def test_split_with_sizes(self): + + class M(torch.nn.Module): + + def forward(self, x): + res = torch.ops.aten.split_with_sizes.default(x, [1, 2, 3], -1) + return res[0], res[1], res[2] + + args = (torch.rand((3, 10, 6)),) + dynamic_shapes = ({0: Dim("dim")},) + m = M() + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search( + r"%arg.: tensor<\?x10x6xf32>.*->.*tensor<\?x10x1xf32>.*tensor<\?x10x2xf32>.*tensor<\?x10x3xf32>", + shlo_text) is not None) + + def test_transpose_on_dynamic_dim(self): + args = (torch.rand((1, 8, 3, 256)),) + dynamic_shapes = (({2: Dim("dim")},),) + m = wrap_func_as_nn_module( + lambda x: torch.ops.aten.transpose.int(x, -2, -1)) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search(r"%arg.: tensor<1x8x\?x256xf32>.*->.*tensor<1x8x256x\?xf32>", + shlo_text) is not None) + + def test_unsqueeze_1(self): + args = (torch.rand((3, 10)),) + dynamic_shapes = (({0: Dim("dim")},),) + m = wrap_func_as_nn_module(lambda x: torch.ops.aten.unsqueeze.default(x, 1)) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search(r"%arg.: tensor<\?x10xf32>.*->.*tensor<\?x1x10xf32>", + shlo_text) is not None) + + def test_unsqueeze_2(self): + args = (torch.rand((1, 1, 3, 256)),) + dynamic_shapes = (({2: Dim("dim")},),) + m = wrap_func_as_nn_module(lambda x: torch.ops.aten.unsqueeze.default(x, 2)) + ep = export(m, args=args, dynamic_shapes=dynamic_shapes) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search( + r"%arg.: tensor<1x1x\?x256xf32>.*->.*tensor<1x1x1x\?x256xf32>", + shlo_text) is not None) + + def test_dynamic_view(self): + + class M(torch.nn.Module): + + def __init__(self): + super().__init__() + self.conv = torch.nn.Conv2d(3, 5, [16, 16]) + + def forward(self, x): + x = self.conv(x) + return x.view(x.shape[0], x.shape[1], -1) + + m = M().eval() + args = (torch.rand((10, 3, 224, 224)),) + dynamic_shapes = ({0: Dim("bs")},) + ep = export(m, args, dynamic_shapes=dynamic_shapes) + out1 = ep.module()(*args) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search( + r"%arg.: tensor<\?x3x224x224xf32>.*->.*tensor<\?x5x43681xf32>", + shlo_text) is not None) + + @unittest.skip("Cannot generate aten.sym_numel in the exported program.") + def test_dynamic_view_sym_numel(self): + + class M(torch.nn.Module): + + def forward(self, x, range): + num_elem = torch.numel(range) + return x.view(x.shape[0], x.shape[2], num_elem, x.shape[4]) + + m = M().eval() + args = (torch.rand((1, 1, 8, 3, 256)), torch.arange(3)) + dynamic_shapes = ({3: Dim("bs")}, {0: Dim("bs")}) + ep = export(m, args, dynamic_shapes=dynamic_shapes) + out1 = ep.module()(*args) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search( + r"%arg.: tensor<\?x3x224x224xf32>.*->.*tensor<\?x5x43681xf32>", + shlo_text) is not None) + + def test_dynamic_view_non_bs(self): + + class M(torch.nn.Module): + + def forward(self, x): + return x.view(x.shape[0], x.shape[1] * x.shape[2], x.shape[3]) + + m = M().eval() + args = (torch.rand((1, 3, 2, 16)),) + dynamic_shapes = ({1: Dim("bs")},) + ep = export(m, args, dynamic_shapes=dynamic_shapes) + out1 = ep.module()(*args) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search(r"%arg.: tensor<1x\?x2x16xf32>.*->.*tensor<1x\?x16xf32>", + shlo_text) is not None) + + def test_dynamic_view_multiplier(self): + + class M(torch.nn.Module): + + def forward(self, x): + return x.view(x.shape[0] * x.shape[1], -1) + + m = M().eval() + args = (torch.rand((10, 197, 768)),) + dynamic_shapes = ({0: Dim("bs")},) + ep = export(m, args, dynamic_shapes=dynamic_shapes) + out1 = ep.module()(*args) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search(r"%arg.: tensor<\?x197x768xf32>.*->.*tensor<\?x768xf32>", + shlo_text) is not None) + + def test_dynamic_expand(self): + + class M(torch.nn.Module): + + def forward(self, x, image): + return x.expand(image.shape[0], -1, -1) + + m = M().eval() + args = (torch.rand((1, 1, 768)), torch.rand((10, 3, 224, 224))) + dynamic_shapes = ( + None, + { + 0: Dim("bs") + }, + ) + ep = export(m, args, dynamic_shapes=dynamic_shapes) + out1 = ep.module()(*args) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search(r"%arg.: tensor<1x1x768xf32>.*->.*tensor<\?x1x768xf32>", + shlo_text) is not None) + + def test_dynamic_expand_2(self): + + class M(torch.nn.Module): + + def forward(self, x, range): + return x.expand(1, 1, 8, range.shape[0], 256) + + m = M().eval() + args = (torch.rand((1, 1, 1, 3, 256)), torch.arange(3)) + dynamic_shapes = ({3: Dim("bs")}, {0: Dim("bs")}) + ep = export(m, args, dynamic_shapes=dynamic_shapes) + out1 = ep.module()(*args) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search( + r"%arg.: tensor<1x1x1x\?x256xf32>.*->.*tensor<1x1x8x\?x256xf32>", + shlo_text) is not None) + + +if __name__ == "__main__": + test = unittest.main() + sys.exit(0 if test.result.wasSuccessful() else 1) diff --git a/experimental/torch_xla2/test_requirements.txt b/experimental/torch_xla2/test_requirements.txt deleted file mode 100644 index c8596327236..00000000000 --- a/experimental/torch_xla2/test_requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -pytest -immutabledict -sentencepiece -pytest-xdist -expecttest \ No newline at end of file diff --git a/experimental/torch_xla2/torch_xla2/__init__.py b/experimental/torch_xla2/torch_xla2/__init__.py index b0bb20712d4..bd0e00fa6ca 100644 --- a/experimental/torch_xla2/torch_xla2/__init__.py +++ b/experimental/torch_xla2/torch_xla2/__init__.py @@ -1,31 +1,34 @@ -import contextlib import jax import torch from torch._functorch import make_functional from torch.utils import _pytree as pytree -from torch_xla2 import export, _ops, ops_registry, tensor, tf_integration, functions +from torch_xla2 import export, tensor, tf_integration jax.config.update('jax_enable_x64', True) +env = None +def default_env(): + global env + if env is None: + env = tensor.Environment(0) + return env -@contextlib.contextmanager -def mode(): - with tensor.XLADispatchMode(), functions.XLAFunctionMode(): - yield -def extract_jax(mod: torch.nn.Module): +def extract_jax(mod: torch.nn.Module, env=None): """Returns a pytree of jax.ndarray and a jax callable.""" + if env is None: + env = default_env() func, weights, buffer = make_functional.make_functional_with_buffers(mod) - states = (weights, buffer) + states = mod.state_dict() + states = pytree.tree_map_only(torch.Tensor, tensor.t2j, states) #@jax.jit def jax_func(states, inputs): - (states, inputs) = tensor.wrap((states, inputs)) - weights, buffer = states - with tensor.XLADispatchMode(): - res = func(weights, buffer, *inputs) - return tensor.unwrap(res) + (states, inputs) = env.j2t_iso((states, inputs)) + with env: + res = torch.func.functional_call(mod, states, inputs) + return env.t2j_iso(res) return states, jax_func diff --git a/experimental/torch_xla2/torch_xla2/_ops.py b/experimental/torch_xla2/torch_xla2/_ops.py deleted file mode 100644 index fe0f97a0f01..00000000000 --- a/experimental/torch_xla2/torch_xla2/_ops.py +++ /dev/null @@ -1,1745 +0,0 @@ -# pylint: disable -"""Torch ops implemented using jax.""" -import sys - -import jax -from jax import numpy as jnp -import numpy as np -import torch -from torch_xla2 import ops_registry -from torch_xla2 import tensor - - -class TorchFunctionLowering: - - def __init__(self, func, is_jax_func, should_jit=False): - if is_jax_func and should_jit: - func = jax.jit(func) - self.func = func - self.is_jax_func = is_jax_func - - def __call__(self, *args, **kwargs): - if self.is_jax_func: - (args, kwargs) = tensor.unwrap((args, kwargs)) - res = self.func(*args, **kwargs) - if self.is_jax_func: - res = tensor.wrap(res) - return res - - -def op(aten_op, is_jax_func=True): - """if is_jax_func is true, then the function it will register - - should takes jax array as input and returns jax array. - - Which means we need to wrap it - """ - - def inner(func): - ops_registry.lowerings.register(aten_op, - TorchFunctionLowering(func, is_jax_func)) - return func - - return inner - - -@op(torch.ops.aten.view_copy) -@op(torch.ops.aten.view) -@op(torch.ops.aten._unsafe_view) -@op(torch.ops.aten.reshape) -def _aten_unsafe_view(x, shape): - return jnp.reshape(x, shape) - - -@op(torch.ops.aten.add) -def _aten_add(x, y, *, alpha=1): - """if isinstance(x, jnp.ndarray) and isinstance(y, jnp.ndarray): - - assert x.dtype == y.dtype, (x.dtype, y.dtype) - """ - return x + y * alpha - - -@op(torch.ops.aten.copy_, is_jax_func=False) -def _aten_copy(x, y, memory_format=None): - if isinstance(x, tensor.XLATensor2): - x._elem = y._elem - elif isinstance(x, tensor.SliceView): - x.mutate(y) - return x - - -@op(torch.ops.aten.clone) -def _aten_clone(x, memory_format=None): - return jnp.copy(x) - - -@op(torch.ops.aten.full) -def _aten_full(size, value, **kwargs): - return jnp.full(size, value) - - -@op(torch.ops.aten.index_copy) -def _aten_index_copy(x, dim, indexes, source): - # return jax.lax.scatter(x, index, dim) - dims = [] - for i in range(len(x.shape)): - if i == dim: - dims.append(indexes) - else: - dims.append(slice(None, None, None)) - return x.at[dim].set(source) - - -@op(torch.ops.aten.select) -@op(torch.ops.aten.index_select) -@op(torch.ops.aten.select_copy) -def _aten_index_select(x, dim, indexes): - dims = [] - for i in range(len(x.shape)): - if i == dim: - dims.append(indexes) - else: - dims.append(slice(None, None, None)) - return x[tuple(dims)] - - -@op(torch.ops.aten.mean) -def _aten_mean(x, dim=None, keepdim=False): - return jnp.mean(x, dim, keepdims=keepdim) - - -def _torch_binary_scalar_type(scalar, tensor): - if "float" in str(tensor.dtype): - return tensor.dtype - - if isinstance(scalar, int): - if "int" in str(tensor.dtype): - return tensor.dtype - - return jnp.float32 - - -@op(torch.ops.aten.sub) -def _aten_sub(x, y): - if isinstance(x, float): - dtype = _torch_binary_scalar_type(x, y) - x = jnp.array(x, dtype=dtype) - if isinstance(y, float): - dtype = _torch_binary_scalar_type(y, x) - y = jnp.array(y, dtype=dtype) - return x - y - - -@op(torch.ops.aten.mm) -def _aten_mm(x, y): - res = x @ y - return res - - -@op(torch.ops.aten.mul) -def _aten_mul(x, y): - return x * y - - -@op(torch.ops.aten.silu) -def _aten_silu(x): - return jax.nn.silu(x) - - -@op(torch.ops.aten.t) -def _aten_t(x): - return jnp.transpose(x) - - -@op(torch.ops.aten.transpose) -@op(torch.ops.aten.transpose_copy) -def _aten_transpose(x, dim0, dim1): - shape = list(range(len(x.shape))) - shape[dim0], shape[dim1] = shape[dim1], shape[dim0] - return jnp.transpose(x, shape) - - -@op(torch.ops.aten.triu) -def _aten_triu(m, k): - return jnp.triu(m, k) - - -@op(torch.ops.aten.slice) -@op(torch.ops.aten.slice_copy) -def _aten_slice(self, dim=0, start=None, end=None, step=1): - if end == sys.maxsize: - end = self.shape[dim] - sl = slice(start, end, step) - dims = [] - for i in range(len(self.shape)): - if i == dim: - dims.append(sl) - else: - dims.append(slice(None, None, None)) - return self[tuple(dims)] - - -@op(torch.ops.aten.detach) -def _aten_detach(self): - return self - - -@op(torch.ops.aten.view_as_real) -def _aten_view_as_real(x): - real = jnp.real(x) - im = jnp.imag(x) - res = jnp.stack([real, im], -1) - return res - - -@op(torch.ops.aten.stack) -def _aten_stack(tensors, dim=0): - return jnp.stack(tensors, dim) - - -@op(torch.ops.aten._softmax) -def _aten_softmax(x, dim, halftofloat): - return jax.nn.softmax(x, dim) - - -@op(torch.ops.aten.pow) -def _aten_pow(x, y): - if isinstance(y, int): - y = float(y) - return jnp.power(x, y) - - -@op(torch.ops.aten.view_as_complex) -def _aten_view_as_complex(input): - if input.dtype == jnp.bfloat16: - input = input.astype(jnp.float32) - x, y = input[..., 0], input[..., 1] - return jax.lax.complex(x, y) - - -@op(torch.ops.aten.div) -def _aten_div(x, y, rounding_mode=""): - res = x / y - if rounding_mode == "trunc": - res = jnp.trunc(res) - return res - - -@op(torch.ops.aten.div_, is_jax_func=False) -def _aten_div_(x, y, rounding_mode=""): - x._elem = _aten_div(x._elem, y._elem, rounding_mode) - return x - - -@op(torch.ops.aten.true_divide) -def _aten_true_divide(x, y): - return x / y - - -@op(torch.ops.aten.bmm) -def _aten_bmm(x, y): - res = x @ y - return res - # return jnp.einsum('bnm,bmk->bnk', x, y) - - -@op(torch.ops.aten.embedding) -# embedding(Tensor weight, Tensor indices, SymInt padding_idx=-1, bool scale_grad_by_freq=False, bool sparse=False) -def _aten_embedding(a, w, padding_idx=-1): - return jnp.take(a, w, axis=0) - - -@op(torch.ops.aten.rsqrt) -def _aten_rsqrt(x): - if isinstance(x, int): - x = float(x) - if x.dtype == jnp.int32: - x = x.astype(jnp.float32) - return jax.lax.rsqrt(x) - - -@op(torch.ops.aten.expand) -@op(torch.ops.aten.expand_copy) -def _aten_expand(x, dims): - - def fix_dims(d, xs): - if d == -1: - return xs - return d - - dims = [fix_dims(p, s) for p, s in zip(dims, x.shape)] - return jnp.broadcast_to(x, dims) - - -@op(torch.ops.aten.dot) -def _aten_dot(x, y): - return jnp.dot(x, y) - - -@op(torch.ops.aten._to_copy) -def _aten__to_copy(self, **kwargs): - dtype = tensor.t2j_dtype(kwargs["dtype"]) - if dtype != self.dtype: - return self.astype(dtype) - return jnp.copy(self) - - -@op(torch.ops.aten.empty) -def _aten_empty(sizes, **kwargs): - return jnp.zeros(sizes) - - -@op(torch.ops.aten.index_put_) -@op(torch.ops.aten.index_put) -def _aten_index_put(self, indexes, values, accumulate=False): - indexes = [slice(None, None, None) if i is None else i for i in indexes] - indexes = tuple(indexes) - if accumulate: - return self.at[indexes].add(values) - else: - return self.at[indexes].set(values) - - -@op(torch.ops.aten.index) -@op(torch.ops.aten._unsafe_index) -@op(torch.ops.aten.index.Tensor) -def _aten_index(self, indexes): - indexes = [slice(None, None, None) if i is None else i for i in indexes] - indexes = tuple(indexes) - return self[indexes] - - -@op(torch.ops.aten.split) -@op(torch.ops.aten.split_copy) -@op(torch.ops.aten.split_with_sizes) -def split_with_sizes(x, sizes, dim=0): - """Splits an array `x` into sub-arrays based on static sizes `sizes`. - - Args: - x: The input array to split. - sizes: A 1D array of integer sizes for each sub-array. - - Returns: - A list of sub-arrays. - """ - if isinstance(sizes, int): - # split equal size - new_sizes = [sizes] * (x.shape[dim] // sizes) - sizes = new_sizes - rank = x.ndim - splits = np.cumsum(sizes) # Cumulative sum for split points - - def make_range(rank, dim, start, end): - res = [slice(None, None, None)] * rank - res[dim] = slice(start, end) - return tuple(res) - - return [ - x[make_range(rank, dim, start, end)] - for start, end in zip([0] + list(splits[:-1]), splits) - ] - - -@op(torch.ops.aten.permute) -@op(torch.ops.aten.permute_copy) -def permute(t, dims): - return jnp.transpose(t, dims) - - -@op(torch.ops.aten.unsqueeze) -@op(torch.ops.aten.unsqueeze_copy) -@op(torch.ops.aten.unsqueeze.default) -def _aten_unsqueeze(self, dim): - if dim < 0: - dim += self.ndim + 1 - return jnp.expand_dims(self, dim) - - -@op(torch.ops.aten.ne) -def _aten_ne(x, y): - return jnp.not_equal(x, y) - - -@op(torch.ops.aten.cumsum) -def _aten_cumsum(x, y, dtype=None): - dtype = tensor.t2j_dtype(dtype) - res = jnp.cumsum(x, y, dtype) - return res - - -@op(torch.ops.aten.native_layer_norm) -def _aten_native_layer_norm(input, - normalized_shape, - weight=None, - bias=None, - eps=1e-5): - """Implements layer normalization in Jax as defined by `aten::native_layer_norm`. - - Args: - input: The input tensor. - normalized_shape: A list of integer dimensions to be normalized over. - weight: Optional weight tensor for the affine transformation. - bias: Optional bias tensor for the affine transformation. - eps: A small epsilon value for numerical stability. - - Returns: - output: The normalized tensor. - mean: The calculated mean tensor. - std: The calculated standard deviation tensor. - """ - if isinstance(normalized_shape, int): - normalized_shape = [normalized_shape] - axis = [i for i, d in enumerate(input.shape) if d in normalized_shape] - - # Calculate mean and standard deviation - mean = jnp.mean(input, axis=axis, keepdims=True) - var = jnp.var(input, axis=axis, keepdims=True) - rstd = jax.lax.rsqrt(var + eps) - - # Normalize the input - norm_x = (input - mean) * rstd - - # Apply affine transformation (if provided) - if weight is not None: - norm_x *= weight - if bias is not None: - norm_x += bias - return norm_x, mean, rstd - - -# - func: addmm(Tensor self, Tensor mat1, Tensor mat2, *, Scalar beta=1, Scalar alpha=1) -> Tensor -@op(torch.ops.aten.addmm) -def _aten_addmm(self, mat1, mat2, *, beta=1.0, alpha=1.0): - self *= beta - self += alpha * jnp.matmul(mat1, mat2) - return self - - -@op(torch.ops.aten.gelu) -def _aten_gelu(self, *, approximate="none"): - approx = approximate == "tanh" - return jax.nn.gelu(self, approx) - - -@op(torch.ops.aten.squeeze) -@op(torch.ops.aten.squeeze_copy) -def _aten_squeeze_dim(self, dim): - """Squeezes a Jax tensor by removing a single dimension of size 1. - - Args: - self: The input tensor. - dim: The dimension to squeeze. - - Returns: - The squeezed tensor with the specified dimension removed if it is 1, - otherwise the original tensor is returned. - """ - - # Validate input arguments - if not isinstance(self, jnp.ndarray): - raise TypeError(f"Expected a Jax tensor, got {type(self)}.") - if isinstance(dim, int): - dim = [dim] - - # Check if the specified dimension has size 1 - if all([self.shape[d] != 1 for d in dim]): - return self - - # Use slicing to remove the dimension if it is 1 - new_shape = list(self.shape) - - def fix_dim(p): - if p < 0: - return p + len(self.shape) - return p - - dim = [fix_dim(d) for d in dim] - new_shape = [p for i, p in enumerate(self.shape) if i not in dim or p != 1] - return self.reshape(new_shape) - - -@op(torch.ops.aten.convolution) -def _aten_convolution( - input, - weight, - bias, - stride, - padding, - dilation, - transposed, - output_padding, - groups, -): - if transposed: - raise NotImplementedError("Transposed convolution is not implemented.") - - def make_padding(padding): - return ((p, p) for p in padding) - - def create_default_conv_dimension_numbers(num_spatial_dims): - # Ref: https://github.com/openxla/xla/blob/main/xla/client/xla_builder.cc#L4211 - # (batch dimension, feature dimension, spatial dimensions...) - lhs_spec = [0, 1] - # (out feature dimension, in feature dimension, spatial dimensions...) - rhs_spec = [0, 1] - # (batch dimension, feature dimension, spatial dimensions...) - out_spec = [0, 1] - for i in range(0, num_spatial_dims): - lhs_spec.append(i + 2) - rhs_spec.append(i + 2) - out_spec.append(i + 2) - return jax.lax.ConvDimensionNumbers( - *map(tuple, (lhs_spec, rhs_spec, out_spec))) - - res = jax.lax.conv_general_dilated( - input, - weight, - stride, - make_padding(padding), - lhs_dilation=(1,) * len(stride), - rhs_dilation=dilation, - dimension_numbers=create_default_conv_dimension_numbers(len(stride)), - feature_group_count=groups, - batch_group_count=1, - ) - - if bias is not None: - # TODO(qihqi): bias always on channel? - if len(bias.shape) == 1: - shape = [1] * len(res.shape) - shape[1] = bias.shape[0] - bias = bias.reshape(tuple(shape)) - res = res + bias - return res - - -# _native_batch_norm_legit(Tensor input, Tensor? weight, Tensor? bias, Tensor(a!) running_mean, Tensor(b!) running_var, bool training, float momentum, float eps) -@op(torch.ops.aten._native_batch_norm_legit) -def _aten__native_batch_norm_legit(input, weight, bias, running_mean, - running_var, training, momentum, eps): - return _aten__native_batch_norm_legit_no_training(input, weight, bias, - running_mean, running_var, - momentum, eps) - - -@op(torch.ops.aten._native_batch_norm_legit_no_training) -def _aten__native_batch_norm_legit_no_training(input, weight, bias, - running_mean, running_var, - momentum, eps): - if weight is None: - weight = jnp.ones_like(running_mean) - if bias is None: - bias = jnp.zeros_like(running_mean) - - def broadcast(t): - return jax.lax.broadcast_in_dim(t, input.shape, broadcast_dimensions=(1,)) - - a = input - broadcast(running_mean) - b = broadcast(jnp.sqrt(running_var + eps)) - return ( - a / b * broadcast(weight) + broadcast(bias), - jnp.array([]), - jnp.array([]), - ) - - -@op(torch.ops.aten.relu) -def _aten_relu(self): - return jax.nn.relu(self) - - -@op(torch.ops.aten.cat) -def _aten_cat(tensors, dims=0): - return jnp.concatenate(tensors, dims) - - -@op(torch.ops.aten.max_pool2d_with_indices) -@op(torch.ops.aten.max_pool3d_with_indices) -def _aten_max_pool2d_with_indices(inputs, - kernel_size, - strides, - padding=0, - dilation=1, - ceil_mode=False): - num_batch_dims = len(inputs.shape) - len(kernel_size) - 1 - kernel_size = tuple(kernel_size) - strides = tuple(strides) - if isinstance(padding, int): - padding = tuple((padding, padding) for _ in range(len(kernel_size))) - elif isinstance(padding, list): - padding = tuple((p, p) for p in padding) - - window_shape = kernel_size - num_batch_dims = inputs.ndim - (len(window_shape) + 1) - strides = strides or (1,) * len(window_shape) - assert len(window_shape) == len( - strides), f'len({window_shape}) must equal len({strides})' - strides = (1,) * (1 + num_batch_dims) + strides - dims = (1,) * (1 + num_batch_dims) + window_shape - - is_single_input = False - if num_batch_dims == 0: - # add singleton batch dimension because lax.reduce_window always - # needs a batch dimension. - inputs = inputs[None] - strides = (1,) + strides - dims = (1,) + dims - is_single_input = True - - assert inputs.ndim == len(dims), f'len({inputs.shape}) != len({dims})' - if not isinstance(padding, str): - padding = tuple(map(tuple, padding)) - assert len(padding) == len(window_shape), ( - f'padding {padding} must specify pads for same number of dims as ' - f'window_shape {window_shape}') - assert all([len(x) == 2 for x in padding - ]), f'each entry in padding {padding} must be length 2' - padding = ((0, 0), (0, 0)) + padding - - indices = jnp.arange(np.prod(inputs.shape)).reshape(inputs.shape) - - def reduce_fn(a, b): - ai, av = a - bi, bv = b - which = av > bv - return jnp.where(which, ai, bi), jnp.where(which, av, bv) - - init_val = -jnp.inf - if inputs.dtype in (jnp.int32, jnp.int64): - init_val = -(1 << 31) - init_val = jnp.array(init_val).astype(inputs.dtype) - - indices, y = jax.lax.reduce_window((indices, inputs), (0, init_val), - reduce_fn, dims, strides, padding) - if is_single_input: - indices = jnp.squeeze(indices, axis=0) - y = jnp.squeeze(y, axis=0) - return y, indices - - batch_result = pool(inputs, -jnp.inf, jax.lax.max, kernel_size, strides, - padding) - indices = pool(inputs, 0, jnp.argmax, kernel_size, strides, padding) - return batch_result, indices - - -# TODO add more ops - - -@op(torch.ops.aten.min) -def _aten_min(x, axis=None): - return jnp.min(x, axis=axis), jnp.argmin(x, axis=axis).astype(jnp.int64) - - -@op(torch.ops.aten.amin) -def _aten_amin(x, axis=None): - return jnp.min(x, axis=axis) - - -@op(torch.ops.aten.argmin) -def _aten_amin(x, axis=None): - return jnp.argmin(x, axis=axis) - - -@op(torch.ops.aten.sin) -def _aten_sin(x): - return jnp.sin(x) - - -@op(torch.ops.aten.sym_size) -def _aten_sym_size(x, dim): - return x.shape[dim] - - -@op(torch.ops.aten.var) -@op(torch.ops.prims.var) -def _aten_var(x, dim=None, *, correction=1, keepdim=False, out=None): - return jnp.var(x, axis=dim, ddof=correction, keepdims=keepdim) - - -@op(torch.ops.prims.broadcast_in_dim) -def _prims_broadcast_in_dim(t, shape, broadcast_dimensions): - return jax.lax.broadcast_in_dim( - t, shape, broadcast_dimensions=broadcast_dimensions) - - -# aten.native_group_norm -- should use decomp table -# func: native_group_norm(Tensor input, Tensor? weight, Tensor? bias, SymInt N, SymInt C, SymInt HxW, int group, float eps) -> (Tensor, Tensor, Tensor) - - -@op(torch.ops.aten.native_group_norm) -def _aten_native_group_norm(input, weight, bias, N, C, HxW, group, eps=1e-5): - """Group Normalization implementation in JAX. - - Args: - input: Input tensor. Expected shape (batch_size, channels, ... spatial dims - ...) - weight: Optional scaling (gamma) parameter. Shape (channels,) - bias: Optional shifting (beta) parameter. Shape (channels,) - N: Batch size. - C: Number of channels. - HxW: Product of spatial dimensions (number of elements per channel after - flattening). - group: Number of groups for Group Normalization. - eps: Small value added for numerical stability. - - Returns: - A tuple of (normalized_output, mean, rstd) - """ - - input_shape = input.shape - - # Reshape for group-wise normalization - reshaped_input = jnp.reshape(input, (1, N * group, -1)) - - # **Core Group Normalization** - def group_norm_body(x): # Function to apply within each group - mean = jnp.mean(x, axis=-1, keepdims=True) - var = jnp.var(x, axis=-1, keepdims=True) - rstd = jax.lax.rsqrt(var + eps) # Reciprocal of std with epsilon - normalized = (x - mean) * rstd - return normalized, mean, rstd - - normalized, group_mean, group_rstd = jax.lax.map(group_norm_body, - reshaped_input) - - # Reshape back to original input shape - output = jnp.reshape(normalized, input_shape) - - # **Affine transformation** - affine_shape = [-1 if i == 1 else 1 for i in range(input.ndim) - ] # Shape for broadcasting - if weight is not None and bias is not None: - output = bias.reshape(affine_shape) + output * weight.reshape(affine_shape) - elif weight is not None: - output = output * weight.reshape(affine_shape) - elif bias is not None: - output = output + bias.reshape(affine_shape) - - # Reshape mean and rstd - mean = jnp.reshape(group_mean, (N, group)) - rstd = jnp.reshape(group_rstd, (N, group)) - - return output, mean, rstd - - -@op(torch.ops.aten.linalg_vector_norm) -def _aten_linalg_vector_norm(self, ord=2, dim=None, keepdim=False, dtype=None): - """Calculates the vector norm along specified dimensions. - - Args: - self: The input tensor. - ord: The order of the norm. Can be a float or 'inf', '-inf', 'fro'. - Default is 2 (Euclidean norm). - dim: Dimensions along which to calculate the norm. If None, the norm is - calculated over all dimensions. - keepdim: Whether to keep the reduced dimensions. - dtype: Optional data type for the output. - - Returns: - The tensor containing the calculated vector norms. - """ - - if ord not in {2, float("inf"), float("-inf"), "fro"}: - raise ValueError( - f"Unsupported ord value: {ord}. Supported values are 2, inf, -inf, and" - " 'fro'.") - - # Special cases (for efficiency and clarity) - if ord == 2: # Euclidean norm - result = jnp.sqrt(jnp.sum(jnp.abs(self)**2, axis=dim, keepdims=keepdim)) - - elif ord == float("inf"): - result = jnp.max(jnp.abs(self), axis=dim, keepdims=keepdim) - - elif ord == float("-inf"): - result = jnp.min(jnp.abs(self), axis=dim, keepdims=keepdim) - - elif ord == "fro": # Frobenius norm - result = jnp.sqrt(jnp.sum(jnp.abs(self)**2, axis=dim, keepdims=keepdim)) - - else: # General case (e.g., ord = 1, ord = 3) - result = jnp.sum( - jnp.abs(self)**ord, axis=dim, keepdims=keepdim)**(1.0 / ord) - - # (Optional) dtype conversion - if dtype is not None: - result = result.astype(dtype) - - return result - - -# aten.reflection_pad1d -@op(torch.ops.aten.reflection_pad1d) -def _aten_reflection_pad1d(input, padding): - rank = len(input.shape) - pad_size = [(0, 0)] * rank - pad_size[-1] = padding - return jnp.pad(input, pad_size, mode="reflect") - - -# aten.alias -@op(torch.ops.aten.alias) -def _aten_alias(self, *args): - return self - - -# aten.sinh -@op(torch.ops.aten.sinh) -def _aten_sinh(self): - return jnp.sinh(self) - - -# aten.native_layer_norm_backward -@op(torch.ops.aten.native_layer_norm_backward) -def _aten_native_layer_norm_backward(grad_out, - input, - normalized_shape, - weight, - bias, - eps=1e-5): - """Implements the backward pass of layer normalization in Jax as defined by `aten::native_layer_norm_backward`. - - Args: - grad_out: The gradient of the output tensor. - input: The input tensor. - normalized_shape: A list of integer dimensions to be normalized over. - weight: Optional weight tensor for the affine transformation. - bias: Optional bias tensor for the affine transformation. - eps: A small epsilon value for numerical stability. - - Returns: - A tuple of (grad_input, grad_weight, grad_bias). - """ - return jax.lax.native_layer_norm_backward(grad_out, input, normalized_shape, - weight, bias, eps) - - -# aten.reflection_pad3d_backward -# aten.reflection_pad2d - - -# aten.atanh -@op(torch.ops.aten.atanh) -def _aten_atanh(self): - return jnp.arctanh(self) - - -# aten.bitwise_not -@op(torch.ops.aten.bitwise_not) -def _aten_bitwise_not(self): - return ~self - - -# aten.embedding_dense_backward - - -# aten.sum -@op(torch.ops.aten.sum) -def _aten_sum(self, dim=None, keepdim=False, dtype=None): - return jnp.sum(self, axis=dim, keepdims=keepdim, dtype=dtype) - - -# aten.sqrt -@op(torch.ops.aten.sqrt) -def _aten_sqrt(self): - return jnp.sqrt(self) - - -@op(torch.ops.aten.tan) -def _aten_tanh(self): - return jnp.tan(self) - - -# aten.tanh -@op(torch.ops.aten.tanh) -def _aten_tanh(self): - return jnp.tanh(self) - - -# aten.ceil -@op(torch.ops.aten.ceil) -def _aten_ceil(self): - return jnp.ceil(self) - - -# aten.asin -@op(torch.ops.aten.asin) -def _aten_asin(self): - return jnp.arcsin(self) - - -# aten.minimum -@op(torch.ops.aten.minimum) -def _aten_minimum(self, other): - return jnp.minimum(self, other) - - -# aten.max_pool2d_backward - - -def _scatter_index(dim, index): - """Returns a tuple of indexes; - - The first is to select in input (to modify), - the second is to select from the values. - """ - index_shape = list(index.shape) - input_indexes = [] - source_indexes = [] - for i in range(len(index_shape)): - source_indexes.append(slice(0, index_shape[i])) - if i == dim: - input_indexes.append(index) - else: - target_shape = [1] * len(index_shape) - target_shape[i] = index_shape[i] - input_indexes.append( - jnp.broadcast_to( - jnp.arange(index_shape[i]).reshape(target_shape), index_shape)) - return tuple(input_indexes), tuple(source_indexes) - - -# aten.scatter_add -@op(torch.ops.aten.scatter_add) -def _aten_scatter_add(input, dim, index, src): - """JAX implementation of scatter, mimicking torch.scatter behavior""" - - input_indexes, source_indexes = _scatter_index(dim, index) - return input.at[input_indexes].add(src[source_indexes]) - - -# aten.logical_not - - -# aten.sign -@op(torch.ops.aten.sign) -def _aten_sign(x): - return jnp.sign(x) - - -# aten.sigmoid -@op(torch.ops.aten.sigmoid) -def _aten_sigmoid(x): - if x.dtype in (jnp.int32, jnp.int64): - x = x.astype(jnp.float32) - return jax.nn.sigmoid(x) - - -# implement aten.asinh in jax -@op(torch.ops.aten.asinh) -def _aten_asinh(self): - return jnp.arcsinh(self) - - -# aten.atan -@op(torch.ops.aten.atan) -def _aten_atan(self): - return jnp.arctan(self) - - -# aten.scatter_reduce -@op(torch.ops.aten.scatter_reduce) -def _aten_scatter_reduce(input, dim, index, src, reduce, *, include_self=True): - input_indexes, source_indexes = _scatter_index(dim, index) - if reduce == "sum": - return input.at[input_indexes].add(src[source_indexes]) - elif reduce == "prod": - return input.at[input_indexes].multiply(src[source_indexes]) - elif reduce == "mean": - return input.at[input_indexes].add(src[source_indexes]) - elif reduce == "amax": - return input.at[input_indexes].max(src[source_indexes]) - elif reduce == "amin": - return input.at[input_indexes].min(src[source_indexes]) - else: - raise RuntimeError('Unknow reduction type: ', reduce) - - -# aten.acos -@op(torch.ops.aten.acos) -def _aten_acos(self): - return jnp.arccos(self) - - -# aten.sym_storage_offset -# aten.native_layer_norm_backward -# aten.max_pool3d_with_indices - - -# aten.gt -@op(torch.ops.aten.gt) -def _aten_gt(self, other): - return self > other - - -# aten.pixel_shuffle -@op(torch.ops.aten.pixel_shuffle) -def _aten_pixel_shuffle(x, upscale_factor): - """PixelShuffle implementation in JAX. - - Args: - x: Input tensor. Typically a feature map. - upscale_factor: Integer by which to upscale the spatial dimensions. - - Returns: - Tensor after PixelShuffle operation. - """ - - batch_size, channels, height, width = x.shape - - if channels % (upscale_factor**2) != 0: - raise ValueError( - 'Number of channels must be divisible by the square of the upscale factor.' - ) - - new_channels = channels // (upscale_factor**2) - new_height = height * upscale_factor - new_width = width * upscale_factor - - x = x.reshape(batch_size, new_channels, upscale_factor, upscale_factor, - height, width) - x = jnp.transpose(x, - (0, 1, 2, 4, 3, 5)) # Move channels to spatial dimensions - x = x.reshape(batch_size, new_channels, new_height, new_width) - - return x - - -# aten.sym_stride -# aten.lt -@op(torch.ops.aten.lt) -def _aten_lt(self, other): - return self < other - - -def pool(inputs, init, reduce_fn, window_shape, strides, padding): - """Helper function to define pooling functions. - - Pooling functions are implemented using the ReduceWindow XLA op. - NOTE: Be aware that pooling is not generally differentiable. - That means providing a reduce_fn that is differentiable does not imply that - pool is differentiable. - - Args: - inputs: input data with dimensions (batch, window dims..., features). - init: the initial value for the reduction - reduce_fn: a reduce function of the form ``(T, T) -> T``. - window_shape: a shape tuple defining the window to reduce over. - strides: a sequence of ``n`` integers, representing the inter-window - strides (default: ``(1, ..., 1)``). - padding: either the string ``'SAME'``, the string ``'VALID'``, or a sequence - of ``n`` ``(low, high)`` integer pairs that give the padding to apply before - and after each spatial dimension. - Returns: - The output of the reduction for each window slice. - """ - num_batch_dims = inputs.ndim - (len(window_shape) + 1) - strides = strides or (1,) * len(window_shape) - assert len(window_shape) == len( - strides), f'len({window_shape}) must equal len({strides})' - strides = (1,) * (1 + num_batch_dims) + strides - dims = (1,) * (1 + num_batch_dims) + window_shape - - is_single_input = False - if num_batch_dims == 0: - # add singleton batch dimension because lax.reduce_window always - # needs a batch dimension. - inputs = inputs[None] - strides = (1,) + strides - dims = (1,) + dims - is_single_input = True - - assert inputs.ndim == len(dims), f'len({inputs.shape}) != len({dims})' - if not isinstance(padding, str): - padding = tuple(map(tuple, padding)) - assert len(padding) == len(window_shape), ( - f'padding {padding} must specify pads for same number of dims as ' - f'window_shape {window_shape}') - assert all([len(x) == 2 for x in padding - ]), f'each entry in padding {padding} must be length 2' - padding = ((0, 0), (0, 0)) + padding - y = jax.lax.reduce_window(inputs, init, reduce_fn, dims, strides, padding) - if is_single_input: - y = jnp.squeeze(y, axis=0) - return y - - -@op(torch.ops.aten._adaptive_avg_pool3d) -def _aten_adaptive_avg_pool3d(x, output_shape): - return _aten_adaptive_avg_pool(x, output_shape, 3) - - -@op(torch.ops.aten._adaptive_avg_pool2d) -def _aten_adaptive_avg_pool3d(x, output_shape): - return _aten_adaptive_avg_pool(x, output_shape, 2) - - -def _aten_adaptive_avg_pool(x, output_shape, pool_dim): - - def adaptive_kernel_size(input_shape, output_shape): - sizes = [1, 1] - spatial_dim_off = len(input_shape) - pool_dim - for spatial_dim in range(pool_dim): - sizes.append(input_shape[spatial_dim_off + spatial_dim] // - output_shape[spatial_dim]) - return tuple(sizes) - - kernel_sizes = adaptive_kernel_size(x.shape, output_shape) - y = pool(x, 0.0, jax.lax.add, kernel_sizes, kernel_sizes, padding='VALID') - - div_shape = list(x.shape) - num_batch_dims = len(x.shape) - pool_dim - 1 - div_shape[num_batch_dims] = 1 - div_shape = tuple(div_shape) - if len(div_shape) - 2 == len(kernel_sizes): - div_shape = (1,) + div_shape[1:] - y = y / pool( - jnp.ones(div_shape), 0.0, jax.lax.add, kernel_sizes, kernel_sizes, - 'VALID') - return y - - -# aten.avg_pool2d -@op(torch.ops.aten.avg_pool2d) -@op(torch.ops.aten.avg_pool3d) -def _aten_avg_pool(inputs, - kernel_size, - strides=None, - padding=0, - ceil_mode=False, - count_include_pad=True, - divisor_override=None): - - num_batch_dims = len(inputs.shape) - len(kernel_size) - 1 - kernel_size = tuple(kernel_size) - strides = tuple(strides) - if isinstance(padding, int): - padding = tuple((padding, padding) for _ in range(len(kernel_size))) - elif isinstance(padding, list): - padding = tuple((p, p) for p in padding) - - y = pool(inputs, 0.0, jax.lax.add, kernel_size, strides, padding) - if count_include_pad: - y = y / np.prod(kernel_size) - else: - div_shape = list(inputs.shape) - div_shape[num_batch_dims] = 1 - div_shape = tuple(div_shape) - if len(div_shape) - 2 == len(kernel_size): - div_shape = (1,) + div_shape[1:] - y = y / pool( - jnp.ones(div_shape), 0.0, jax.lax.add, kernel_size, strides, padding) - return y - - -# aten.sym_numel -# aten.reciprocal -@op(torch.ops.aten.reciprocal) -def _aten_reciprocal(a): - return 1 / a - - -# aten.scatter -@op(torch.ops.aten.select_scatter) -def _aten_select_scatter(input, src, dim, index): - input_indexes = [] - for x in range(len(input.shape)): - if x == dim: - input_indexes.append(index) - else: - input_indexes.append(slice(None, None, None)) - return input.at[tuple(input_indexes)].set(src) - - -@op(torch.ops.aten.scatter.src) -def _aten_scatter_src(input, dim, index, src, reduce=None): - input_index, source_indexes = _scatter_index(dim, index) - return input.at[input_index].set(src[source_indexes]) - - -@op(torch.ops.aten.scatter.value) -def _aten_scatter(input, dim, index, src, reduce=None): - input_index, source_indexes = _scatter_index(dim, index) - return input.at[input_index].set(src) - - -# aten.acosh -@op(torch.ops.aten.acosh) -def _aten_acosh(self): - return jnp.arccosh(self) - - -# aten.avg_pool2d_backward -# aten.col2im -# aten.avg_pool3d -# aten.round -@op(torch.ops.aten.round) -def _aten_round(input, decimals=0): - return jnp.round(input, decimals) - - -# aten.max -@op(torch.ops.aten.max) -def _aten_max(self, dim=None, keepdim=False): - return jnp.max( - self, axis=dim, keepdims=keepdim), jnp.argmax( - self, axis=dim, keepdims=keepdim) - - -# aten.maximum -@op(torch.ops.aten.maximum) -def _aten_maximum(self, other): - return jnp.maximum(self, other) - - -# aten.abs -@op(torch.ops.aten.abs) -def _aten_abs(self): - return jnp.abs(self) - - -# generate aten.amax only -@op(torch.ops.aten.amax) -def _aten_amax(self, dim=None, keepdim=False): - return jnp.amax(self, axis=dim, keepdims=keepdim) - - -# aten.any -@op(torch.ops.aten.any) -def _aten_any(self, dim=None, keepdim=False): - return jnp.any(self, axis=dim, keepdims=keepdim) - - -# aten.arange -@op(torch.ops.aten.arange) -def _aten_arange(start, - end=None, - step=1, - *, - dtype=None, - layout=None, - requires_grad=False, - device=None, - pin_memory=False): - if end is None: - end = start - start = 0 - dtype = tensor.t2j_dtype(dtype) - return jnp.arange( - start, - end, - step, - dtype=dtype, - ) - - -# aten.argmax -@op(torch.ops.aten.argmax) -def _aten_argmax(self, dim=None, keepdim=False): - return jnp.argmax(self, axis=dim, keepdims=keepdim) - - -# aten.as_strided -@op(torch.ops.aten.as_strided) -@op(torch.ops.aten.as_strided_copy) -def _aten_as_strided(x, sizes, strides, storage_offset=None): - ind = jnp.zeros(sizes, dtype=jnp.int32) - - for i, (size, stride) in enumerate(zip(sizes, strides)): - result_shape = (1,) * i + (size,) + (1,) * (len(sizes) - i - 1) - indexes = (jnp.arange(size) * stride).reshape(result_shape) - ind += indexes - - return jnp.ravel(x)[ind] - - -# aten.atan2 -@op(torch.ops.aten.atan2) -def _aten_atan2(self, other): - return jnp.arctan2(self, other) - - -# aten.bitwise_and -@op(torch.ops.aten.bitwise_and) -def _aten_bitwise_and(self, other): - return self & other - - -# aten.bitwise_or -@op(torch.ops.aten.bitwise_or) -def _aten_bitwise_or(self, other): - return self | other - - -# aten.bitwise_xor -@op(torch.ops.aten.bitwise_xor) -def _aten_bitwise_xor(self, other): - return self ^ other - - -# aten.clamp -@op(torch.ops.aten.clamp) -def _aten_clamp(self, min=None, max=None): - return jnp.clip(self, min, max) - - -# aten.constant_pad_nd -@op(torch.ops.aten.constant_pad_nd) -def _aten_constant_pad_nd(input, padding, value=0): - # NOTE: Torch padding is flat and reversed: (1, 1, 2, 2) - # means last dim get padded 1 in front and 1 in back; - # and second last dim get padded 2 in front and 2 in back. - # Jax padding tuple of 2-tuple: the same padding is - # [(0, 0), ..., (2,2), (1,1)] - m = len(padding) - rev_padding = [(padding[i - 1], padding[i]) for i in range(m - 1, 0, -2)] - pad_dim = tuple(([(0, 0)] * (len(input.shape) - m // 2)) + rev_padding) - return jnp.pad(input, pad_dim, mode="constant", constant_values=value) - - -# aten.convolution_backward -@op(torch.ops.aten.copy) -@op(torch.ops.aten.lift_fresh_copy) -def _aten_copy(x): - return jnp.copy(x) - - -@op(torch.ops.aten._cdist_forward) -def _aten_cdist_forward(x1, x2, p, compute_mode=''): - # x1 is B x P x M - # x2 is B x Q x M - # res is B x P x Q - x1 = jnp.expand_dims(x1, len(x1.shape) - 1) - x2 = jnp.expand_dims(x2, len(x2.shape) - 2) - return jnp.linalg.norm(x1 - x2, ord=p, axis=-1) - - -@op(torch.ops.aten._pdist_forward) -def _aten__pdist_forward(x, p): - pairwise_dists = _aten_cdist_forward(x, x, p) - condensed_dists = pairwise_dists[jnp.triu_indices( - pairwise_dists.shape[0], k=1)] - return condensed_dists - - -# aten.cos -@op(torch.ops.aten.cos) -def _aten_cos(input): - return jnp.cos(input) - - -# aten.cosh -@op(torch.ops.aten.cosh) -def _aten_cosh(input): - return jnp.cosh(input) - - -# aten.diagonal -@op(torch.ops.aten.diagonal) -def _aten_diagonal(input, offset=0, dim1=0, dim2=1): - return jnp.diagonal(input, offset, dim1, dim2) - - -# aten.empty_strided -# aten.eq -@op(torch.ops.aten.eq) -def _aten_eq(input1, input2): - return input1 == input2 - - -# aten.erf -@op(torch.ops.aten.erf) -def _aten_erf(x): - if x.dtype in (jnp.int32, jnp.int64): - x = x.astype(jnp.float32) - return jax.lax.erf(x) - - -# aten.exp -@op(torch.ops.aten.exp) -def _aten_exp(input): - return jnp.exp(input) - - -# aten.expm1 -@op(torch.ops.aten.expm1) -def _aten_expm1(input): - return jnp.expm1(input) - - -# aten.fill -@op(torch.ops.aten.fill) -@op(torch.ops.aten.full_like) -def _aten_fill(x, value, dtype=None, pin_memory=None, memory_format=None): - if dtype is None: - dtype = x.dtype - else: - dtype = tensor.t2j_dtype(dtype) - return jnp.full(x.shape, value, dtype) - - -# aten.flip -@op(torch.ops.aten.flip) -def _aten_flip(input, dims): - if dims is not None: - return jnp.flip(input, tuple(dims)) - else: - return jnp.flip(input) - - -# aten.floor -@op(torch.ops.aten.floor) -def _aten_floor(input): - return jnp.floor(input) - - -# aten.fmod -@op(torch.ops.aten.fmod) -def _aten_fmod(input, other): - return input - other * _aten_div(input, other, 'trunc') - - -# aten.gather -@op(torch.ops.aten.gather) -def _aten_gather(input, dim, index): - input_indexes, source_indexes = _scatter_index(dim, index) - return input[input_indexes] - - -# aten.ge -@op(torch.ops.aten.ge) -def _aten_ge(self, other): - return self >= other - - -@op(torch.ops.aten.glu) -@op(torch.ops.aten.glu.default) -def _aten_glu(x, dim=-1): - return jax.nn.glu(x, dim) - - -# aten.hardtanh -@op(torch.ops.aten.hardtanh) -def _aten_hardtanh(input, min_val=-1., max_val=1., inplace=False): - return jnp.clip(input, min_val, max_val) - - -# aten.isinf -@op(torch.ops.aten.isinf) -def _aten_isinf(input): - return jnp.isinf(input) - - -# aten.isnan -@op(torch.ops.aten.isnan) -def _aten_isnan(input): - return jnp.isnan(input) - - -@op(torch.ops.aten.le) -def _aten_le(self, other): - return self <= other - - -# aten.leaky_relu -@op(torch.ops.aten.leaky_relu) -def _aten_leaky_relu(x, negative_slope): - return jax.nn.leaky_relu(x, negative_slope) - - -# aten.log -@op(torch.ops.aten.log) -def _aten_log(x): - return jnp.log(x) - - -# aten.log10 -@op(torch.ops.aten.log10) -def _aten_log10(x): - return jnp.log10(x) - - -# aten.log1p -@op(torch.ops.aten.log1p) -def _aten_log1p(x): - return jnp.log1p(x) - - -# aten.log2 -@op(torch.ops.aten.log2) -def _aten_log2(x): - return jnp.log2(x) - - -# aten.logical_and -@op(torch.ops.aten.logical_and) -def _aten_logical_and(self, other): - return jnp.logical_and(self, other) - - -# aten.logical_or -@op(torch.ops.aten.logical_or) -def _aten_logical_or(self, other): - return jnp.logical_or(self, other) - - -# aten.logical_not -@op(torch.ops.aten.logical_not) -def _aten_logical_not(self): - return jnp.logical_not(self) - - -# aten.log_softmax -@op(torch.ops.aten._log_softmax) -def _aten_log_softmax(self, axis=-1, half_to_float=False): - return jax.nn.log_softmax(self, axis) - - -# aten.max_pool3d_backward -# aten.logical_xor -@op(torch.ops.aten.logical_xor) -def _aten_logical_xor(self, other): - return jnp.logical_xor(self, other) - - -# aten.max_pool2d_with_indices_backward -# aten.native_dropout -# aten.native_group_norm_backward -# aten.neg -@op(torch.ops.aten.neg) -def _aten_neg(x): - return -1 * x - - -# aten.nonzero -@op(torch.ops.aten.nonzero) -def _aten_nonzero(x): - index_tuple = jnp.nonzero(x) - index_tuple = [jnp.expand_dims(p, -1) for p in index_tuple] - return jnp.concatenate(index_tuple, axis=-1) - - -# aten.prod - - -@op(torch.ops.aten.prod) -def _aten_prod(self, dim=None, keepdim=False): - return jnp.prod(self, axis=dim, keepdims=keepdim) - - -# aten.rand -# aten.randn -# aten.randperm -# aten.reflection_pad3d -# aten.remainder -@op(torch.ops.aten.remainder) -def _aten_remainder(inputs, other): - return inputs % other - - -# aten.repeat -@op(torch.ops.aten.repeat) -def _aten_repeat(x, reps): - return jnp.tile(x, reps) - - -# aten.replication_pad2d -# aten.replication_pad3d -# aten.roll -@op(torch.ops.aten.roll) -def _aten_roll(input, shifts, dims=None): - return jnp.roll(input, shifts, dims) - - -# aten.scalar_tensor -# aten.slice_scatter -@op(torch.ops.aten.slice_scatter) -def _aten_slice_scatter(input, src, dim=0, start=None, end=None, step=1): - input_index = [] - for x in range(len(input.shape)): - if x == dim: - input_index.append(slice(start, end, step)) - else: - input_index.append(slice(None, None, None)) - return input.at[tuple(input_index)].set(src) - - -# aten.sort -# torch.sort(input, dim=-1, descending=False, stable=False, *, out=None) -@op(torch.ops.aten.sort) -def _aten_sort(a, dim=-1, descending=False, stable=False): - return ( - jnp.sort(a, axis=dim, stable=stable, descending=descending), - jnp.argsort(a, axis=dim, stable=stable, descending=descending), - ) - - -# aten.sym_size - - -# aten.topk -@op(torch.ops.aten.topk) -def _aten_topk(input, k, dim=None, largest=True, sorted=True, *, out=None): - """JAX top-k implementation using jax.lax.top_k for improved efficiency. - - Args: - input: The input JAX array. - k: The number of top elements to return. - dim: The dimension along which to find the top-k. If None, operates on the - flattened array. - largest: If True, returns the largest k elements. Otherwise, smallest k. - sorted: If True, returns the elements in sorted order. - - Returns: - A tuple (values, indices) containing: - - values: The top k values. - - indices: The indices of the top k values in the original array. - """ - if dim is None: - input = input.flatten() - dim = 0 - - if not largest: - input = -input # Find top-k of negated input if we want the smallest - - transpose_shape = None - if dim != -1 and dim != len(input.shape) - 1: - transpose_shape = list(range(len(input.shape))) - transpose_shape[dim], transpose_shape[-1] = (transpose_shape[-1], - transpose_shape[dim]) - input = jnp.transpose(input, transpose_shape) - - values, indices = jax.lax.top_k(input, k) - - if sorted: - values = jnp.sort(values, descending=True) - indices = jnp.take_along_axis( - indices, jnp.argsort(values, axis=-1, descending=True), axis=-1) - - if not largest: - values = -values # Negate values back if we found smallest - - if transpose_shape is not None: - values = jnp.transpose(values, transpose_shape) - indices = jnp.transpose(indices, transpose_shape) - - return values, indices - - -# aten.trunc -@op(torch.ops.aten.trunc) -def _aten_trunc(a): - return jnp.trunc(a) - - -@op(torch.ops.aten.unbind) -@op(torch.ops.aten.unbind_copy) -def _aten_unbind(a, dim=0): - return tuple( - _aten_squeeze_dim(jax.lax.index_in_dim(a, i, axis=dim), dim) - for i in range(a.shape[dim])) - - -# NOTE: skip aten.upsample_nearest2d and aten.upsample_bilinear2d -# despite those being core aten ops, they also have decompositions. -# here we are using torch decompositions. - - -# aten.where -@op(torch.ops.aten.where) -def _aten_where(condition, x, y): - return jnp.where(condition, x, y) - - -# aten.to.dtype -#Tensor(a) self, ScalarType dtype, bool non_blocking=False, bool copy=False, MemoryFormat? memory_format=None -@op(torch.ops.aten.to.dtype) -def _aten_to_dtype(a, - dtype, - non_blocking=False, - copy=False, - memory_format=None): - jaxdtype = tensor.t2j_dtype(dtype) - return a.astype(jaxdtype) - - -# aten.to.device - - -#Tensor self, int[1]? dim=None, *, Scalar? correction=None, bool keepdim=False -@op(torch.ops.aten.var_mean.correction) -def _aten_var_mean_correction(self, dim=None, correction=None, keepdim=False): - return (jnp.var(self, axis=dim, ddof=correction, - keepdims=keepdim), jnp.mean(self, dim, keepdims=keepdim)) - - -@op(torch.ops.aten.scalar_tensor) -def _aten_scalar_tensor(s, - dtype=None, - layout=None, - device=None, - pin_memory=None): - if dtype is not None: - dtype = tensor.t2j_dtype(dtype) - return jnp.array(s, dtype=dtype) - return jnp.array(s) - - -@op(torch.ops.aten.to.device) -def _aten_to_device(x,device, dtype): - return x - - -@op(torch.ops.aten.max_pool2d_with_indices_backward) -def max_pool2d_with_indices_backward_custom(grad_output, self, kernel_size, stride, padding, dilation, ceil_mode, indices): - - """ - Approximates the gradient calculation of PyTorch's max_pool2d_with_indices_backward. - - Args: - grad_output: The gradient tensor from the preceding layer. - self: The input tensor on which the original max pooling was performed. - kernel_size: The size of the pooling window. - stride: The stride of the pooling window. - padding: The padding applied during max pooling. - dilation: The dilation factor for the pooling operation. - ceil_mode: Whether to use ceil or floor when calculating output shapes. - indices: The indices of the maximum values, as produced by max_pool2d_with_indices. - - Returns: - The calculated gradient with respect to the input (grad_input). - """ - - kH, kW = kernel_size - dH, dW = stride - padH, padW = padding - dilH, dilW = dilation - - # Calculate output shape (may need adjustment based on ceil_mode) - out_shape = jnp.array(self.shape) - grad_input = jnp.zeros_like(self) - - # Iterate over the flattened input and output tensors - for i, idx in enumerate(indices.flatten()): - # Calculate input coordinates corresponding to the maximum value - out_y, out_x = i // grad_output.shape[3], i % grad_output.shape[3] - in_y = out_y * dH - padH + out_y * (dilH - 1) - in_x = out_x * dW - padW + out_x * (dilW - 1) - - # Scatter the gradient to the appropriate input locations (handling potential overlaps) - for y in range(in_y, in_y + kH): - for x in range(in_x, in_x + kW): - if 0 <= y < grad_input.shape[2] and 0 <= x < grad_input.shape[3]: - grad_input = grad_input.at[y, x].add(grad_output.flatten()[i]) - - return grad_input - - -@op(torch.ops.aten._local_scalar_dense) -def _aten_local_scalar_dense(x): - return x.item() - -@op(torch.ops.aten.tensor_split.sections) -def _aten_tensor_split(ary, indices_or_sections, axis=0): - return jnp.array_split(ary, indices_or_sections, axis) \ No newline at end of file diff --git a/experimental/torch_xla2/torch_xla2/decompositions.py b/experimental/torch_xla2/torch_xla2/decompositions.py index e85e49e13ee..81b48bb5da8 100644 --- a/experimental/torch_xla2/torch_xla2/decompositions.py +++ b/experimental/torch_xla2/torch_xla2/decompositions.py @@ -90,4 +90,21 @@ def _reflection_or_replication_pad( return result _try_register(aten.replication_pad1d, _replication_pad) -_try_register(aten.replication_pad3d, _replication_pad) \ No newline at end of file +_try_register(aten.replication_pad3d, _replication_pad) + +EXTRA_DECOMP = decomp.get_decompositions([ + torch.ops.aten.upsample_nearest2d, + torch.ops.aten._native_batch_norm_legit.no_stats, + torch.ops.aten._adaptive_avg_pool2d, + torch.ops.aten._adaptive_avg_pool3d, + torch.ops.aten.grid_sampler_2d, + torch.ops.aten.native_dropout, + torch.ops.aten.reflection_pad1d, + torch.ops.aten.reflection_pad2d, + torch.ops.aten.reflection_pad3d, + torch.ops.aten.replication_pad1d, + torch.ops.aten.replication_pad2d, + torch.ops.aten.replication_pad3d, +]) + +EXTRA_DECOMP[torch.ops.aten.uniform] = torch.ops.aten.rand \ No newline at end of file diff --git a/experimental/torch_xla2/torch_xla2/environment.py b/experimental/torch_xla2/torch_xla2/environment.py index 6a71c7d51c0..139597f9cb0 100644 --- a/experimental/torch_xla2/torch_xla2/environment.py +++ b/experimental/torch_xla2/torch_xla2/environment.py @@ -1,26 +1,2 @@ -import jax - - -class Environment: - """This class holds a set of configurations and "globals" needed - - for executing torch program using jax. - Things included so far: - - op registry - PRNGKey - Configs - - Also helper functions to manipulate those. - """ - - _prng_key: jax.random.PRNGKey - - - def __init__(self, random_seed): - self._prng_key = jax.random.PRNGKey(random_seed) - - def get_and_rotate_prng_key(self): - self._prng_key, key = jax.random.split(self._prng_key) diff --git a/experimental/torch_xla2/torch_xla2/export.py b/experimental/torch_xla2/torch_xla2/export.py index 64a3f9d175c..387d9889386 100644 --- a/experimental/torch_xla2/torch_xla2/export.py +++ b/experimental/torch_xla2/torch_xla2/export.py @@ -2,145 +2,13 @@ """Utilities for exporting a torch program to jax/stablehlo.""" import copy from typing import Any, Dict, Tuple -import jax import torch -from torch.fx import _pytree as fx_pytree -from torch_xla2 import ops_registry, tensor from torch.utils import _pytree as pytree - - -class JaxProgram: - - def _wrap_inputs(self, xs, allow_torch_tensor=False): - - def convert(t): - if isinstance(t, tensor.XLATensor2): - return t - if isinstance(t, torch.Tensor): - if allow_torch_tensor: - return tensor.move_to_device(t) - else: - raise ValueError('Regular torch.Tensor is not allowed.') - if isinstance(t, jax.Array): - return tensor.XLATensor2(t) - return t - - return jax.tree_util.tree_map(convert, xs) - - def _unwrap_outputs(self, xs): - - def convert(t): - if isinstance(t, tensor.XLATensor2): - return t.jax() - if isinstance(t, torch.Tensor): - raise ValueError('Regular torch.Tensor is not allowed.') - return t - - return jax.tree_util.tree_map(convert, xs) - - def __init__( - self, - exported_program, - param_buffer_values, - ordered_tensor_constants, - ): - - self.param_buffer_values = self._wrap_inputs( - param_buffer_values, allow_torch_tensor=True) - self.ordered_tensor_constants = self._wrap_inputs( - ordered_tensor_constants, allow_torch_tensor=True) - self.exported_program = exported_program - - def __hash__(self): - return hash(self.exported_program) - - @property - def example_inputs(self): - args, kwargs = self.exported_program.example_inputs - args = pytree.tree_map(tensor.t2j, args) - kwargs = pytree.tree_map(tensor.t2j, kwargs) - return args, kwargs - - def flatten_inputs(self, args, kwargs): - if args is None: - args = tuple() - if kwargs is None: - kwargs = {} - - if (in_spec := self.exported_program.call_spec.in_spec) is not None: - if (in_spec.type == tuple and len(in_spec.children_specs) == 2 and - in_spec.children_specs[0].type == tuple and - in_spec.children_specs[1].type == dict): - # NOTE: this is the case where in_spec is for both args and kwargs - return fx_pytree.tree_flatten_spec((args, kwargs), in_spec) - return fx_pytree.tree_flatten_spec(args, in_spec) - return copy.deepcopy(args) - - def unflatten_outputs(self, res): - return pytree.tree_unflatten(res, self.exported_program.call_spec.out_spec) - - def __call__(self, *args, **kwargs): - - inputs = self.flatten_inputs(args, kwargs) - res = self.flatten_callable(*inputs) - res = self.unflatten_outputs(res) - - return res - - @property - def flatten_callable(self): - - def func(*inputs: jax.Array): - nonlocal self - inputs = self._wrap_inputs(inputs) - num_mutations = len( - self.exported_program.graph_signature.buffers_to_mutate) - res = torch.fx.Interpreter(self.exported_program.graph_module).run( - *self.param_buffer_values, - *inputs, - *self.ordered_tensor_constants, - enable_io_processing=False, - ) - res = res[num_mutations:] - res = self._unwrap_outputs(res) - return res - - return func - - def jit(self, *args, **kwargs): - """Returns `jax.jit(self, *args, **kwargs)`.""" - return jax.jit(self, *args, **kwargs) - - def jit_lower(self, *args, **kwargs): - """Returns `jax.jit(self, *args, **kwargs).lower(...)` with example_inputs used in export.""" - example_args, example_kwargs = self.example_inputs - return self.jit(*args, **kwargs).lower(*example_args, **example_kwargs) - - -def exported_program_to_jax_program(ep): - """exported_program_to_jax_program. - - Args: - ep: torch.export.ExportedProgram - - Returns: - JaxProgram - - """ - if torch.__version__ >= '2.2': - ep = ep.run_decompositions() - - param_buffer_keys = ep.graph_signature.parameters + ep.graph_signature.buffers - param_buffer_values = tuple(ep.state_dict[key] for key in param_buffer_keys) - - if hasattr(ep.graph_signature, 'lifted_tensor_constants'): - ordered_tensor_constants = tuple( - ep.tensor_constants[name] - for name in ep.graph_signature.lifted_tensor_constants) - else: - ordered_tensor_constants = tuple() - - return JaxProgram(ep, param_buffer_values, ordered_tensor_constants) +from torch_xla2 import tensor +from torch_xla2.ops import ops_registry +import jax +import jax.numpy as jnp +import sympy DEBUG = False @@ -149,6 +17,11 @@ def exported_program_to_jax_program(ep): class JaxInterpreter(torch.fx.Interpreter): """Experimental.""" + def __init__(self, graph_module): + super().__init__(graph_module) + import torch_xla2.ops.jaten + import torch_xla2.ops.jtorch + def call_function(self, target, args: Tuple, kwargs: Dict) -> Any: if not isinstance(target, (torch._ops.OpOverloadPacket, torch._ops.OpOverload)): @@ -157,7 +30,9 @@ def call_function(self, target, args: Tuple, kwargs: Dict) -> Any: if DEBUG: print('Running ', target.name(), '--------') - op = ops_registry.lowerings.lookup(target) + op = ops_registry.all_aten_ops.get(target) + if op is None: + op = ops_registry.all_aten_ops.get(target.overloadpacket) if op is None: print(target.name(), target.tags) raise RuntimeError('No lowering found for', target.name()) @@ -231,3 +106,125 @@ def func(states, inputs): states = pytree.tree_map_only(torch.Tensor, tensor.t2j, states) return states, func + + +def extract_avals(exported): + """Return JAX Abstract Value shapes for all input parameters of the exported + program. This supports dynamic batch dimensions, including with constraints. + """ + + def _to_aval(arg_meta, symbolic_shapes): + """Convet from torch type to jax abstract value for export tracing + """ + def _get_dim(d): + if isinstance(d, torch.SymInt): + return symbolic_shapes[str(d)] + return d + + val = arg_meta['val'] + is_scalar = isinstance(val, float) or isinstance(val, int) or isinstance(val, bool) + if is_scalar: + return jax.ShapeDtypeStruct([], type(arg_meta['val'])) + + tensor_meta = arg_meta['tensor_meta'] + shape = [_get_dim(d) for d in tensor_meta.shape] + return jax.ShapeDtypeStruct(shape, tensor.t2j_dtype(tensor_meta.dtype)) + + def _get_inputs(exported): + """Return placeholders with input metadata""" + placeholders = [p for p in exported.graph.nodes if p.op == "placeholder"] + input_placeholders = [ + p + for p, s in zip(placeholders, exported.graph_signature.input_specs) + if s.kind == torch.export.graph_signature.InputKind.USER_INPUT + ] + return input_placeholders + + def _build_symbolic_shapes(range_constraints): + """Convert torch SymInt to JAX symbolic_shape and stores in a map using the + string name of the torch symbolic int. + + TODO: There is probably a better way of storing a key for a symbolic int. + This value needs to be looked up again in `_to_aval` to figure out which + JAX symbolic to map to for a given torch tensor. + """ + if len(range_constraints) == 0: + return None + + def _build_symbolic_constraints(symbol_name, torch_constraint): + """Convert torch SymInt constraints to string for JAX symbolic_shape + Using sympy may be overkill here, currently PyTorch only uses ValueRanges + which allow specifying the min and the max of a value, for example: + torch.export.Dim("a", min=5, max=10) + ==> ("a >= 5", "a <= 10",) + """ + if not isinstance(torch_constraint, torch.utils._sympy.value_ranges.ValueRanges) or torch_constraint.is_bool: + raise TypeError(f"No symbolic constraint handler for: {torch_constraint}") + + constraints = [] + symbol = sympy.Symbol(symbol_name) + if torch_constraint.lower != 2: + constraints.append(symbol >= torch_constraint.lower) + if not torch_constraint.upper.is_infinite: + constraints.append(symbol <= torch_constraint.upper) + + return tuple(sympy.pretty(c, use_unicode=False) for c in constraints) + + def _build_symbolic_shape(sym, constraint, free_symbols): + """Returns a JAX symbolic shape for a given symbol and constraint + + There are two possible sympy `sym` inputs: + 1. Symbol - (s0) These can have custom constraints. + 2. Expr - (s0*2) These apply the expr to s0's constraints, cannot override. + + Currently support is limited to operations with a symbol and and int, + in `torch/export/dynamic_shapes.py`: + "Only increasing linear operations with integer coefficients are supported." + """ + symbol_name = str(sym) + constraints = _build_symbolic_constraints(symbol_name, constraint) + if sym.is_symbol: + symbolic_shape = jax.experimental.export.symbolic_shape(symbol_name, constraints=constraints) + else: + assert len(sym.free_symbols) > 0 + scope = free_symbols[str(list(sym.free_symbols)[0])].scope + symbolic_shape = jax.experimental.export.symbolic_shape(symbol_name, scope=scope) + assert len(symbolic_shape) == 1 + return symbolic_shape[0] + + # Populate symbol variables before expressions, exprs need to use the same + # Symbolic scope as the variable they operate on. Expressions can only be + # integer compuations on symbol variables, so each symbol variable is OK to + # have its own scope. + symbolic_shapes = {} + symbol_variables = [(s,v) for s,v in range_constraints.items() if s.is_symbol] + symbol_exprs = [(s,v) for s,v in range_constraints.items() if not s.is_symbol] + for sym, constraint in symbol_variables + symbol_exprs: + symbolic_shape = _build_symbolic_shape(sym, constraint, symbolic_shapes) + symbolic_shapes[str(sym)] = symbolic_shape + return symbolic_shapes + + symbolic_shapes = _build_symbolic_shapes(exported.range_constraints) + args = _get_inputs(exported) + + if DEBUG: + print('Inputs to aval:', args, '--------') + print('Symbolic shapes:', symbolic_shapes) + for arg in args: + print('Meta2Aval', arg.meta, '--> ', _to_aval(arg.meta, symbolic_shapes)) + + return [_to_aval(arg.meta, symbolic_shapes) for arg in args] + + +def exported_program_to_stablehlo(exported_program): + """Replacement for torch_xla.stablehlo.exported_program_to_stablehlo + + Convert a program exported via torch.export to StableHLO. + + This supports dynamic dimension sizes and generates explicit checks for + dynamo guards in the IR using shape_assertion custom_call ops. + """ + weights, func = exported_program_to_jax(exported_program) + jax_avals = extract_avals(exported_program) + jax_export = jax.experimental.export.export(func)(weights, (jax_avals,)) + return jax_export diff --git a/experimental/torch_xla2/torch_xla2/extra.py b/experimental/torch_xla2/torch_xla2/extra.py deleted file mode 100644 index ebfdb96b1db..00000000000 --- a/experimental/torch_xla2/torch_xla2/extra.py +++ /dev/null @@ -1,62 +0,0 @@ -import jax -import jax.numpy as jnp -import functools -import torch -from torch.utils import _pytree as pytree -from torch_xla2 import tensor - -def torch_view(t): - # t is an object from jax land - # view it as-if it's a torch land object - if isinstance(t, jax.Array): - return tensor.XLATensor2(t) - if isinstance(t, type(jnp.int32)): - return tensor.t2j_type(t) - if callable(t): - def new_t(*args, **kwargs): - # args, kwargs are torch-land - args, kwargs = pytree.tree_map(jax_view, (args, kwargs)) - # now they are objs in jax-land - res = t(*args, **kwargs) # t is jax callable - # res is jax-land obj - return pytree.tree_map(torch_view, res) - return new_t - # regular types are not changed - return t - - -def jax_view(t): - # t is an object from torch land - # view it as-if it's a jax land object - if isinstance(t, torch.Tensor): - assert isinstance(t, tensor.XLATensor2) - return t.jax() - if isinstance(t, type(torch.int32)): - return tensor.j2t_dtype(t) - if callable(t): - def new_t(*args, **kwargs): - # args, kwargs are jax-land - args, kwargs = pytree.tree_map(torch_view, (args, kwargs)) - # now they are objs in torch-land - res = t(*args, **kwargs) - # res is torch-land obj - return pytree.tree_map(jax_view, res) - return new_t - # regular types are not changed - return t - -def call_jax(jax_func, *args, **kwargs): - return torch_view(jax_func)(*args, **kwargs) - - -def call_torch(torch_func, *args, **kwargs): - return jax_view(torch_func)(*args, **kwargs) - - -fori_loop = torch_view(jax.lax.fori_loop) - -def jax_jit(torch_function, kwargs_for_jax_jit=None): - kwargs_for_jax_jit = kwargs_for_jax_jit or {} - jax_func = jax_view(torch_function) - jitted = jax.jit(jax_func, **kwargs_for_jax_jit) - return torch_view(jitted) diff --git a/experimental/torch_xla2/torch_xla2/functions.py b/experimental/torch_xla2/torch_xla2/functions.py deleted file mode 100644 index 9fcd5653a86..00000000000 --- a/experimental/torch_xla2/torch_xla2/functions.py +++ /dev/null @@ -1,109 +0,0 @@ -"""Tensor constructor overrides""" -import functools -import logging -from typing import Callable, Optional, ParamSpec, Sequence - -import jax -import torch -import jax.numpy as jnp -from torch_xla2 import tensor - -registry = {} - -P = ParamSpec('P') - - -def register_function(torch_func: Callable[P, torch.Tensor]): - """Registers a function as the JAX implementation of a torch function.""" - - def decorator(jax_impl: Callable[P, jax.Array]): - registry[torch_func] = jax_impl - return jax_impl - - return decorator - - -def convert_dtype(use_default_dtype: bool = True): - """Converts `dtype` kwarg of function from torch to JAX. - - Args: - use_default_dtype: Whether to use torch default dtype if none is provided. - - Returns: - A decorator that wraps a JAX implementation of a torch function. - """ - - def decorator(func: Callable[P, torch.Tensor]): - - @functools.wraps(func) - def wrapper(*args: P.args, - dtype: Optional[torch.dtype] = None, - **kwargs: P.kwargs): - if not dtype and use_default_dtype: - dtype = torch.get_default_dtype() - jax_dtype = tensor.t2j_dtype(dtype) - - return func(*args, dtype=jax_dtype, **kwargs) - - return wrapper - - return decorator - - -@register_function(torch.tensor) -@convert_dtype(use_default_dtype=False) # Attempt to infer type from elements -def _tensor(data, *, dtype=None, **kwargs): - python_types_to_torch_types = { - bool: jnp.bool, - int: jnp.int64, - float: jnp.float32, - complex: jnp.complex64, - } - if not dtype: - leaves = jax.tree_util.tree_leaves(data) - if len(leaves) > 0: - dtype = python_types_to_torch_types.get(type(leaves[0])) - - return jnp.array( - data, dtype=dtype or tensor.t2j_dtype(torch.get_default_dtype())) - - -@register_function(torch.ones) -@convert_dtype() -def _ones(*size: int, dtype=None, **kwargs): - return jnp.ones(size, dtype) - - -@register_function(torch.zeros) -@convert_dtype() -def _zeros(*size: int, dtype=None, **kwargs): - return jnp.zeros(size, dtype) - - -@register_function(torch.eye) -@convert_dtype() -def _eye(n: int, m: Optional[int] = None, *, dtype=None, **kwargs): - return jnp.eye(n, m, dtype=dtype) - - -@register_function(torch.full) -@convert_dtype() -def _full(size: Sequence[int], fill_value, *, dtype=None, **kwargs): - # TODO: handle torch.Size - return jnp.full(size, fill_value, dtype=dtype) - - -class XLAFunctionMode(torch.overrides.TorchFunctionMode): - """Context manager that dispatches torch function calls to JAX.""" - - def __torch_function__(self, - func, - types, - args=(), - kwargs=None) -> torch.Tensor: - jax_func = registry.get(func) - if not jax_func: - return func(*args, **(kwargs or {})) - - # TODO: unwrap args here or in implementations? - return tensor.wrap(jax_func(*args, **(kwargs or {}))) diff --git a/experimental/torch_xla2/torch_xla2/interop.py b/experimental/torch_xla2/torch_xla2/interop.py new file mode 100644 index 00000000000..d1a96179e82 --- /dev/null +++ b/experimental/torch_xla2/torch_xla2/interop.py @@ -0,0 +1,69 @@ +import functools +import torch +import jax +import jax.numpy as jnp +from jax import tree_util as pytree +from torch_xla2 import tensor +import torch_xla2 + +from torch_xla2.types import JaxValue, TorchValue, JaxCallable, TorchCallable + + + +def _torch_view(t: JaxValue) -> TorchValue: + # t is an object from jax land + # view it as-if it's a torch land object + if isinstance(t, jax.Array): + # TODO + return tensor.XLATensor2(t, torch_xla2.default_env()) + if isinstance(t, type(jnp.int32)): + return tensor.t2j_type(t) + if callable(t): # t is a JaxCallable + return functools.partial(call_jax, t) + # regular types are not changed + return t + +torch_view = functools.partial(pytree.tree_map, _torch_view) + + +def _jax_view(t: TorchValue) -> JaxValue: + # t is an object from torch land + # view it as-if it's a jax land object + if isinstance(t, torch.Tensor): + assert isinstance(t, tensor.XLATensor2) + return t.jax() + if isinstance(t, type(torch.int32)): + return tensor.j2t_dtype(t) + + # torch.nn.Module needs special handling + if not isinstance(t, torch.nn.Module) and callable(t): # t is a TorchCallable + return functools.partial(call_torch, t) + # regular types are not changed + return t + +jax_view = functools.partial(pytree.tree_map, _jax_view) + + +def call_jax(jax_func: JaxCallable, + *args: TorchValue, + **kwargs: TorchValue) -> TorchValue: + args, kwargs = jax_view((args, kwargs)) + res: JaxValue = jax_func(*args, **kwargs) + return torch_view(res) + + +def call_torch(torch_func: TorchCallable, *args: JaxValue, **kwargs: JaxValue) -> JaxValue: + args, kwargs = torch_view((args, kwargs)) + with torch_xla2.default_env(): + res: TorchValue = torch_func(*args, **kwargs) + return jax_view(res) + + +fori_loop = torch_view(jax.lax.fori_loop) + +def jax_jit(torch_function, kwargs_for_jax_jit=None): + kwargs_for_jax_jit = kwargs_for_jax_jit or {} + jax_func = jax_view(torch_function) + jitted = jax.jit(jax_func, **kwargs_for_jax_jit) + return torch_view(jitted) + diff --git a/experimental/torch_xla2/torch_xla2/ops/__init__.py b/experimental/torch_xla2/torch_xla2/ops/__init__.py index e69de29bb2d..abefc8344b1 100644 --- a/experimental/torch_xla2/torch_xla2/ops/__init__.py +++ b/experimental/torch_xla2/torch_xla2/ops/__init__.py @@ -0,0 +1,9 @@ +def all_aten_jax_ops(): + # to load the ops + import torch_xla2.jaten # type: ignore + import torch_xla2.ops_registry # type: ignore + return { + key: val.func + for key, val in torch_xla2.ops_registry.all_aten_ops + if val.is_jax_function + } \ No newline at end of file diff --git a/experimental/torch_xla2/torch_xla2/ops/jaten.py b/experimental/torch_xla2/torch_xla2/ops/jaten.py index a30fae82de8..c5ca628908f 100644 --- a/experimental/torch_xla2/torch_xla2/ops/jaten.py +++ b/experimental/torch_xla2/torch_xla2/ops/jaten.py @@ -1,5 +1,14 @@ -"""This module contains implementation of ATen ops.""" +"""Torch ops implemented using jax.""" + +import sys + +import jax +from jax import numpy as jnp +import numpy as np import torch +from torch_xla2.ops import ops_registry +from torch_xla2 import tensor +from torch_xla2.ops import op_base # Keys are OpOverload, value is a callable that takes # XLATensor2 @@ -9,29 +18,1980 @@ # and need to be implemented in jax mutation_ops_to_functional = { - torch.ops.aten.add_: torch.ops.aten.add, - torch.ops.aten.sub_: torch.ops.aten.sub, - torch.ops.aten.mul_: torch.ops.aten.mul, - torch.ops.aten.div_: torch.ops.aten.div, - torch.ops.aten.pow_: torch.ops.aten.pow, - torch.ops.aten.lt_: torch.ops.aten.lt, - torch.ops.aten.le_: torch.ops.aten.le, - torch.ops.aten.gt_: torch.ops.aten.gt, - torch.ops.aten.ge_: torch.ops.aten.ge, - torch.ops.aten.eq_: torch.ops.aten.eq, - torch.ops.aten.ne_: torch.ops.aten.ne, + torch.ops.aten.add_: torch.ops.aten.add, + torch.ops.aten.sub_: torch.ops.aten.sub, + torch.ops.aten.mul_: torch.ops.aten.mul, + torch.ops.aten.div_: torch.ops.aten.div, + torch.ops.aten.pow_: torch.ops.aten.pow, + torch.ops.aten.lt_: torch.ops.aten.lt, + torch.ops.aten.le_: torch.ops.aten.le, + torch.ops.aten.gt_: torch.ops.aten.gt, + torch.ops.aten.ge_: torch.ops.aten.ge, + torch.ops.aten.eq_: torch.ops.aten.eq, + torch.ops.aten.ne_: torch.ops.aten.ne, + torch.ops.aten.uniform_: torch.ops.aten.uniform, + torch.ops.aten.relu_: torch.ops.aten.relu, } def make_mutation(op): + return op_base.InplaceOp(mutation_ops_to_functional[op], position_to_mutate=0) - def f(*args, **kwargs): - res = mutation_ops_to_functional[op](*args, **kwargs) - args[0].copy_(res) - return args[0] - return f +for op in mutation_ops_to_functional.keys(): + ops_registry.register_torch_dispatch_op( + op, make_mutation(op), is_jax_function=False + ) -for op in mutation_ops_to_functional.keys(): - all_ops[op] = make_mutation(op) +def op(*aten, **kwargs): + def inner(func): + for a in aten: + ops_registry.register_torch_dispatch_op(a, func, **kwargs) + return func + + return inner + + +@op( + torch.ops.aten.view_copy, + torch.ops.aten.view, + torch.ops.aten._unsafe_view, + torch.ops.aten.reshape, +) +def _aten_unsafe_view(x, shape): + return jnp.reshape(x, shape) + + +@op(torch.ops.aten.add.Tensor) +@op(torch.ops.aten.add.Scalar) +def _aten_add(x, y, *, alpha=1): + """if isinstance(x, jnp.ndarray) and isinstance(y, jnp.ndarray): + + assert x.dtype == y.dtype, (x.dtype, y.dtype) + """ + return x + y * alpha + + +@op(torch.ops.aten.copy_, torch.ops.aten.copy_.default, is_jax_function=False) +def _aten_copy(x, y, memory_format=None): + if isinstance(x, tensor.XLATensor2): + x._elem = y._elem + elif isinstance(x, tensor.SliceView): + x.mutate(y) + return x + + +@op(torch.ops.aten.clone) +@op(torch.ops.aten.clone.default) +def _aten_clone(x, memory_format=None): + return jnp.copy(x) + + +@op(torch.ops.aten.full) +def _aten_full(size, value, **kwargs): + return jnp.full(size, value) + + +@op(torch.ops.aten.index_copy) +def _aten_index_copy(x, dim, indexes, source): + # return jax.lax.scatter(x, index, dim) + dims = [] + for i in range(len(x.shape)): + if i == dim: + dims.append(indexes) + else: + dims.append(slice(None, None, None)) + return x.at[dim].set(source) + + +@op(torch.ops.aten.select) +@op(torch.ops.aten.index_select) +@op(torch.ops.aten.select_copy) +def _aten_index_select(x, dim, indexes): + dims = [] + for i in range(len(x.shape)): + if i == dim: + dims.append(indexes) + else: + dims.append(slice(None, None, None)) + return x[tuple(dims)] + + +@op(torch.ops.aten.mean) +def _aten_mean(x, dim=None, keepdim=False): + return jnp.mean(x, dim, keepdims=keepdim) + + +def _torch_binary_scalar_type(scalar, tensor): + if "float" in str(tensor.dtype): + return tensor.dtype + + if isinstance(scalar, int): + if "int" in str(tensor.dtype): + return tensor.dtype + + return jnp.float32 + + +@op(torch.ops.aten.sub.Tensor) +@op(torch.ops.aten.sub.Scalar) +def _aten_sub(x, y): + if isinstance(x, float): + dtype = _torch_binary_scalar_type(x, y) + x = jnp.array(x, dtype=dtype) + if isinstance(y, float): + dtype = _torch_binary_scalar_type(y, x) + y = jnp.array(y, dtype=dtype) + return x - y + + +@op(torch.ops.aten.mm) +def _aten_mm(x, y): + res = x @ y + return res + + +@op(torch.ops.aten.mul.Tensor, torch.ops.aten.mul.Scalar) +def _aten_mul(x, y): + return x * y + + +@op(torch.ops.aten.silu) +def _aten_silu(x): + return jax.nn.silu(x) + + +@op(torch.ops.aten.t) +def _aten_t(x): + return jnp.transpose(x) + + +@op(torch.ops.aten.transpose) +@op(torch.ops.aten.transpose_copy) +def _aten_transpose(x, dim0, dim1): + shape = list(range(len(x.shape))) + shape[dim0], shape[dim1] = shape[dim1], shape[dim0] + return jnp.transpose(x, shape) + + +@op(torch.ops.aten.triu) +def _aten_triu(m, k): + return jnp.triu(m, k) + + +@op(torch.ops.aten.slice) +@op(torch.ops.aten.slice_copy) +def _aten_slice(self, dim=0, start=None, end=None, step=1): + if end == sys.maxsize: + end = self.shape[dim] + sl = slice(start, end, step) + dims = [] + for i in range(len(self.shape)): + if i == dim: + dims.append(sl) + else: + dims.append(slice(None, None, None)) + return self[tuple(dims)] + + +@op(torch.ops.aten.detach) +def _aten_detach(self): + return self + + +@op(torch.ops.aten.view_as_real) +def _aten_view_as_real(x): + real = jnp.real(x) + im = jnp.imag(x) + res = jnp.stack([real, im], -1) + return res + + +@op(torch.ops.aten.stack) +def _aten_stack(tensors, dim=0): + return jnp.stack(tensors, dim) + + +@op(torch.ops.aten._softmax) +def _aten_softmax(x, dim, halftofloat): + return jax.nn.softmax(x, dim) + + +@op(torch.ops.aten.pow) +def _aten_pow(x, y): + if isinstance(y, int): + y = float(y) + return jnp.power(x, y) + + +@op(torch.ops.aten.view_as_complex) +def _aten_view_as_complex(input): + if input.dtype == jnp.bfloat16: + input = input.astype(jnp.float32) + x, y = input[..., 0], input[..., 1] + return jax.lax.complex(x, y) + + +@op(torch.ops.aten.div) +def _aten_div(x, y, rounding_mode=""): + res = x / y + if rounding_mode == "trunc": + res = jnp.trunc(res) + return res + + +@op(torch.ops.aten.div_, is_jax_function=False) +def _aten_div_(x, y, rounding_mode=""): + x._elem = _aten_div(x._elem, y._elem, rounding_mode) + return x + + +@op(torch.ops.aten.true_divide) +def _aten_true_divide(x, y): + return x / y + + +@op(torch.ops.aten.bmm) +def _aten_bmm(x, y): + res = x @ y + return res + # return jnp.einsum('bnm,bmk->bnk', x, y) + + +@op(torch.ops.aten.embedding) +# embedding(Tensor weight, Tensor indices, SymInt padding_idx=-1, bool scale_grad_by_freq=False, bool sparse=False) +def _aten_embedding(a, w, padding_idx=-1): + return jnp.take(a, w, axis=0) + + +@op(torch.ops.aten.rsqrt) +def _aten_rsqrt(x): + if isinstance(x, int): + x = float(x) + if x.dtype == jnp.int32: + x = x.astype(jnp.float32) + return jax.lax.rsqrt(x) + + +@op(torch.ops.aten.expand) +@op(torch.ops.aten.expand_copy) +def _aten_expand(x, dims): + def fix_dims(d, xs): + if d == -1: + return xs + return d + + dims = [fix_dims(p, s) for p, s in zip(dims, x.shape)] + return jnp.broadcast_to(x, dims) + + +@op(torch.ops.aten.dot) +def _aten_dot(x, y): + return jnp.dot(x, y) + + +@op(torch.ops.aten._to_copy) +def _aten__to_copy(self, **kwargs): + dtype = tensor.t2j_dtype(kwargs["dtype"]) + if dtype != self.dtype: + return self.astype(dtype) + return jnp.copy(self) + + +@op(torch.ops.aten.empty) +def _aten_empty(sizes, **kwargs): + return jnp.zeros(sizes) + + +@op(torch.ops.aten.index_put_) +@op(torch.ops.aten.index_put) +def _aten_index_put(self, indexes, values, accumulate=False): + indexes = [slice(None, None, None) if i is None else i for i in indexes] + indexes = tuple(indexes) + if accumulate: + return self.at[indexes].add(values) + else: + return self.at[indexes].set(values) + + +@op(torch.ops.aten.index) +@op(torch.ops.aten._unsafe_index) +@op(torch.ops.aten.index.Tensor) +def _aten_index(self, indexes): + indexes = [slice(None, None, None) if i is None else i for i in indexes] + indexes = tuple(indexes) + return self[indexes] + + +@op(torch.ops.aten.split) +@op(torch.ops.aten.split_copy) +@op(torch.ops.aten.split_with_sizes) +def split_with_sizes(x, sizes, dim=0): + """Splits an array `x` into sub-arrays based on static sizes `sizes`. + + Args: + x: The input array to split. + sizes: A 1D array of integer sizes for each sub-array. + + Returns: + A list of sub-arrays. + """ + if isinstance(sizes, int): + # split equal size + new_sizes = [sizes] * (x.shape[dim] // sizes) + sizes = new_sizes + rank = x.ndim + splits = np.cumsum(sizes) # Cumulative sum for split points + + def make_range(rank, dim, start, end): + res = [slice(None, None, None)] * rank + res[dim] = slice(start, end) + return tuple(res) + + return [ + x[make_range(rank, dim, start, end)] + for start, end in zip([0] + list(splits[:-1]), splits) + ] + + +@op(torch.ops.aten.permute) +@op(torch.ops.aten.permute_copy) +def permute(t, dims): + return jnp.transpose(t, dims) + + +@op(torch.ops.aten.unsqueeze) +@op(torch.ops.aten.unsqueeze_copy) +@op(torch.ops.aten.unsqueeze.default) +def _aten_unsqueeze(self, dim): + if dim < 0: + dim += self.ndim + 1 + return jnp.expand_dims(self, dim) + + +@op(torch.ops.aten.ne) +def _aten_ne(x, y): + return jnp.not_equal(x, y) + + +@op(torch.ops.aten.cumsum) +def _aten_cumsum(x, y, dtype=None): + if dtype: + dtype = tensor.t2j_dtype(dtype) + res = jnp.cumsum(x, y, dtype) + return res + + +@op(torch.ops.aten.native_layer_norm) +def _aten_native_layer_norm( + input, normalized_shape, weight=None, bias=None, eps=1e-5 +): + """Implements layer normalization in Jax as defined by `aten::native_layer_norm`. + + Args: + input: The input tensor. + normalized_shape: A list of integer dimensions to be normalized over. + weight: Optional weight tensor for the affine transformation. + bias: Optional bias tensor for the affine transformation. + eps: A small epsilon value for numerical stability. + + Returns: + output: The normalized tensor. + mean: The calculated mean tensor. + std: The calculated standard deviation tensor. + """ + if isinstance(normalized_shape, int): + normalized_shape = [normalized_shape] + axis = [i for i, d in enumerate(input.shape) if d in normalized_shape] + + # Calculate mean and standard deviation + mean = jnp.mean(input, axis=axis, keepdims=True) + var = jnp.var(input, axis=axis, keepdims=True) + rstd = jax.lax.rsqrt(var + eps) + + # Normalize the input + norm_x = (input - mean) * rstd + + # Apply affine transformation (if provided) + if weight is not None: + norm_x *= weight + if bias is not None: + norm_x += bias + return norm_x, mean, rstd + + +# - func: addmm(Tensor self, Tensor mat1, Tensor mat2, *, Scalar beta=1, Scalar alpha=1) -> Tensor +@op(torch.ops.aten.addmm) +@op(torch.ops.aten.addmv) +def _aten_addmm(self, mat1, mat2, *, beta=1.0, alpha=1.0): + alpha = jnp.array(alpha).astype(mat1.dtype) + beta = jnp.array(beta).astype(mat1.dtype) + self *= beta + self += alpha * jnp.matmul(mat1, mat2) + return self + + +@op(torch.ops.aten.addbmm.default) +def _aten_addbmm(input, batch1, batch2, *, beta=1, alpha=1): + alpha = jnp.array(alpha).astype(batch1.dtype) + beta = jnp.array(beta).astype(batch1.dtype) + mm = jnp.einsum("bxy, byz -> xz", batch1, batch2) + return jax.lax.cond( + beta == 0, lambda: alpha * mm, lambda: beta * input + alpha * mm + ) + + +@op(torch.ops.aten.gelu) +def _aten_gelu(self, *, approximate="none"): + approx = approximate == "tanh" + return jax.nn.gelu(self, approx) + + +@op(torch.ops.aten.squeeze) +@op(torch.ops.aten.squeeze_copy) +def _aten_squeeze_dim(self, dim): + """Squeezes a Jax tensor by removing a single dimension of size 1. + + Args: + self: The input tensor. + dim: The dimension to squeeze. + + Returns: + The squeezed tensor with the specified dimension removed if it is 1, + otherwise the original tensor is returned. + """ + + # Validate input arguments + if not isinstance(self, jnp.ndarray): + raise TypeError(f"Expected a Jax tensor, got {type(self)}.") + if isinstance(dim, int): + dim = [dim] + + # Check if the specified dimension has size 1 + if all([self.shape[d] != 1 for d in dim]): + return self + + # Use slicing to remove the dimension if it is 1 + new_shape = list(self.shape) + + def fix_dim(p): + if p < 0: + return p + len(self.shape) + return p + + dim = [fix_dim(d) for d in dim] + new_shape = [p for i, p in enumerate(self.shape) if i not in dim or p != 1] + return self.reshape(new_shape) + + +@op(torch.ops.aten.convolution) +def _aten_convolution( + input, + weight, + bias, + stride, + padding, + dilation, + transposed, + output_padding, + groups, +): + if transposed: + raise NotImplementedError("Transposed convolution is not implemented.") + + def make_padding(padding): + return ((p, p) for p in padding) + + def create_default_conv_dimension_numbers(num_spatial_dims): + # Ref: https://github.com/openxla/xla/blob/main/xla/client/xla_builder.cc#L4211 + # (batch dimension, feature dimension, spatial dimensions...) + lhs_spec = [0, 1] + # (out feature dimension, in feature dimension, spatial dimensions...) + rhs_spec = [0, 1] + # (batch dimension, feature dimension, spatial dimensions...) + out_spec = [0, 1] + for i in range(0, num_spatial_dims): + lhs_spec.append(i + 2) + rhs_spec.append(i + 2) + out_spec.append(i + 2) + return jax.lax.ConvDimensionNumbers( + *map(tuple, (lhs_spec, rhs_spec, out_spec)) + ) + + res = jax.lax.conv_general_dilated( + input, + weight, + stride, + make_padding(padding), + lhs_dilation=(1,) * len(stride), + rhs_dilation=dilation, + dimension_numbers=create_default_conv_dimension_numbers(len(stride)), + feature_group_count=groups, + batch_group_count=1, + ) + + if bias is not None: + # TODO(qihqi): bias always on channel? + if len(bias.shape) == 1: + shape = [1] * len(res.shape) + shape[1] = bias.shape[0] + bias = bias.reshape(tuple(shape)) + res = res + bias + return res + + +# _native_batch_norm_legit(Tensor input, Tensor? weight, Tensor? bias, Tensor(a!) running_mean, Tensor(b!) running_var, bool training, float momentum, float eps) +@op(torch.ops.aten._native_batch_norm_legit) +def _aten__native_batch_norm_legit( + input, weight, bias, running_mean, running_var, training, momentum, eps +): + """JAX implementation of batch normalization with optional parameters. + Refers to https://github.com/pytorch/pytorch/blob/cd3a71f754a2248bcfe500de7c9860bd7d2002bf/torch/_decomp/decompositions.py#L1713. + + Args: + input (DeviceArray): Input data (N, C, H, W). + running_mean ([DeviceArray]): Running mean of input (C,). + running_var ([DeviceArray]): Running variance of input (C,). + weight (Optional[DeviceArray]): Scaling factor (gamma) (C,). Can be None. + bias (Optional[DeviceArray]): Shift factor (beta) (C,). Can be None. + training (bool): If True, use batch statistics for normalization. + If False, use running statistics. + momentum (float): Momentum factor for updating running statistics. + eps (float): Small constant for numerical stability. + + Returns: + DeviceArray: Normalized output + DeviceArray: Batch mean (C,) or empty if training is False + DeviceArray: Reversed batch variance (C,) or empty if training is False + """ + reduction_dims = [0] + list(range(2, input.ndim)) + reshape_dims = [1, -1] + [1]*(input.ndim-2) + + if training: + # Calculate batch mean and variance + mean = jnp.mean(input, axis=reduction_dims, keepdims=True) + saved_mean = jnp.squeeze(mean, reduction_dims) + var = jnp.var(input, axis=reduction_dims) + rstd = jax.lax.rsqrt(var.reshape(reshape_dims) + eps) + # Update running statistics using momentum + running_mean = (1 - momentum) * running_mean + momentum * saved_mean + running_var = (1 - momentum) * running_var + momentum * var + saved_rstd = jnp.squeeze(rstd, reduction_dims) + else: + rstd = jax.lax.rsqrt(running_var.reshape(reshape_dims) + eps) + saved_mean = jnp.array([]) # No need to calculate batch statistics in inference mode + saved_rstd = jnp.array([]) + + # Normalize + if training: + # use batch statistics if training + x_hat = (input - mean) * rstd + else: + # Use running statistics in inference mode + x_hat = (input - running_mean.reshape(reshape_dims)) * rstd + + # Scale and shift + if weight is not None: + x_hat *= weight.reshape(reshape_dims) # Reshape weight for broadcasting + if bias is not None: + x_hat += bias.reshape(reshape_dims) # Reshape bias for broadcasting + + return x_hat, saved_mean, saved_rstd + + + +@op(torch.ops.aten._native_batch_norm_legit_no_training) +def _aten__native_batch_norm_legit_no_training( + input, weight, bias, running_mean, running_var, momentum, eps +): + return _aten__native_batch_norm_legit( + input, weight, bias, running_mean, running_var, False, momentum, eps + ) + + +@op(torch.ops.aten.relu) +def _aten_relu(self): + return jax.nn.relu(self) + + +@op(torch.ops.aten.cat) +def _aten_cat(tensors, dims=0): + return jnp.concatenate(tensors, dims) + + +@op(torch.ops.aten.max_pool2d_with_indices) +@op(torch.ops.aten.max_pool3d_with_indices) +def _aten_max_pool2d_with_indices( + inputs, kernel_size, strides, padding=0, dilation=1, ceil_mode=False +): + num_batch_dims = len(inputs.shape) - len(kernel_size) - 1 + kernel_size = tuple(kernel_size) + strides = tuple(strides) + if isinstance(padding, int): + padding = tuple((padding, padding) for _ in range(len(kernel_size))) + elif isinstance(padding, list): + padding = tuple((p, p) for p in padding) + + window_shape = kernel_size + num_batch_dims = inputs.ndim - (len(window_shape) + 1) + strides = strides or (1,) * len(window_shape) + assert len(window_shape) == len( + strides + ), f"len({window_shape}) must equal len({strides})" + strides = (1,) * (1 + num_batch_dims) + strides + dims = (1,) * (1 + num_batch_dims) + window_shape + + is_single_input = False + if num_batch_dims == 0: + # add singleton batch dimension because lax.reduce_window always + # needs a batch dimension. + inputs = inputs[None] + strides = (1,) + strides + dims = (1,) + dims + is_single_input = True + + assert inputs.ndim == len(dims), f"len({inputs.shape}) != len({dims})" + if not isinstance(padding, str): + padding = tuple(map(tuple, padding)) + assert len(padding) == len(window_shape), ( + f"padding {padding} must specify pads for same number of dims as " + f"window_shape {window_shape}" + ) + assert all( + [len(x) == 2 for x in padding] + ), f"each entry in padding {padding} must be length 2" + padding = ((0, 0), (0, 0)) + padding + + indices = jnp.arange(np.prod(inputs.shape)).reshape(inputs.shape) + + def reduce_fn(a, b): + ai, av = a + bi, bv = b + which = av > bv + return jnp.where(which, ai, bi), jnp.where(which, av, bv) + + init_val = -jnp.inf + if inputs.dtype in (jnp.int32, jnp.int64): + init_val = -(1 << 31) + init_val = jnp.array(init_val).astype(inputs.dtype) + + indices, y = jax.lax.reduce_window( + (indices, inputs), (0, init_val), reduce_fn, dims, strides, padding + ) + if is_single_input: + indices = jnp.squeeze(indices, axis=0) + y = jnp.squeeze(y, axis=0) + return y, indices + + batch_result = pool( + inputs, -jnp.inf, jax.lax.max, kernel_size, strides, padding + ) + indices = pool(inputs, 0, jnp.argmax, kernel_size, strides, padding) + return batch_result, indices + + +# TODO add more ops + + +@op(torch.ops.aten.min) +def _aten_min(x, axis=None): + return jnp.min(x, axis=axis), jnp.argmin(x, axis=axis).astype(jnp.int64) + + +@op(torch.ops.aten.amin) +def _aten_amin(x, dim=None, keepdim=False): + return _with_reduction_scalar(jnp.amin, x, dim, keepdim) + + +@op(torch.ops.aten.argmin) +def _aten_argmin(self, dim=None, keepdim=False): + return _with_reduction_scalar(jnp.argmin, self, dim, keepdim) + + +@op(torch.ops.aten.sin) +def _aten_sin(x): + return jnp.sin(x) + + +@op(torch.ops.aten.sym_size) +def _aten_sym_size(x, dim): + return x.shape[dim] + + +@op(torch.ops.aten.var.correction) +@op(torch.ops.prims.var) +def _aten_var(x, dim=None, *, correction=1, keepdim=False, out=None): + return jnp.var(x, axis=dim, ddof=correction, keepdims=keepdim) + + +@op(torch.ops.prims.broadcast_in_dim) +def _prims_broadcast_in_dim(t, shape, broadcast_dimensions): + return jax.lax.broadcast_in_dim( + t, shape, broadcast_dimensions=broadcast_dimensions + ) + + +# aten.native_group_norm -- should use decomp table +# func: native_group_norm(Tensor input, Tensor? weight, Tensor? bias, SymInt N, SymInt C, SymInt HxW, int group, float eps) -> (Tensor, Tensor, Tensor) + + +@op(torch.ops.aten.native_group_norm) +def _aten_native_group_norm(input, weight, bias, N, C, HxW, group, eps=1e-5): + """Group Normalization implementation in JAX. + + Args: + input: Input tensor. Expected shape (batch_size, channels, ... spatial dims + ...) + weight: Optional scaling (gamma) parameter. Shape (channels,) + bias: Optional shifting (beta) parameter. Shape (channels,) + N: Batch size. + C: Number of channels. + HxW: Product of spatial dimensions (number of elements per channel after + flattening). + group: Number of groups for Group Normalization. + eps: Small value added for numerical stability. + + Returns: + A tuple of (normalized_output, mean, rstd) + """ + + input_shape = input.shape + + # Reshape for group-wise normalization + reshaped_input = jnp.reshape(input, (1, N * group, -1)) + + # **Core Group Normalization** + def group_norm_body(x): # Function to apply within each group + mean = jnp.mean(x, axis=-1, keepdims=True) + var = jnp.var(x, axis=-1, keepdims=True) + rstd = jax.lax.rsqrt(var + eps) # Reciprocal of std with epsilon + normalized = (x - mean) * rstd + return normalized, mean, rstd + + normalized, group_mean, group_rstd = jax.lax.map( + group_norm_body, reshaped_input + ) + + # Reshape back to original input shape + output = jnp.reshape(normalized, input_shape) + + # **Affine transformation** + affine_shape = [ + -1 if i == 1 else 1 for i in range(input.ndim) + ] # Shape for broadcasting + if weight is not None and bias is not None: + output = bias.reshape(affine_shape) + output * weight.reshape(affine_shape) + elif weight is not None: + output = output * weight.reshape(affine_shape) + elif bias is not None: + output = output + bias.reshape(affine_shape) + + # Reshape mean and rstd + mean = jnp.reshape(group_mean, (N, group)) + rstd = jnp.reshape(group_rstd, (N, group)) + + return output, mean, rstd + + +@op(torch.ops.aten.linalg_vector_norm) +def _aten_linalg_vector_norm(self, ord=2, dim=None, keepdim=False, dtype=None): + """Calculates the vector norm along specified dimensions. + + Args: + self: The input tensor. + ord: The order of the norm. Can be a float or 'inf', '-inf', 'fro'. + Default is 2 (Euclidean norm). + dim: Dimensions along which to calculate the norm. If None, the norm is + calculated over all dimensions. + keepdim: Whether to keep the reduced dimensions. + dtype: Optional data type for the output. + + Returns: + The tensor containing the calculated vector norms. + """ + + if ord not in {2, float("inf"), float("-inf"), "fro"}: + raise ValueError( + f"Unsupported ord value: {ord}. Supported values are 2, inf, -inf, and" + " 'fro'." + ) + + # Special cases (for efficiency and clarity) + if ord == 2: # Euclidean norm + result = jnp.sqrt(jnp.sum(jnp.abs(self) ** 2, axis=dim, keepdims=keepdim)) + + elif ord == float("inf"): + result = jnp.max(jnp.abs(self), axis=dim, keepdims=keepdim) + + elif ord == float("-inf"): + result = jnp.min(jnp.abs(self), axis=dim, keepdims=keepdim) + + elif ord == "fro": # Frobenius norm + result = jnp.sqrt(jnp.sum(jnp.abs(self) ** 2, axis=dim, keepdims=keepdim)) + + else: # General case (e.g., ord = 1, ord = 3) + result = jnp.sum(jnp.abs(self) ** ord, axis=dim, keepdims=keepdim) ** ( + 1.0 / ord + ) + + # (Optional) dtype conversion + if dtype is not None: + result = result.astype(dtype) + + return result + + +# aten.reflection_pad1d +@op(torch.ops.aten.reflection_pad1d) +def _aten_reflection_pad1d(input, padding): + rank = len(input.shape) + pad_size = [(0, 0)] * rank + pad_size[-1] = padding + return jnp.pad(input, pad_size, mode="reflect") + + +# aten.alias +@op(torch.ops.aten.alias) +def _aten_alias(self, *args): + return self + + +# aten.sinh +@op(torch.ops.aten.sinh) +def _aten_sinh(self): + return jnp.sinh(self) + + +# aten.native_layer_norm_backward +@op(torch.ops.aten.native_layer_norm_backward) +def _aten_native_layer_norm_backward( + grad_out, input, normalized_shape, weight, bias, eps=1e-5 +): + """Implements the backward pass of layer normalization in Jax as defined by `aten::native_layer_norm_backward`. + + Args: + grad_out: The gradient of the output tensor. + input: The input tensor. + normalized_shape: A list of integer dimensions to be normalized over. + weight: Optional weight tensor for the affine transformation. + bias: Optional bias tensor for the affine transformation. + eps: A small epsilon value for numerical stability. + + Returns: + A tuple of (grad_input, grad_weight, grad_bias). + """ + return jax.lax.native_layer_norm_backward( + grad_out, input, normalized_shape, weight, bias, eps + ) + + +# aten.reflection_pad3d_backward +# aten.reflection_pad2d + + +# aten.atanh +@op(torch.ops.aten.atanh) +def _aten_atanh(self): + return jnp.arctanh(self) + + +# aten.bitwise_not +@op(torch.ops.aten.bitwise_not) +def _aten_bitwise_not(self): + return ~self + + +# aten.embedding_dense_backward + + +# aten.sum +@op(torch.ops.aten.sum) +def _aten_sum(self, dim=None, keepdim=False, dtype=None): + if not dim: + dim = None + return jnp.sum(self, axis=dim, keepdims=keepdim, dtype=dtype) + + +# aten.sqrt +@op(torch.ops.aten.sqrt) +def _aten_sqrt(self): + return jnp.sqrt(self) + + +@op(torch.ops.aten.tan) +def _aten_tanh(self): + return jnp.tan(self) + + +# aten.tanh +@op(torch.ops.aten.tanh) +def _aten_tanh(self): + return jnp.tanh(self) + + +# aten.ceil +@op(torch.ops.aten.ceil) +def _aten_ceil(self): + return jnp.ceil(self) + + +# aten.asin +@op(torch.ops.aten.asin) +def _aten_asin(self): + return jnp.arcsin(self) + + +# aten.minimum +@op(torch.ops.aten.minimum) +def _aten_minimum(self, other): + return jnp.minimum(self, other) + + +# aten.max_pool2d_backward + + +def _scatter_index(dim, index): + """Returns a tuple of indexes; + + The first is to select in input (to modify), + the second is to select from the values. + """ + index_shape = list(index.shape) + input_indexes = [] + source_indexes = [] + for i in range(len(index_shape)): + source_indexes.append(slice(0, index_shape[i])) + if i == dim: + input_indexes.append(index) + else: + target_shape = [1] * len(index_shape) + target_shape[i] = index_shape[i] + input_indexes.append( + jnp.broadcast_to( + jnp.arange(index_shape[i]).reshape(target_shape), index_shape + ) + ) + return tuple(input_indexes), tuple(source_indexes) + + +# aten.scatter_add +@op(torch.ops.aten.scatter_add) +def _aten_scatter_add(input, dim, index, src): + """JAX implementation of scatter, mimicking torch.scatter behavior""" + + input_indexes, source_indexes = _scatter_index(dim, index) + return input.at[input_indexes].add(src[source_indexes]) + + +# aten.logical_not + + +# aten.sign +@op(torch.ops.aten.sign) +def _aten_sign(x): + return jnp.sign(x) + + +# aten.sigmoid +@op(torch.ops.aten.sigmoid) +def _aten_sigmoid(x): + if x.dtype in (jnp.int32, jnp.int64): + x = x.astype(jnp.float32) + return jax.nn.sigmoid(x) + + +# implement aten.asinh in jax +@op(torch.ops.aten.asinh) +def _aten_asinh(self): + return jnp.arcsinh(self) + + +# aten.atan +@op(torch.ops.aten.atan) +def _aten_atan(self): + return jnp.arctan(self) + + +# aten.scatter_reduce +@op(torch.ops.aten.scatter_reduce) +def _aten_scatter_reduce(input, dim, index, src, reduce, *, include_self=True): + input_indexes, source_indexes = _scatter_index(dim, index) + if reduce == "sum": + return input.at[input_indexes].add(src[source_indexes]) + elif reduce == "prod": + return input.at[input_indexes].multiply(src[source_indexes]) + elif reduce == "mean": + return input.at[input_indexes].add(src[source_indexes]) + elif reduce == "amax": + return input.at[input_indexes].max(src[source_indexes]) + elif reduce == "amin": + return input.at[input_indexes].min(src[source_indexes]) + else: + raise RuntimeError("Unknow reduction type: ", reduce) + + +# aten.acos +@op(torch.ops.aten.acos) +def _aten_acos(self): + return jnp.arccos(self) + + +# aten.sym_storage_offset +# aten.native_layer_norm_backward +# aten.max_pool3d_with_indices + + +# aten.gt +@op(torch.ops.aten.gt) +def _aten_gt(self, other): + return self > other + + +# aten.pixel_shuffle +@op(torch.ops.aten.pixel_shuffle) +def _aten_pixel_shuffle(x, upscale_factor): + """PixelShuffle implementation in JAX. + + Args: + x: Input tensor. Typically a feature map. + upscale_factor: Integer by which to upscale the spatial dimensions. + + Returns: + Tensor after PixelShuffle operation. + """ + + batch_size, channels, height, width = x.shape + + if channels % (upscale_factor**2) != 0: + raise ValueError( + "Number of channels must be divisible by the square of the upscale factor." + ) + + new_channels = channels // (upscale_factor**2) + new_height = height * upscale_factor + new_width = width * upscale_factor + + x = x.reshape( + batch_size, new_channels, upscale_factor, upscale_factor, height, width + ) + x = jnp.transpose( + x, (0, 1, 2, 4, 3, 5) + ) # Move channels to spatial dimensions + x = x.reshape(batch_size, new_channels, new_height, new_width) + + return x + + +# aten.sym_stride +# aten.lt +@op(torch.ops.aten.lt) +def _aten_lt(self, other): + return self < other + + +def pool(inputs, init, reduce_fn, window_shape, strides, padding): + """Helper function to define pooling functions. + + Pooling functions are implemented using the ReduceWindow XLA op. + NOTE: Be aware that pooling is not generally differentiable. + That means providing a reduce_fn that is differentiable does not imply that + pool is differentiable. + + Args: + inputs: input data with dimensions (batch, window dims..., features). + init: the initial value for the reduction + reduce_fn: a reduce function of the form ``(T, T) -> T``. + window_shape: a shape tuple defining the window to reduce over. + strides: a sequence of ``n`` integers, representing the inter-window + strides (default: ``(1, ..., 1)``). + padding: either the string ``'SAME'``, the string ``'VALID'``, or a sequence + of ``n`` ``(low, high)`` integer pairs that give the padding to apply before + and after each spatial dimension. + Returns: + The output of the reduction for each window slice. + """ + num_batch_dims = inputs.ndim - (len(window_shape) + 1) + strides = strides or (1,) * len(window_shape) + assert len(window_shape) == len( + strides + ), f"len({window_shape}) must equal len({strides})" + strides = (1,) * (1 + num_batch_dims) + strides + dims = (1,) * (1 + num_batch_dims) + window_shape + + is_single_input = False + if num_batch_dims == 0: + # add singleton batch dimension because lax.reduce_window always + # needs a batch dimension. + inputs = inputs[None] + strides = (1,) + strides + dims = (1,) + dims + is_single_input = True + + assert inputs.ndim == len(dims), f"len({inputs.shape}) != len({dims})" + if not isinstance(padding, str): + padding = tuple(map(tuple, padding)) + assert len(padding) == len(window_shape), ( + f"padding {padding} must specify pads for same number of dims as " + f"window_shape {window_shape}" + ) + assert all( + [len(x) == 2 for x in padding] + ), f"each entry in padding {padding} must be length 2" + padding = ((0, 0), (0, 0)) + padding + y = jax.lax.reduce_window(inputs, init, reduce_fn, dims, strides, padding) + if is_single_input: + y = jnp.squeeze(y, axis=0) + return y + + +@op(torch.ops.aten._adaptive_avg_pool3d) +def _aten_adaptive_avg_pool3d(x, output_shape): + return _aten_adaptive_avg_pool(x, output_shape, 3) + + +@op(torch.ops.aten._adaptive_avg_pool2d) +def _aten_adaptive_avg_pool3d(x, output_shape): + return _aten_adaptive_avg_pool(x, output_shape, 2) + + +def _aten_adaptive_avg_pool(x, output_shape, pool_dim): + def adaptive_kernel_size(input_shape, output_shape): + sizes = [1, 1] + spatial_dim_off = len(input_shape) - pool_dim + for spatial_dim in range(pool_dim): + sizes.append( + input_shape[spatial_dim_off + spatial_dim] // output_shape[spatial_dim] + ) + return tuple(sizes) + + kernel_sizes = adaptive_kernel_size(x.shape, output_shape) + y = pool(x, 0.0, jax.lax.add, kernel_sizes, kernel_sizes, padding="VALID") + + div_shape = list(x.shape) + num_batch_dims = len(x.shape) - pool_dim - 1 + div_shape[num_batch_dims] = 1 + div_shape = tuple(div_shape) + if len(div_shape) - 2 == len(kernel_sizes): + div_shape = (1,) + div_shape[1:] + y = y / pool( + jnp.ones(div_shape), 0.0, jax.lax.add, kernel_sizes, kernel_sizes, "VALID" + ) + return y + + +# aten.avg_pool2d +@op(torch.ops.aten.avg_pool2d) +@op(torch.ops.aten.avg_pool3d) +def _aten_avg_pool( + inputs, + kernel_size, + strides=None, + padding=0, + ceil_mode=False, + count_include_pad=True, + divisor_override=None, +): + num_batch_dims = len(inputs.shape) - len(kernel_size) - 1 + kernel_size = tuple(kernel_size) + strides = tuple(strides) + if isinstance(padding, int): + padding = tuple((padding, padding) for _ in range(len(kernel_size))) + elif isinstance(padding, list): + padding = tuple((p, p) for p in padding) + + y = pool(inputs, 0.0, jax.lax.add, kernel_size, strides, padding) + if count_include_pad: + y = y / np.prod(kernel_size) + else: + div_shape = list(inputs.shape) + div_shape[num_batch_dims] = 1 + div_shape = tuple(div_shape) + if len(div_shape) - 2 == len(kernel_size): + div_shape = (1,) + div_shape[1:] + y = y / pool( + jnp.ones(div_shape), 0.0, jax.lax.add, kernel_size, strides, padding + ) + return y + + +# aten.sym_numel +# aten.reciprocal +@op(torch.ops.aten.reciprocal) +def _aten_reciprocal(a): + return 1 / a + + +# aten.scatter +@op(torch.ops.aten.select_scatter) +def _aten_select_scatter(input, src, dim, index): + input_indexes = [] + for x in range(len(input.shape)): + if x == dim: + input_indexes.append(index) + else: + input_indexes.append(slice(None, None, None)) + return input.at[tuple(input_indexes)].set(src) + + +@op(torch.ops.aten.scatter.src) +def _aten_scatter_src(input, dim, index, src, reduce=None): + input_index, source_indexes = _scatter_index(dim, index) + return input.at[input_index].set(src[source_indexes]) + + +@op(torch.ops.aten.scatter.value) +def _aten_scatter(input, dim, index, src, reduce=None): + input_index, source_indexes = _scatter_index(dim, index) + return input.at[input_index].set(src) + + +# aten.acosh +@op(torch.ops.aten.acosh) +def _aten_acosh(self): + return jnp.arccosh(self) + + +# aten.avg_pool2d_backward +# aten.col2im +# aten.avg_pool3d +# aten.round +@op(torch.ops.aten.round) +def _aten_round(input, decimals=0): + return jnp.round(input, decimals) + + +# aten.max +@op(torch.ops.aten.max) +def _aten_max(self, dim=None, keepdim=False): + return jnp.max(self, axis=dim, keepdims=keepdim), jnp.argmax( + self, axis=dim, keepdims=keepdim + ) + + +# aten.maximum +@op(torch.ops.aten.maximum) +def _aten_maximum(self, other): + return jnp.maximum(self, other) + + +# aten.abs +@op(torch.ops.aten.abs) +def _aten_abs(self): + return jnp.abs(self) + + +# generate aten.amax only +@op(torch.ops.aten.amax) +def _aten_amax(self, dim=None, keepdim=False): + return _with_reduction_scalar(jnp.amax, self, dim, keepdim) + + +def _with_reduction_scalar(jax_func, self, dim, keepdim): + expanded = False + if self.ndim == 0: + # for self of rank 0: + # torch.any(x, 0), torch.any(x, -1) works; + # torch.any(x, 1) throws out of bounds, so it's + # behavior is the same as a jnp array of rank 1 + expanded = True + self = jnp.expand_dims(self, 0) + res = jax_func(self, axis=dim, keepdims=keepdim) + if expanded: + res = res.squeeze() + return res + + +# aten.any +@op(torch.ops.aten.any) +def _aten_any(self, dim=None, keepdim=False): + return _with_reduction_scalar(jnp.any, self, dim, keepdim) + + +# aten.arange +@op(torch.ops.aten.arange.start_step) +@op(torch.ops.aten.arange.start) +@op(torch.ops.aten.arange.default) +def _aten_arange( + start, + end=None, + step=1, + *, + dtype=None, + layout=None, + requires_grad=False, + device=None, + pin_memory=False, +): + if end is None: + end = start + start = 0 + if dtype: + dtype = tensor.t2j_dtype(dtype) + return jnp.arange( + start, + end, + step, + dtype=dtype, + ) + + +# aten.argmax +@op(torch.ops.aten.argmax) +def _aten_argmax(self, dim=None, keepdim=False): + return _with_reduction_scalar(jnp.argmax, self, dim, keepdim) + + +# aten.as_strided +@op(torch.ops.aten.as_strided) +@op(torch.ops.aten.as_strided_copy) +def _aten_as_strided(x, sizes, strides, storage_offset=None): + ind = jnp.zeros(sizes, dtype=jnp.int32) + + for i, (size, stride) in enumerate(zip(sizes, strides)): + result_shape = (1,) * i + (size,) + (1,) * (len(sizes) - i - 1) + indexes = (jnp.arange(size) * stride).reshape(result_shape) + ind += indexes + + return jnp.ravel(x)[ind] + + +# aten.atan2 +@op(torch.ops.aten.atan2) +def _aten_atan2(self, other): + return jnp.arctan2(self, other) + + +# aten.bitwise_and +@op(torch.ops.aten.bitwise_and) +def _aten_bitwise_and(self, other): + return self & other + + +# aten.bitwise_or +@op(torch.ops.aten.bitwise_or) +def _aten_bitwise_or(self, other): + return self | other + + +# aten.bitwise_xor +@op(torch.ops.aten.bitwise_xor) +def _aten_bitwise_xor(self, other): + return self ^ other + + +# aten.clamp +@op(torch.ops.aten.clamp.default) +@op(torch.ops.aten.clamp.Tensor) +def _aten_clamp(self, min=None, max=None): + return jnp.clip(self, min, max) + + +# aten.constant_pad_nd +@op(torch.ops.aten.constant_pad_nd) +def _aten_constant_pad_nd(input, padding, value=0): + # NOTE: Torch padding is flat and reversed: (1, 1, 2, 2) + # means last dim get padded 1 in front and 1 in back; + # and second last dim get padded 2 in front and 2 in back. + # Jax padding tuple of 2-tuple: the same padding is + # [(0, 0), ..., (2,2), (1,1)] + m = len(padding) + rev_padding = [(padding[i - 1], padding[i]) for i in range(m - 1, 0, -2)] + pad_dim = tuple(([(0, 0)] * (len(input.shape) - m // 2)) + rev_padding) + return jnp.pad(input, pad_dim, mode="constant", constant_values=value) + + +# aten.convolution_backward +@op(torch.ops.aten.copy) +@op(torch.ops.aten.lift_fresh_copy) +def _aten_copy(x): + return jnp.copy(x) + + +@op(torch.ops.aten._cdist_forward) +def _aten_cdist_forward(x1, x2, p, compute_mode=""): + # x1 is B x P x M + # x2 is B x Q x M + # res is B x P x Q + x1 = jnp.expand_dims(x1, len(x1.shape) - 1) + x2 = jnp.expand_dims(x2, len(x2.shape) - 2) + return jnp.linalg.norm(x1 - x2, ord=p, axis=-1) + + +@op(torch.ops.aten._pdist_forward) +def _aten__pdist_forward(x, p): + pairwise_dists = _aten_cdist_forward(x, x, p) + condensed_dists = pairwise_dists[ + jnp.triu_indices(pairwise_dists.shape[0], k=1) + ] + return condensed_dists + + +# aten.cos +@op(torch.ops.aten.cos) +def _aten_cos(input): + return jnp.cos(input) + + +# aten.cosh +@op(torch.ops.aten.cosh) +def _aten_cosh(input): + return jnp.cosh(input) + + +# aten.diagonal +@op(torch.ops.aten.diagonal) +def _aten_diagonal(input, offset=0, dim1=0, dim2=1): + return jnp.diagonal(input, offset, dim1, dim2) + + +# aten.empty_strided +# aten.eq +@op(torch.ops.aten.eq) +def _aten_eq(input1, input2): + return input1 == input2 + + +# aten.erf +@op(torch.ops.aten.erf) +def _aten_erf(x): + if x.dtype in (jnp.int32, jnp.int64): + x = x.astype(jnp.float32) + return jax.lax.erf(x) + + +# aten.exp +@op(torch.ops.aten.exp) +def _aten_exp(input): + return jnp.exp(input) + + +# aten.expm1 +@op(torch.ops.aten.expm1) +def _aten_expm1(input): + return jnp.expm1(input) + + +# aten.fill +@op(torch.ops.aten.fill) +@op(torch.ops.aten.full_like) +def _aten_fill(x, value, dtype=None, pin_memory=None, memory_format=None): + if dtype is None: + dtype = x.dtype + else: + dtype = tensor.t2j_dtype(dtype) + return jnp.full(x.shape, value, dtype) + + +# aten.flip +@op(torch.ops.aten.flip) +def _aten_flip(input, dims): + if dims is not None: + return jnp.flip(input, tuple(dims)) + else: + return jnp.flip(input) + + +# aten.floor +@op(torch.ops.aten.floor) +def _aten_floor(input): + return jnp.floor(input) + + +# aten.fmod +@op(torch.ops.aten.fmod) +def _aten_fmod(input, other): + return input - other * _aten_div(input, other, "trunc") + + +# aten.gather +@op(torch.ops.aten.gather) +def _aten_gather(input, dim, index): + input_indexes, source_indexes = _scatter_index(dim, index) + return input[input_indexes] + + +# aten.ge +@op(torch.ops.aten.ge) +def _aten_ge(self, other): + return self >= other + + +@op(torch.ops.aten.glu) +@op(torch.ops.aten.glu.default) +def _aten_glu(x, dim=-1): + return jax.nn.glu(x, dim) + + +# aten.hardtanh +@op(torch.ops.aten.hardtanh) +def _aten_hardtanh(input, min_val=-1.0, max_val=1.0, inplace=False): + return jnp.clip(input, min_val, max_val) + + +# aten.isinf +@op(torch.ops.aten.isinf) +def _aten_isinf(input): + return jnp.isinf(input) + + +# aten.isnan +@op(torch.ops.aten.isnan) +def _aten_isnan(input): + return jnp.isnan(input) + + +@op(torch.ops.aten.le) +def _aten_le(self, other): + return self <= other + + +# aten.leaky_relu +@op(torch.ops.aten.leaky_relu) +def _aten_leaky_relu(x, negative_slope): + return jax.nn.leaky_relu(x, negative_slope) + + +# aten.log +@op(torch.ops.aten.log) +def _aten_log(x): + return jnp.log(x) + + +# aten.log10 +@op(torch.ops.aten.log10) +def _aten_log10(x): + return jnp.log10(x) + + +# aten.log1p +@op(torch.ops.aten.log1p) +def _aten_log1p(x): + return jnp.log1p(x) + + +# aten.log2 +@op(torch.ops.aten.log2) +def _aten_log2(x): + return jnp.log2(x) + + +# aten.logical_and +@op(torch.ops.aten.logical_and) +def _aten_logical_and(self, other): + return jnp.logical_and(self, other) + + +# aten.logical_or +@op(torch.ops.aten.logical_or) +def _aten_logical_or(self, other): + return jnp.logical_or(self, other) + + +# aten.logical_not +@op(torch.ops.aten.logical_not) +def _aten_logical_not(self): + return jnp.logical_not(self) + + +# aten.log_softmax +@op(torch.ops.aten._log_softmax) +def _aten_log_softmax(self, axis=-1, half_to_float=False): + return jax.nn.log_softmax(self, axis) + + +# aten.max_pool3d_backward +# aten.logical_xor +@op(torch.ops.aten.logical_xor) +def _aten_logical_xor(self, other): + return jnp.logical_xor(self, other) + + +# aten.max_pool2d_with_indices_backward +# aten.native_dropout +# aten.native_group_norm_backward +# aten.neg +@op(torch.ops.aten.neg) +def _aten_neg(x): + return -1 * x + + +# aten.nonzero +@op(torch.ops.aten.nonzero) +def _aten_nonzero(x): + index_tuple = jnp.nonzero(x) + index_tuple = [jnp.expand_dims(p, -1) for p in index_tuple] + return jnp.concatenate(index_tuple, axis=-1) + + +# aten.prod + + +@op(torch.ops.aten.prod) +def _aten_prod(self, dim=None, keepdim=False): + return jnp.prod(self, axis=dim, keepdims=keepdim) + + +# aten.randperm + + +# aten.reflection_pad3d + + +# aten.remainder +@op(torch.ops.aten.remainder) +def _aten_remainder(inputs, other): + return inputs % other + + +# aten.repeat +@op(torch.ops.aten.repeat) +def _aten_repeat(x, reps): + return jnp.tile(x, reps) + + +# aten.replication_pad2d +# aten.replication_pad3d +# aten.roll +@op(torch.ops.aten.roll) +def _aten_roll(input, shifts, dims=None): + return jnp.roll(input, shifts, dims) + + +# aten.scalar_tensor +# aten.slice_scatter +@op(torch.ops.aten.slice_scatter) +def _aten_slice_scatter(input, src, dim=0, start=None, end=None, step=1): + input_index = [] + for x in range(len(input.shape)): + if x == dim: + input_index.append(slice(start, end, step)) + else: + input_index.append(slice(None, None, None)) + return input.at[tuple(input_index)].set(src) + + +# aten.sort +# torch.sort(input, dim=-1, descending=False, stable=False, *, out=None) +@op(torch.ops.aten.sort) +def _aten_sort(a, dim=-1, descending=False, stable=False): + return ( + jnp.sort(a, axis=dim, stable=stable, descending=descending), + jnp.argsort(a, axis=dim, stable=stable, descending=descending), + ) + + +# aten.sym_size + + +# aten.topk +@op(torch.ops.aten.topk) +def _aten_topk(input, k, dim=None, largest=True, sorted=True, *, out=None): + """JAX top-k implementation using jax.lax.top_k for improved efficiency. + + Args: + input: The input JAX array. + k: The number of top elements to return. + dim: The dimension along which to find the top-k. If None, operates on the + flattened array. + largest: If True, returns the largest k elements. Otherwise, smallest k. + sorted: If True, returns the elements in sorted order. + + Returns: + A tuple (values, indices) containing: + - values: The top k values. + - indices: The indices of the top k values in the original array. + """ + if dim is None: + # last dim is chosen + dim = input.ndim - 1 + + if dim < 0: + dim = dim + input.ndim + + if not largest: + input = -input # Find top-k of negated input if we want the smallest + + transpose_shape = None + if dim != -1 and dim != len(input.shape) - 1: + transpose_shape = list(range(len(input.shape))) + transpose_shape[dim], transpose_shape[-1] = ( + transpose_shape[-1], + transpose_shape[dim], + ) + input = jnp.transpose(input, transpose_shape) + + values, indices = jax.lax.top_k(input, k) + + if sorted: + values = jnp.sort(values, descending=True) + indices = jnp.take_along_axis( + indices, jnp.argsort(values, axis=-1, descending=True), axis=-1 + ) + + if not largest: + values = -values # Negate values back if we found smallest + + if transpose_shape is not None: + values = jnp.transpose(values, transpose_shape) + indices = jnp.transpose(indices, transpose_shape) + + return values, indices + + +# aten.trunc +@op(torch.ops.aten.trunc) +def _aten_trunc(a): + return jnp.trunc(a) + + +@op(torch.ops.aten.unbind) +@op(torch.ops.aten.unbind_copy) +def _aten_unbind(a, dim=0): + return tuple( + _aten_squeeze_dim(jax.lax.index_in_dim(a, i, axis=dim), dim) + for i in range(a.shape[dim]) + ) + + +# NOTE: skip aten.upsample_nearest2d and aten.upsample_bilinear2d +# despite those being core aten ops, they also have decompositions. +# here we are using torch decompositions. + + +# aten.where +@op(torch.ops.aten.where.self) +@op(torch.ops.aten.where.ScalarSelf) +@op(torch.ops.aten.where.ScalarOther) +def _aten_where(condition, x, y): + return jnp.where(condition, x, y) + + +# aten.to.dtype +# Tensor(a) self, ScalarType dtype, bool non_blocking=False, bool copy=False, MemoryFormat? memory_format=None +@op(torch.ops.aten.to.dtype) +def _aten_to_dtype( + a, dtype, non_blocking=False, copy=False, memory_format=None +): + if dtype: + jaxdtype = tensor.t2j_dtype(dtype) + return a.astype(jaxdtype) + + +# aten.to.device + + +# Tensor self, int[1]? dim=None, *, Scalar? correction=None, bool keepdim=False +@op(torch.ops.aten.var_mean.correction) +def _aten_var_mean_correction(self, dim=None, correction=None, keepdim=False): + return ( + jnp.var(self, axis=dim, ddof=correction, keepdims=keepdim), + jnp.mean(self, dim, keepdims=keepdim), + ) + + +@op(torch.ops.aten.scalar_tensor) +def _aten_scalar_tensor( + s, dtype=None, layout=None, device=None, pin_memory=None +): + if dtype is not None: + dtype = tensor.t2j_dtype(dtype) + return jnp.array(s, dtype=dtype) + return jnp.array(s) + + +@op(torch.ops.aten.to.device) +def _aten_to_device(x, device, dtype): + return x + + +@op(torch.ops.aten.max_pool2d_with_indices_backward) +def max_pool2d_with_indices_backward_custom( + grad_output, self, kernel_size, stride, padding, dilation, ceil_mode, indices +): + """ + Approximates the gradient calculation of PyTorch's max_pool2d_with_indices_backward. + + Args: + grad_output: The gradient tensor from the preceding layer. + self: The input tensor on which the original max pooling was performed. + kernel_size: The size of the pooling window. + stride: The stride of the pooling window. + padding: The padding applied during max pooling. + dilation: The dilation factor for the pooling operation. + ceil_mode: Whether to use ceil or floor when calculating output shapes. + indices: The indices of the maximum values, as produced by max_pool2d_with_indices. + + Returns: + The calculated gradient with respect to the input (grad_input). + """ + + kH, kW = kernel_size + dH, dW = stride + padH, padW = padding + dilH, dilW = dilation + + # Calculate output shape (may need adjustment based on ceil_mode) + out_shape = jnp.array(self.shape) + grad_input = jnp.zeros_like(self) + + # Iterate over the flattened input and output tensors + for i, idx in enumerate(indices.flatten()): + # Calculate input coordinates corresponding to the maximum value + out_y, out_x = i // grad_output.shape[3], i % grad_output.shape[3] + in_y = out_y * dH - padH + out_y * (dilH - 1) + in_x = out_x * dW - padW + out_x * (dilW - 1) + + # Scatter the gradient to the appropriate input locations (handling potential overlaps) + for y in range(in_y, in_y + kH): + for x in range(in_x, in_x + kW): + if 0 <= y < grad_input.shape[2] and 0 <= x < grad_input.shape[3]: + grad_input = grad_input.at[y, x].add(grad_output.flatten()[i]) + + return grad_input + + +@op(torch.ops.aten._local_scalar_dense) +def _aten_local_scalar_dense(x): + return x.item() + + +@op(torch.ops.aten.tensor_split.sections) +def _aten_tensor_split(ary, indices_or_sections, axis=0): + return jnp.array_split(ary, indices_or_sections, axis) + + +@op(torch.ops.aten.randn, needs_env=True) +@op_base.convert_dtype() +def _randn( + *size, + generator=None, + out=None, + dtype=None, + layout=torch.strided, + device=None, + requires_grad=False, + pin_memory=False, + env=None, +): + shape = size + if len(shape) == 1 and isinstance(shape[0], (list, tuple)): + shape = shape[0] + key = env.get_and_rotate_prng_key() + res = jax.random.normal(key, shape) + if dtype is not None: + res = res.astype(dtype) + return res + + +@op(torch.ops.aten.rand, needs_env=True) +@op_base.convert_dtype() +def _rand( + *size, + generator=None, + out=None, + dtype=None, + layout=torch.strided, + device=None, + requires_grad=False, + pin_memory=False, + env=None, +): + shape = size + if len(shape) == 1 and isinstance(shape[0], (list, tuple)): + shape = shape[0] + key = env.get_and_rotate_prng_key() + res = jax.random.uniform(key, shape) + if dtype is not None: + res = res.astype(dtype) + return res + + +@op(torch.ops.aten.scalar_tensor.default) +def _aten_scalar_tensor(val, **kwargs): + p = torch.ops.aten.scalar_tensor(val) + return tensor.t2j(p) + + +@op(torch.ops.aten.to.device) +def _aten_to_device(x, device, dtype): + return x + + +@op(torch.ops.aten.max_pool2d_with_indices_backward) +def max_pool2d_with_indices_backward_custom( + grad_output, self, kernel_size, stride, padding, dilation, ceil_mode, indices +): + """ + Approximates the gradient calculation of PyTorch's max_pool2d_with_indices_backward. + + Args: + grad_output: The gradient tensor from the preceding layer. + self: The input tensor on which the original max pooling was performed. + kernel_size: The size of the pooling window. + stride: The stride of the pooling window. + padding: The padding applied during max pooling. + dilation: The dilation factor for the pooling operation. + ceil_mode: Whether to use ceil or floor when calculating output shapes. + indices: The indices of the maximum values, as produced by max_pool2d_with_indices. + + Returns: + The calculated gradient with respect to the input (grad_input). + """ + + kH, kW = kernel_size + dH, dW = stride + padH, padW = padding + dilH, dilW = dilation + + # Calculate output shape (may need adjustment based on ceil_mode) + out_shape = jnp.array(self.shape) + grad_input = jnp.zeros_like(self) + + # Iterate over the flattened input and output tensors + for i, idx in enumerate(indices.flatten()): + # Calculate input coordinates corresponding to the maximum value + out_y, out_x = i // grad_output.shape[3], i % grad_output.shape[3] + in_y = out_y * dH - padH + out_y * (dilH - 1) + in_x = out_x * dW - padW + out_x * (dilW - 1) + + # Scatter the gradient to the appropriate input locations (handling potential overlaps) + for y in range(in_y, in_y + kH): + for x in range(in_x, in_x + kW): + if 0 <= y < grad_input.shape[2] and 0 <= x < grad_input.shape[3]: + grad_input = grad_input.at[y, x].add(grad_output.flatten()[i]) + + return grad_input + + +@op(torch.ops.aten._local_scalar_dense) +def _aten_local_scalar_dense(x): + return x.item() + + +@op(torch.ops.aten.tensor_split.sections) +def _aten_tensor_split(ary, indices_or_sections, axis=0): + return jnp.array_split(ary, indices_or_sections, axis) + + +@op(torch.ops.aten.outer) +def _aten_outer(a, b): + return jnp.outer(a, b) + + +@op(torch.ops.aten.allclose) +def _aten_allclose(input, other, rtol=1e-05, atol=1e-08, equal_nan=False): + return jnp.allclose(input, other, rtol, atol, equal_nan) + +@op(torch.ops.aten.native_batch_norm) +def _aten_native_batch_norm(input, weight, bias, running_mean, running_var, training=False, momentum=0.1, eps=1e-5): + + if running_mean is None: + running_mean = jnp.zeros(input.shape[1]) # Initialize running mean if None + if running_var is None: + running_var = jnp.ones(input.shape[1]) # Initialize running variance if None + + if training: + return torch.ops.aten._native_batch_norm_legit(input, weight, bias, running_mean, running_var, training, momentum, eps) + else: + return torch.ops.aten._native_batch_norm_legit_no_training(input, weight, bias, running_mean, running_var, momentum, eps) diff --git a/experimental/torch_xla2/torch_xla2/ops/jtorch.py b/experimental/torch_xla2/torch_xla2/ops/jtorch.py index e69de29bb2d..6d7003b936e 100644 --- a/experimental/torch_xla2/torch_xla2/ops/jtorch.py +++ b/experimental/torch_xla2/torch_xla2/ops/jtorch.py @@ -0,0 +1,88 @@ +"""Tensor constructor overrides""" +import functools +from typing import Optional, Sequence + +import jax +import torch +import jax.numpy as jnp +from torch_xla2 import tensor +from torch_xla2.ops.ops_registry import register_torch_function_op +from torch_xla2.ops import op_base + + +def register_function(torch_func, **kwargs): + return functools.partial(register_torch_function_op, torch_func, **kwargs) + + +@register_function(torch.tensor) +@op_base.convert_dtype(use_default_dtype=False) # Attempt to infer type from elements +def _tensor(data, *, dtype=None, **kwargs): + python_types_to_torch_types = { + bool: jnp.bool, + int: jnp.int64, + float: jnp.float32, + complex: jnp.complex64, + } + if not dtype: + leaves = jax.tree_util.tree_leaves(data) + if len(leaves) > 0: + dtype = python_types_to_torch_types.get(type(leaves[0])) + + return jnp.array( + data, dtype=dtype or tensor.t2j_dtype(torch.get_default_dtype())) + + +@register_function(torch.ones) +@op_base.convert_dtype() +def _ones(*size: int, dtype=None, **kwargs): + return jnp.ones(size, dtype) + + +@register_function(torch.zeros) +@op_base.convert_dtype() +def _zeros(*size: int, dtype=None, **kwargs): + return jnp.zeros(size, dtype) + + +@register_function(torch.eye) +@op_base.convert_dtype() +def _eye(n: int, m: Optional[int] = None, *, dtype=None, **kwargs): + return jnp.eye(n, m, dtype=dtype) + + +@register_function(torch.full) +@op_base.convert_dtype() +def _full(size: Sequence[int], fill_value, *, dtype=None, **kwargs): + # TODO: handle torch.Size + return jnp.full(size, fill_value, dtype=dtype) + + +@register_function(torch.allclose) +def _aten_allclose(input, other, rtol=1e-05, atol=1e-08, equal_nan=False): + return jnp.allclose(input, other, rtol, atol, equal_nan) + +@register_function(torch.angle) +def _torch_angle(input): + return jnp.angle(input) + + +@register_function(torch.argsort) +def _torch_argsort(input, dim=-1, descending=False, stable=False): + expanded = False + if input == 0: + # for self of rank 0: + # torch.any(x, 0), torch.any(x, -1) works; + # torch.any(x, 1) throws out of bounds, so it's + # behavior is the same as a jnp array of rank 1 + expanded = True + input = jnp.expand_dims(input, 0) + res = jnp.argsort(input, axis=dim, descending=descending, + stable=stable) + if expanded: + res = res.squeeze() + return res + +@register_function(torch.einsum) +def _einsum(equation, *operands): + assert isinstance(equation, str), 'Only accept str equation' + return jnp.einsum(equation, *operands) \ No newline at end of file diff --git a/experimental/torch_xla2/torch_xla2/ops/op_base.py b/experimental/torch_xla2/torch_xla2/ops/op_base.py index 62df160edc9..8076a11fb09 100644 --- a/experimental/torch_xla2/torch_xla2/ops/op_base.py +++ b/experimental/torch_xla2/torch_xla2/ops/op_base.py @@ -1,22 +1,15 @@ +import functools import torch -from torch_xla2 import extra +from torch_xla2 import interop, tensor +from torch_xla2 import types -class JaxOperator: - """This is a aten op backed by jax function.""" - - def __init__(self, jax_callable): - self.jax = jax_callable - - def __call__(self, *args, **kwargs): - # args are torch.Tensor - res = call_jax(self.jax, args, kwargs) - return res +from typing import Callable, Optional, ParamSpec, Sequence class BinaryOpWithPromotion: - def __init__(self, jax_callable): - self.jax = jax_callable + def __init__(self, inner): + self.inner = inner def _get_dtype(self, obj): if isinstance(obj, torch.Tensor): @@ -31,7 +24,7 @@ def _get_dtype(self, obj): def __call__(self, *args, **kwargs): # args are torch.Tensor - res = extra.torch_view(self.jax)(*args, **kwargs) + res = interop.torch_view(self.jax)(*args, **kwargs) dtype = torch.promote_types( self._get_dtype(args[0]), @@ -41,15 +34,6 @@ def __call__(self, *args, **kwargs): return res -class TorchLowering: - - def __init__(self, lowering): - self.lowering = lowering - - def __call__(self, *args, **kwargs): - return self.lowering(*args, **kwargs) - - class InplaceOp: def __init__(self, functional_op, position_to_mutate=0): @@ -58,7 +42,7 @@ def __init__(self, functional_op, position_to_mutate=0): def __call__(self, *args, **kwargs): to_mutate = args[0] - to_mutate._elem = self.functional(*args, **kwargs)._elem + to_mutate.copy_(self.functional(*args, **kwargs)) return to_mutate @@ -72,4 +56,29 @@ def __call__(self, *args, **kwargs): +P = ParamSpec('P') +def convert_dtype(use_default_dtype: bool = True): + """Converts `dtype` kwarg of function from torch to JAX. + + Args: + use_default_dtype: Whether to use torch default dtype if none is provided. + + Returns: + A decorator that wraps a JAX implementation of a torch function. + """ + + def decorator(func: types.TorchCallable): + + @functools.wraps(func) + def wrapper(*args: P.args, + dtype: Optional[torch.dtype] = None, + **kwargs: P.kwargs): + if not dtype and use_default_dtype: + dtype = torch.get_default_dtype() + jax_dtype = tensor.t2j_dtype(dtype) + + return func(*args, dtype=jax_dtype, **kwargs) + + return wrapper + return decorator diff --git a/experimental/torch_xla2/torch_xla2/ops/ops_registry.py b/experimental/torch_xla2/torch_xla2/ops/ops_registry.py new file mode 100644 index 00000000000..e75d1549456 --- /dev/null +++ b/experimental/torch_xla2/torch_xla2/ops/ops_registry.py @@ -0,0 +1,47 @@ +import dataclasses +from torch_xla2.types import JaxCallable, TorchCallable + +from typing import Union, Dict + + +@dataclasses.dataclass +class Operator: + torch_op: TorchCallable + func: Union[TorchCallable, JaxCallable] + is_jax_function: bool + is_user_defined: bool + needs_env: bool + + +all_aten_ops: Dict[TorchCallable, Operator] = {} +all_torch_functions: Dict[TorchCallable, Operator] = {} + + +def register_torch_dispatch_op( + aten_op, impl_callable, + is_jax_function=True, + is_user_defined=False, + needs_env=False, +): + op = Operator( + aten_op, impl_callable, + is_jax_function=is_jax_function, + is_user_defined=is_user_defined, + needs_env=needs_env) + all_aten_ops[aten_op] = op + return impl_callable + + +def register_torch_function_op( + torch_func, impl_callable, + is_jax_function=True, + is_user_defined=False, + needs_env=False, +): + op = Operator( + torch_func, impl_callable, + is_jax_function=is_jax_function, + is_user_defined=is_user_defined, + needs_env=needs_env) + all_torch_functions[torch_func] = op + return impl_callable \ No newline at end of file diff --git a/experimental/torch_xla2/torch_xla2/ops_registry.py b/experimental/torch_xla2/torch_xla2/ops_registry.py deleted file mode 100644 index f1d115864d3..00000000000 --- a/experimental/torch_xla2/torch_xla2/ops_registry.py +++ /dev/null @@ -1,74 +0,0 @@ -import torch -import torch._decomp as decomp -import torch_xla2.decompositions - -class LoweringRegistry: - - def __init__(self): - self.registered_ops = {} - self.decomps = {} - - def lookup(self, op_or_name): - candidate = self._lookup(op_or_name) - if candidate is None: - if isinstance(op_or_name, torch._ops.OpOverloadPacket): - candidate = self._lookup(op_or_name.default) - if isinstance(op_or_name, torch._ops.OpOverload): - candidate = self._lookup(op_or_name.overloadpacket) - return candidate - - def _lookup(self, op): - candidate = self.registered_ops.get(op) - if candidate is None: - candidate = self.decomp.get(op) - return candidate - - def register(self, op, lowering): - if isinstance(op, torch._ops.OpOverloadPacket): - if hasattr(op, 'default'): - self.registered_ops[op.default] = lowering - self.registered_ops[op] = lowering - - -lowerings = LoweringRegistry() -EXTRA_DECOMP = decomp.get_decompositions([ - torch.ops.aten.upsample_nearest2d, - torch.ops.aten._native_batch_norm_legit.no_stats, - torch.ops.aten._adaptive_avg_pool2d, - torch.ops.aten._adaptive_avg_pool3d, - torch.ops.aten.grid_sampler_2d, - torch.ops.aten.native_dropout, - torch.ops.aten.reflection_pad1d, - torch.ops.aten.reflection_pad2d, - torch.ops.aten.reflection_pad3d, - torch.ops.aten.replication_pad1d, - torch.ops.aten.replication_pad2d, - torch.ops.aten.replication_pad3d, -]) -CORE_ATEN_DECOMP = decomp.core_aten_decompositions() -CORE_ATEN_DECOMP.update(EXTRA_DECOMP) -lowerings.decomp = CORE_ATEN_DECOMP - - -def _all_core_ops(): - """Yields all core ops.""" - import torch._ops - - for k, v in torch.ops.aten.__dict__.items(): - if k.startswith('__'): - continue - if k.startswith('_'): - continue - if isinstance(v, torch._ops.OpOverloadPacket): - for overload in v.overloads(): - op = getattr(v, overload) - if torch.Tag.core in op.tags: - yield v - break - - -def print_missing_ops(): - core_aten = set(_all_core_ops()) - existing = set(lowerings.registered_ops.keys()) - for v in core_aten - existing: - print(v) diff --git a/experimental/torch_xla2/torch_xla2/tensor.py b/experimental/torch_xla2/torch_xla2/tensor.py index 98953a8b04c..460e06f8841 100644 --- a/experimental/torch_xla2/torch_xla2/tensor.py +++ b/experimental/torch_xla2/torch_xla2/tensor.py @@ -1,53 +1,16 @@ -import functools +import contextlib import jax from jax import dlpack as jaxdl import jax.numpy as jnp import numpy import torch import torch.func -import torch._decomp.decompositions -from torch_xla2 import ops_registry import torch.utils._python_dispatch as torch_dispatch import torch.utils._pytree as torch_pytree import torch.utils.dlpack as torchdl -from torch_xla2.ops import jaten -from torch._subclasses.fake_tensor import FakeTensorMode -fake_mode = FakeTensorMode() - - -class XLADispatchMode(torch_dispatch.TorchDispatchMode): - - def __torch_dispatch__(self, fn, types, args=(), kwargs=None): - if fn in constructors: - args, kwargs = unwrap((args, kwargs)) - res = constructors[fn](*args, **kwargs) - return wrap(res) - - return fn(*args, **kwargs) - - -def _aten_arange(start, - end, - *, - dtype=None, - layout=None, - requires_grad=False, - device=None, - pin_memory=False): - return jnp.arange(start, end, 1) - - -def _aten_scalar_tensor(val, **kwargs): - p = torch.ops.aten.scalar_tensor(val) - return wrap(t2j(p)) - - -constructors = { - torch.ops.aten.scalar_tensor.default: _aten_scalar_tensor, - torch.ops.aten.arange.default: functools.partial(_aten_arange, 0), - torch.ops.aten.arange.start: _aten_arange, -} +class OperatorNotFound(Exception): + pass def wrap(jaxarray): @@ -61,7 +24,9 @@ def unwrap(torchtensors): def t2j(t): if isinstance(t, XLATensor2): return t._elem + is_bool = False if t.dtype == torch.bool: + is_bool = True t = t.to(torch.int8) if not t.is_contiguous(): @@ -82,7 +47,7 @@ def t2j(t): if t.dtype == torch.bfloat16: res = res.astype(jnp.bfloat16) - if t.dtype == torch.bool: + if is_bool: res = res.astype(jnp.bool_) return res @@ -97,48 +62,59 @@ def j2t(x): res = res.to(torch.bool) return res +TORCH_DTYPE_TO_JAX = { + # NO_MAPPING : jnp.float0.dtype (signless scalar int), + torch.bool : jnp.bool_.dtype, + # NO_MAPPING : jnp.int4.dtype, + torch.int8 : jnp.int8.dtype, + torch.int16 : jnp.int16.dtype, + torch.int32 : jnp.int32.dtype, + torch.int64 : jnp.int64.dtype, + torch.long : jnp.int64.dtype, + # NO_MAPPING : jnp.uint4 + torch.uint8 : jnp.uint8.dtype, + torch.uint16 : jnp.uint16.dtype, + torch.uint32 : jnp.uint32.dtype, + torch.uint64 : jnp.uint64.dtype, + # NO_MAPPING : jnp.float8_e4m3b11fnuz.dtype, + torch.float8_e4m3fn : jnp.float8_e4m3fn.dtype, + # NO_MAPPING : jnp.float8_e4m3fnuz.dtype, + torch.float8_e5m2 : jnp.float8_e5m2.dtype, + # NO_MAPPING : jnp.float8_e5m2fnuz.dtype, + torch.bfloat16 : jnp.bfloat16.dtype, + torch.half : jnp.float16.dtype, + torch.float16 : jnp.float16.dtype, + torch.float32 : jnp.float32.dtype, + torch.float64 : jnp.float64.dtype, + torch.double : jnp.double.dtype, + torch.complex64 : jnp.complex64.dtype, + torch.complex128 : jnp.complex128.dtype, + None : None, +} + +JAX_DTYPE_TO_TORCH = { + value: key for key, value in TORCH_DTYPE_TO_JAX.items() +} +# Add imprecise mappings for some JAX dtypes which don't have torch analogues +JAX_DTYPE_TO_TORCH[jnp.dtype('int4')] = torch.int8 +JAX_DTYPE_TO_TORCH[jnp.dtype('uint4')] = torch.uint8 def t2j_dtype(dtype): - return { - torch.float16: jnp.float16, - torch.bfloat16: jnp.bfloat16, - torch.half: jnp.float16, - torch.float32: jnp.float32, - torch.double: jnp.double, - torch.long: jnp.int64, - torch.int32: jnp.int32, - torch.int16: jnp.int16, - torch.int8: jnp.int8, - torch.uint8: jnp.uint8, - torch.bool: jnp.bool_, - torch.complex64: jnp.complex64, - torch.complex128: jnp.complex128, - }.get(dtype) + if dtype not in TORCH_DTYPE_TO_JAX: + raise RuntimeError(f'Attempting to convert unknown type: {dtype} to torch type,') + return TORCH_DTYPE_TO_JAX[dtype] def j2t_dtype(dtype): - return { - jnp.float16: torch.float16, - jnp.bfloat16: torch.bfloat16, - jnp.double: torch.double, - jnp.float32: torch.float32, - jnp.float16: torch.half, - jnp.int64: torch.long, - jnp.int32: torch.int32, - jnp.int16: torch.int16, - jnp.bool_: torch.bool, - jnp.complex64: torch.complex64, - }.get(dtype) - - -def move_to_device(t): - return XLATensor2(t2j(t)) + if dtype not in JAX_DTYPE_TO_TORCH: + raise RuntimeError(f'Attempting to convert unknown type: {dtype} to torch type,') + return JAX_DTYPE_TO_TORCH[dtype] class XLATensor2(torch.Tensor): @staticmethod - def __new__(cls, elem): + def __new__(cls, elem, env): dtype = j2t_dtype(elem.dtype) shape = list(elem.shape) for i, s in enumerate(shape): @@ -154,9 +130,10 @@ def __new__(cls, elem): requires_grad=False, ) - def __init__(self, elem: jax.Array): + def __init__(self, elem: jax.Array, env: 'Environment'): super().__init__() self._elem = elem + self._env = env def __str__(self): return "XLATensor2({} {})".format(str(type(self._elem)), str(self._elem)) @@ -178,7 +155,7 @@ def flatten(self, start_dim=0, end_dim=-1): new_shape = ( self._elem.shape[:start_dim] + (-1,) + self._elem.shape[end_dim:]) new_elem = jnp.reshape(self._elem, new_shape) - return XLATensor2(new_elem) + return XLATensor2(new_elem, self._env) # return torch.reshape(self, new_shape) def __setitem__(self, key, val): @@ -193,32 +170,17 @@ def type_as(self, other): @classmethod def __torch_dispatch__(cls, func, types, args=(), kwargs=None): - kwargs = kwargs or {} - with jax.named_scope(func.name()): - - if isinstance(func, torch._ops.OpOverloadPacket): - return func(*args, **kwargs) - - if func.name() == 'aten::copy_': - x, y = args - x._elem = y._elem - return - - if func.overloadpacket in jaten.all_ops: - return jaten.all_ops[func.overloadpacket](*args, **kwargs) - - lowering = ops_registry.lowerings.lookup(func) + env = None + for arg in torch_pytree.arg_tree_leaves(*args, **kwargs): + if isinstance(arg, XLATensor2): + env = arg._env + break - if lowering is None: - raise RuntimeError("No lowering found for", func.name()) - - with XLADispatchMode(): - res = lowering(*args, **kwargs) - debug_accuracy(func, args, kwargs, res) - return res + with env: + return func(*args, **(kwargs or {})) def detach(self): - return XLATensor2(jax.lax.stop_gradient(self.jax())) + return XLATensor2(jax.lax.stop_gradient(self.jax()), self._env) def numpy(self) -> numpy.ndarray: import numpy as np @@ -231,6 +193,20 @@ def jax(self) -> jax.Array: def torch(self) -> torch.Tensor: return j2t(self.jax()) + def to(self, *args, **kwargs): + if len(args) == 1: + if isinstance(args[0], torch.dtype): + return XLATensor2(self._elem.astype(t2j_dtype(args[0])), self._env) + if 'dtype' in kwargs: + dtype = kwargs['dtype'] + return XLATensor2(self._elem.astype(t2j_dtype(dtype)), self._env) + return self + + @property + def dtype(self): + return j2t_dtype(self._elem.dtype) + + # TODO: slice of slice should also be another slice class SliceView(XLATensor2): @@ -281,3 +257,159 @@ def debug_accuracy(func, args, kwargs, current_output): pdb.set_trace() return True + + +class XLAFunctionMode(torch.overrides.TorchFunctionMode): + """Context manager that dispatches torch function calls to JAX.""" + + def __init__(self, env): + self.env = env + + def __torch_function__(self, + func, + types, + args=(), + kwargs=None) -> torch.Tensor: + try: + return self.env.dispatch(func, types, args, kwargs) + except OperatorNotFound: + return func(*args, **(kwargs or {})) + + +class XLADispatchMode(torch_dispatch.TorchDispatchMode): + + def __init__(self, env): + self.env = env + + def __torch_dispatch__(self, func, types, args=(), kwargs=None): + if isinstance(func, torch._ops.OpOverloadPacket): + with self: + return func(*args, **kwargs) + if func.namespace != 'aten': + return func(*args, **kwargs) + return self.env.dispatch(func, types, args, kwargs) + +def _name_of_func(func): + if hasattr(func, 'name'): + return func.name() + return func.__name__ + + +class Environment(contextlib.ContextDecorator): + """This class holds a set of configurations and "globals" needed + + for executing torch program using jax. + Things included so far: + + op registry + PRNGKey + Configs + + Also helper functions to manipulate those. + """ + + _prng_key: jax.random.PRNGKey + + + def __init__(self, random_seed): + self._prng_key = jax.random.PRNGKey(random_seed) + self._function_mode = XLAFunctionMode(self) + self._dispatch_mode = XLADispatchMode(self) + + # name is torch callable + self._ops = {} + self.load_ops() + + def load_ops(self): + from torch_xla2.ops import jaten, jtorch, ops_registry + self._ops.update(ops_registry.all_aten_ops) + self._ops.update(ops_registry.all_torch_functions) + + decomps = torch._decomp.core_aten_decompositions() + from torch_xla2.decompositions import EXTRA_DECOMP + decomps.update(EXTRA_DECOMP) + for k, v in decomps.items(): + if k not in self._ops: + self._ops[k] = ops_registry.Operator( + k, + v, + is_jax_function=False, + is_user_defined=False, + needs_env=False + ) + + def get_and_rotate_prng_key(self): + self._prng_key, key = jax.random.split(self._prng_key) + return key + + def dispatch(self, func, types, args, kwargs): + with jax.named_scope(_name_of_func(func)): + kwargs = kwargs or {} + op = self._ops.get(func) + + if op is None and isinstance(func, torch._ops.OpOverloadPacket): + op = self._ops.get(func.default) + + if op is None and isinstance(func, torch._ops.OpOverload): + op = self._ops.get(func.overloadpacket) + + if op is None: + raise OperatorNotFound( + f'Operator with name {_name_of_func(func)} has no lowering') + + if op.is_jax_function: + args, kwargs = self.t2j_iso((args, kwargs)) + + if op.needs_env: + kwargs['env'] = self + + with self: + res = op.func(*args, **kwargs) + + if op.is_jax_function: + res = self.j2t_iso(res) + + #if self.config.debug_accuracy_for_each_op: + # debug_accuracy(func, args, kwargs, res) + return res + + def __enter__(self): + self._dispatch_mode.__enter__() + self._function_mode.__enter__() + return self + + def __exit__(self, *exc): + self._function_mode.__exit__(*exc) + self._dispatch_mode.__exit__(*exc) + + def _move_one_value(self, val): + if isinstance(val, torch.nn.Module): + state_dict = self.to_xla(val.state_dict()) + val.load_state_dict(state_dict, assign=True) + return val + if isinstance(val, XLATensor2): + return val + if isinstance(val, torch.Tensor): + return XLATensor2(t2j(val), self) + return val + + def to_xla(self, torchvalues): + # tensors are torch.Tensors (not XLATensor) + res = torch_pytree.tree_map( + self._move_one_value, + torchvalues) + return res + + def t2j_iso(self, torchtensors): + return torch_pytree.tree_map_only( + XLATensor2, lambda x: x.jax(), torchtensors) + + def j2t_iso(self, jaxarray): + return torch_pytree.tree_map_only( + jnp.ndarray, lambda x: XLATensor2(x, self), jaxarray) + + def j2t_copy(self, args): + pass + + def j2t_copy(self, args): + pass diff --git a/experimental/torch_xla2/torch_xla2/types.py b/experimental/torch_xla2/torch_xla2/types.py new file mode 100644 index 00000000000..f39d530c18d --- /dev/null +++ b/experimental/torch_xla2/torch_xla2/types.py @@ -0,0 +1,12 @@ +from typing import TypeAlias, Callable, ParamSpec, Any, Union +import torch +import jax +import jax.numpy as jnp + + +P = ParamSpec('P') + +TorchValue: TypeAlias = Union[torch.Tensor, torch.dtype, 'TorchCallable', Any] +TorchCallable: TypeAlias = Callable[P, TorchValue] +JaxValue: TypeAlias = Union[jax.Array, jnp.dtype, 'JaxCallable', Any] +JaxCallable: TypeAlias = Callable[P, JaxValue] \ No newline at end of file diff --git a/infra/ansible/config/env.yaml b/infra/ansible/config/env.yaml index 15e8dc79d6c..9e2fe7270cc 100644 --- a/infra/ansible/config/env.yaml +++ b/infra/ansible/config/env.yaml @@ -14,7 +14,7 @@ release_env: TPUVM_MODE: 1 cuda: - TF_CUDA_COMPUTE_CAPABILITIES: 7.0,7.5,8.0,9.0 + TF_CUDA_COMPUTE_CAPABILITIES: "{{ cuda_compute_capabilities }}" XLA_CUDA: 1 # Variables that will be passed to shell environment only for building PyTorch and XLA libs. @@ -22,7 +22,7 @@ build_env: common: LD_LIBRARY_PATH: "$LD_LIBRARY_PATH:/usr/local/lib" # Set explicitly to 0 as setup.py defaults this flag to true if unset. - BUILD_CPP_TESTS: 0 + BUILD_CPP_TESTS: "{{ build_cpp_tests }}" # Force GCC because clang/bazel has issues. CC: gcc-10 CXX: g++-10 @@ -31,9 +31,9 @@ build_env: PYTORCH_BUILD_VERSION: "{{ package_version }}" XLA_SANDBOX_BUILD: 1 BAZEL_REMOTE_CACHE: 1 - SILO_NAME: "cache-silo-{{ arch }}-{{ accelerator }}-{{ clang_version }}" + SILO_NAME: "cache-silo-{{ arch }}-{{ accelerator }}-{{ clang_version }}{{ cache_suffix }}" _GLIBCXX_USE_CXX11_ABI: 0 - GIT_VERSIONED_XLA_BUILD: "{{ nightly_release }}" + GIT_VERSIONED_XLA_BUILD: "{{ nightly_release or git_versioned_xla_build }}" amd64: ARCH: amd64 @@ -41,7 +41,7 @@ build_env: aarch64: cuda: - TF_CUDA_COMPUTE_CAPABILITIES: 7.0,7.5,8.0,9.0 + TF_CUDA_COMPUTE_CAPABILITIES: "{{ cuda_compute_capabilities }}" XLA_CUDA: 1 tpu: diff --git a/infra/ansible/config/vars.yaml b/infra/ansible/config/vars.yaml index 2347d066e84..e5851d0cc77 100644 --- a/infra/ansible/config/vars.yaml +++ b/infra/ansible/config/vars.yaml @@ -1,6 +1,8 @@ # Used for fetching cuda from the right repo, see apt.yaml. cuda_repo: debian11 cuda_version: "11.8" +# Determines supported GPUs. See https://developer.nvidia.com/cuda-gpus +cuda_compute_capabilities: 7.0,7.5,8.0,9.0 # Used for fetching clang from the right repo, see apt.yaml. llvm_debian_repo: bullseye clang_version: 17 @@ -10,3 +12,9 @@ package_version: 2.4.0 nightly_release: false # Whether to preinstall libtpu in the PyTorch/XLA wheel. Ignored for GPU build. bundle_libtpu: 1 +# Suffix for bazel remote cache key +cache_suffix: "" +# Whether to build C++ tests with `torch_xla` wheel +build_cpp_tests: 0 +# Whether to tag wheels with git hash, e.g. X.Y.Z+git123abc +git_versioned_xla_build: false diff --git a/infra/ansible/roles/build_srcs/tasks/main.yaml b/infra/ansible/roles/build_srcs/tasks/main.yaml index d945f150d38..da09a695453 100644 --- a/infra/ansible/roles/build_srcs/tasks/main.yaml +++ b/infra/ansible/roles/build_srcs/tasks/main.yaml @@ -1,3 +1,27 @@ +- name: Read PyTorch pin + ansible.builtin.command: cat {{ (src_root, 'pytorch/xla/.torch_pin') | path_join }} + register: torch_pin + # Pin may not exist + ignore_errors: true + +- name: Checkout PyTorch pin + # ansible.builtin.git wants to fetch the entire history, so check out the pin manually + ansible.builtin.shell: + cmd: | + set -xe + PIN="{{ torch_pin.stdout }}" + if [[ $PIN = \#* ]]; then + PRNUM="${PIN//[!0-9]/}" + git fetch origin "pull/$PRNUM/head" + else + git fetch origin {{ torch_pin.stdout }} + fi + git checkout --recurse-submodules FETCH_HEAD + chdir: "{{ (src_root, 'pytorch') | path_join }}" + args: + executable: /bin/bash + when: torch_pin is succeeded + - name: Build PyTorch ansible.builtin.command: cmd: python setup.py bdist_wheel @@ -77,6 +101,22 @@ state: absent mode: '0755' +- name: Create temp directory for C++ tests + ansible.builtin.file: + path: /tmp/test/bin + state: directory + mode: '0755' + when: build_cpp_tests + +- name: Collect C++ test files + ansible.builtin.shell: | + cd pytorch/xla/build/temp* + bazel query 'kind(".*_test", tests(//:cpp_tests))' --output=label | xargs -n 1 bazel cquery --output=files | xargs cp -t /tmp/test/bin + args: + executable: bash + chdir: "{{ src_root }}" + when: build_cpp_tests + - name: Read Torchvision pin ansible.builtin.command: cat {{ (src_root, 'pytorch') | path_join }}/.github/ci_commit_pins/vision.txt register: torchvision_pin diff --git a/infra/tpu-pytorch-releases/artifacts.auto.tfvars b/infra/tpu-pytorch-releases/artifacts.auto.tfvars index 0229a79c190..c2617739f45 100644 --- a/infra/tpu-pytorch-releases/artifacts.auto.tfvars +++ b/infra/tpu-pytorch-releases/artifacts.auto.tfvars @@ -35,62 +35,70 @@ nightly_builds = [ versioned_builds = [ # Remove libtpu from PyPI builds { - git_tag = "v2.3.0-rc12" - package_version = "2.3.0-rc12" - pytorch_git_rev = "v2.3.0-rc12" + git_tag = "v2.3.0" + package_version = "2.3.0" + pytorch_git_rev = "v2.3.0" accelerator = "tpu" python_version = "3.8" bundle_libtpu = "0" }, { - git_tag = "v2.3.0-rc12" - package_version = "2.3.0-rc12" - pytorch_git_rev = "v2.3.0-rc12" + git_tag = "v2.3.0" + package_version = "2.3.0" + pytorch_git_rev = "v2.3.0" accelerator = "tpu" python_version = "3.9" bundle_libtpu = "0" }, { - git_tag = "v2.3.0-rc12" - package_version = "2.3.0-rc12" - pytorch_git_rev = "v2.3.0-rc12" + git_tag = "v2.3.0" + package_version = "2.3.0" + pytorch_git_rev = "v2.3.0" accelerator = "tpu" python_version = "3.10" bundle_libtpu = "0" }, { - git_tag = "v2.3.0-rc12" - package_version = "2.3.0-rc12" - pytorch_git_rev = "v2.3.0-rc12" + git_tag = "v2.3.0" + package_version = "2.3.0" + pytorch_git_rev = "v2.3.0" accelerator = "tpu" python_version = "3.11" bundle_libtpu = "0" }, # Bundle libtpu for Kaggle { - git_tag = "v2.3.0-rc12" - package_version = "2.3.0-rc12+libtpu" - pytorch_git_rev = "v2.3.0-rc12" + git_tag = "v2.3.0" + package_version = "2.3.0+libtpu" + pytorch_git_rev = "v2.3.0" accelerator = "tpu" python_version = "3.10" bundle_libtpu = "1" }, { - git_tag = "v2.3.0-rc12" - pytorch_git_rev = "v2.3.0-rc12" - package_version = "2.3.0-rc12" + git_tag = "v2.3.0" + pytorch_git_rev = "v2.3.0" + package_version = "2.3.0" accelerator = "cuda" cuda_version = "12.1" python_version = "3.8" }, { - git_tag = "v2.3.0-rc12" - pytorch_git_rev = "v2.3.0-rc12" - package_version = "2.3.0-rc12" + git_tag = "v2.3.0" + pytorch_git_rev = "v2.3.0" + package_version = "2.3.0" accelerator = "cuda" cuda_version = "12.1" python_version = "3.10" }, + { + git_tag = "v2.3.0" + pytorch_git_rev = "v2.3.0" + package_version = "2.3.0" + accelerator = "cuda" + cuda_version = "12.1" + python_version = "3.11" + }, # Remove libtpu from PyPI builds { git_tag = "v2.2.0" diff --git a/infra/tpu-pytorch-releases/dev_images.tf b/infra/tpu-pytorch-releases/dev_images.tf index 023ac8b870a..54c340809ef 100644 --- a/infra/tpu-pytorch-releases/dev_images.tf +++ b/infra/tpu-pytorch-releases/dev_images.tf @@ -36,8 +36,6 @@ module "dev_images" { image_name = "development" image_tags = concat(each.value.extra_tags, [ each.key, - # Append _YYYYMMDD suffix to the dev image name. - "${each.key}_$(date +%Y%m%d)", ]) dockerfile = "development.Dockerfile" diff --git a/plugins/cuda/torch_xla_cuda_plugin/__init__.py b/plugins/cuda/torch_xla_cuda_plugin/__init__.py index 9321d26a1a6..e6863ff711a 100644 --- a/plugins/cuda/torch_xla_cuda_plugin/__init__.py +++ b/plugins/cuda/torch_xla_cuda_plugin/__init__.py @@ -27,6 +27,9 @@ def physical_chip_count(self) -> int: # TODO: default to actual device count return xu.getenv_as('GPU_NUM_DEVICES', int, 1) + def configure_single_process(self): + pass + def client_create_options(self) -> dict: local_process_rank, global_process_rank = self._get_process_rank() local_world_size, global_world_size = self._get_world_size() diff --git a/requirements.in b/requirements.in new file mode 100644 index 00000000000..0dafeec6331 --- /dev/null +++ b/requirements.in @@ -0,0 +1,9 @@ +filelock +fsspec +jinja2 +markupsafe +mpmath +networkx +pyyaml +sympy +typing-extensions diff --git a/requirements_lock_3_10.txt b/requirements_lock_3_10.txt new file mode 100644 index 00000000000..225f30d1443 --- /dev/null +++ b/requirements_lock_3_10.txt @@ -0,0 +1,153 @@ +# +# This file is autogenerated by pip-compile with Python 3.10 +# by the following command: +# +# bazel run //:requirements.update +# +filelock==3.14.0 \ + --hash=sha256:43339835842f110ca7ae60f1e1c160714c5a6afd15a2873419ab185334975c0f \ + --hash=sha256:6ea72da3be9b8c82afd3edcf99f2fffbb5076335a5ae4d03248bb5b6c3eae78a + # via -r requirements.in +fsspec==2024.5.0 \ + --hash=sha256:1d021b0b0f933e3b3029ed808eb400c08ba101ca2de4b3483fbc9ca23fcee94a \ + --hash=sha256:e0fdbc446d67e182f49a70b82cf7889028a63588fde6b222521f10937b2b670c + # via -r requirements.in +jinja2==3.1.4 \ + --hash=sha256:4a3aee7acbbe7303aede8e9648d13b8bf88a429282aa6122a993f0ac800cb369 \ + --hash=sha256:bc5dd2abb727a5319567b7a813e6a2e7318c39f4f487cfe6c89c6f9c7d25197d + # via -r requirements.in +markupsafe==2.1.5 \ + --hash=sha256:00e046b6dd71aa03a41079792f8473dc494d564611a8f89bbbd7cb93295ebdcf \ + --hash=sha256:075202fa5b72c86ad32dc7d0b56024ebdbcf2048c0ba09f1cde31bfdd57bcfff \ + --hash=sha256:0e397ac966fdf721b2c528cf028494e86172b4feba51d65f81ffd65c63798f3f \ + --hash=sha256:17b950fccb810b3293638215058e432159d2b71005c74371d784862b7e4683f3 \ + --hash=sha256:1f3fbcb7ef1f16e48246f704ab79d79da8a46891e2da03f8783a5b6fa41a9532 \ + --hash=sha256:2174c595a0d73a3080ca3257b40096db99799265e1c27cc5a610743acd86d62f \ + --hash=sha256:2b7c57a4dfc4f16f7142221afe5ba4e093e09e728ca65c51f5620c9aaeb9a617 \ + --hash=sha256:2d2d793e36e230fd32babe143b04cec8a8b3eb8a3122d2aceb4a371e6b09b8df \ + --hash=sha256:30b600cf0a7ac9234b2638fbc0fb6158ba5bdcdf46aeb631ead21248b9affbc4 \ + --hash=sha256:397081c1a0bfb5124355710fe79478cdbeb39626492b15d399526ae53422b906 \ + --hash=sha256:3a57fdd7ce31c7ff06cdfbf31dafa96cc533c21e443d57f5b1ecc6cdc668ec7f \ + --hash=sha256:3c6b973f22eb18a789b1460b4b91bf04ae3f0c4234a0a6aa6b0a92f6f7b951d4 \ + --hash=sha256:3e53af139f8579a6d5f7b76549125f0d94d7e630761a2111bc431fd820e163b8 \ + --hash=sha256:4096e9de5c6fdf43fb4f04c26fb114f61ef0bf2e5604b6ee3019d51b69e8c371 \ + --hash=sha256:4275d846e41ecefa46e2015117a9f491e57a71ddd59bbead77e904dc02b1bed2 \ + --hash=sha256:4c31f53cdae6ecfa91a77820e8b151dba54ab528ba65dfd235c80b086d68a465 \ + --hash=sha256:4f11aa001c540f62c6166c7726f71f7573b52c68c31f014c25cc7901deea0b52 \ + --hash=sha256:5049256f536511ee3f7e1b3f87d1d1209d327e818e6ae1365e8653d7e3abb6a6 \ + --hash=sha256:58c98fee265677f63a4385256a6d7683ab1832f3ddd1e66fe948d5880c21a169 \ + --hash=sha256:598e3276b64aff0e7b3451b72e94fa3c238d452e7ddcd893c3ab324717456bad \ + --hash=sha256:5b7b716f97b52c5a14bffdf688f971b2d5ef4029127f1ad7a513973cfd818df2 \ + --hash=sha256:5dedb4db619ba5a2787a94d877bc8ffc0566f92a01c0ef214865e54ecc9ee5e0 \ + --hash=sha256:619bc166c4f2de5caa5a633b8b7326fbe98e0ccbfacabd87268a2b15ff73a029 \ + --hash=sha256:629ddd2ca402ae6dbedfceeba9c46d5f7b2a61d9749597d4307f943ef198fc1f \ + --hash=sha256:656f7526c69fac7f600bd1f400991cc282b417d17539a1b228617081106feb4a \ + --hash=sha256:6ec585f69cec0aa07d945b20805be741395e28ac1627333b1c5b0105962ffced \ + --hash=sha256:72b6be590cc35924b02c78ef34b467da4ba07e4e0f0454a2c5907f473fc50ce5 \ + --hash=sha256:7502934a33b54030eaf1194c21c692a534196063db72176b0c4028e140f8f32c \ + --hash=sha256:7a68b554d356a91cce1236aa7682dc01df0edba8d043fd1ce607c49dd3c1edcf \ + --hash=sha256:7b2e5a267c855eea6b4283940daa6e88a285f5f2a67f2220203786dfa59b37e9 \ + --hash=sha256:823b65d8706e32ad2df51ed89496147a42a2a6e01c13cfb6ffb8b1e92bc910bb \ + --hash=sha256:8590b4ae07a35970728874632fed7bd57b26b0102df2d2b233b6d9d82f6c62ad \ + --hash=sha256:8dd717634f5a044f860435c1d8c16a270ddf0ef8588d4887037c5028b859b0c3 \ + --hash=sha256:8dec4936e9c3100156f8a2dc89c4b88d5c435175ff03413b443469c7c8c5f4d1 \ + --hash=sha256:97cafb1f3cbcd3fd2b6fbfb99ae11cdb14deea0736fc2b0952ee177f2b813a46 \ + --hash=sha256:a17a92de5231666cfbe003f0e4b9b3a7ae3afb1ec2845aadc2bacc93ff85febc \ + --hash=sha256:a549b9c31bec33820e885335b451286e2969a2d9e24879f83fe904a5ce59d70a \ + --hash=sha256:ac07bad82163452a6884fe8fa0963fb98c2346ba78d779ec06bd7a6262132aee \ + --hash=sha256:ae2ad8ae6ebee9d2d94b17fb62763125f3f374c25618198f40cbb8b525411900 \ + --hash=sha256:b91c037585eba9095565a3556f611e3cbfaa42ca1e865f7b8015fe5c7336d5a5 \ + --hash=sha256:bc1667f8b83f48511b94671e0e441401371dfd0f0a795c7daa4a3cd1dde55bea \ + --hash=sha256:bec0a414d016ac1a18862a519e54b2fd0fc8bbfd6890376898a6c0891dd82e9f \ + --hash=sha256:bf50cd79a75d181c9181df03572cdce0fbb75cc353bc350712073108cba98de5 \ + --hash=sha256:bff1b4290a66b490a2f4719358c0cdcd9bafb6b8f061e45c7a2460866bf50c2e \ + --hash=sha256:c061bb86a71b42465156a3ee7bd58c8c2ceacdbeb95d05a99893e08b8467359a \ + --hash=sha256:c8b29db45f8fe46ad280a7294f5c3ec36dbac9491f2d1c17345be8e69cc5928f \ + --hash=sha256:ce409136744f6521e39fd8e2a24c53fa18ad67aa5bc7c2cf83645cce5b5c4e50 \ + --hash=sha256:d050b3361367a06d752db6ead6e7edeb0009be66bc3bae0ee9d97fb326badc2a \ + --hash=sha256:d283d37a890ba4c1ae73ffadf8046435c76e7bc2247bbb63c00bd1a709c6544b \ + --hash=sha256:d9fad5155d72433c921b782e58892377c44bd6252b5af2f67f16b194987338a4 \ + --hash=sha256:daa4ee5a243f0f20d528d939d06670a298dd39b1ad5f8a72a4275124a7819eff \ + --hash=sha256:db0b55e0f3cc0be60c1f19efdde9a637c32740486004f20d1cff53c3c0ece4d2 \ + --hash=sha256:e61659ba32cf2cf1481e575d0462554625196a1f2fc06a1c777d3f48e8865d46 \ + --hash=sha256:ea3d8a3d18833cf4304cd2fc9cbb1efe188ca9b5efef2bdac7adc20594a0e46b \ + --hash=sha256:ec6a563cff360b50eed26f13adc43e61bc0c04d94b8be985e6fb24b81f6dcfdf \ + --hash=sha256:f5dfb42c4604dddc8e4305050aa6deb084540643ed5804d7455b5df8fe16f5e5 \ + --hash=sha256:fa173ec60341d6bb97a89f5ea19c85c5643c1e7dedebc22f5181eb73573142c5 \ + --hash=sha256:fa9db3f79de01457b03d4f01b34cf91bc0048eb2c3846ff26f66687c2f6d16ab \ + --hash=sha256:fce659a462a1be54d2ffcacea5e3ba2d74daa74f30f5f143fe0c58636e355fdd \ + --hash=sha256:ffee1f21e5ef0d712f9033568f8344d5da8cc2869dbd08d87c84656e6a2d2f68 + # via + # -r requirements.in + # jinja2 +mpmath==1.3.0 \ + --hash=sha256:7a28eb2a9774d00c7bc92411c19a89209d5da7c4c9a9e227be8330a23a25b91f \ + --hash=sha256:a0b2b9fe80bbcd81a6647ff13108738cfb482d481d826cc0e02f5b35e5c88d2c + # via + # -r requirements.in + # sympy +networkx==3.3 \ + --hash=sha256:0c127d8b2f4865f59ae9cb8aafcd60b5c70f3241ebd66f7defad7c4ab90126c9 \ + --hash=sha256:28575580c6ebdaf4505b22c6256a2b9de86b316dc63ba9e93abde3d78dfdbcf2 + # via -r requirements.in +pyyaml==6.0.1 \ + --hash=sha256:04ac92ad1925b2cff1db0cfebffb6ffc43457495c9b3c39d3fcae417d7125dc5 \ + --hash=sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc \ + --hash=sha256:0d3304d8c0adc42be59c5f8a4d9e3d7379e6955ad754aa9d6ab7a398b59dd1df \ + --hash=sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741 \ + --hash=sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206 \ + --hash=sha256:18aeb1bf9a78867dc38b259769503436b7c72f7a1f1f4c93ff9a17de54319b27 \ + --hash=sha256:1d4c7e777c441b20e32f52bd377e0c409713e8bb1386e1099c2415f26e479595 \ + --hash=sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62 \ + --hash=sha256:1fe35611261b29bd1de0070f0b2f47cb6ff71fa6595c077e42bd0c419fa27b98 \ + --hash=sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696 \ + --hash=sha256:326c013efe8048858a6d312ddd31d56e468118ad4cdeda36c719bf5bb6192290 \ + --hash=sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9 \ + --hash=sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d \ + --hash=sha256:49a183be227561de579b4a36efbb21b3eab9651dd81b1858589f796549873dd6 \ + --hash=sha256:4fb147e7a67ef577a588a0e2c17b6db51dda102c71de36f8549b6816a96e1867 \ + --hash=sha256:50550eb667afee136e9a77d6dc71ae76a44df8b3e51e41b77f6de2932bfe0f47 \ + --hash=sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486 \ + --hash=sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6 \ + --hash=sha256:596106435fa6ad000c2991a98fa58eeb8656ef2325d7e158344fb33864ed87e3 \ + --hash=sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007 \ + --hash=sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938 \ + --hash=sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0 \ + --hash=sha256:704219a11b772aea0d8ecd7058d0082713c3562b4e271b849ad7dc4a5c90c13c \ + --hash=sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735 \ + --hash=sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d \ + --hash=sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28 \ + --hash=sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4 \ + --hash=sha256:9046c58c4395dff28dd494285c82ba00b546adfc7ef001486fbf0324bc174fba \ + --hash=sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8 \ + --hash=sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef \ + --hash=sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5 \ + --hash=sha256:afd7e57eddb1a54f0f1a974bc4391af8bcce0b444685d936840f125cf046d5bd \ + --hash=sha256:b1275ad35a5d18c62a7220633c913e1b42d44b46ee12554e5fd39c70a243d6a3 \ + --hash=sha256:b786eecbdf8499b9ca1d697215862083bd6d2a99965554781d0d8d1ad31e13a0 \ + --hash=sha256:ba336e390cd8e4d1739f42dfe9bb83a3cc2e80f567d8805e11b46f4a943f5515 \ + --hash=sha256:baa90d3f661d43131ca170712d903e6295d1f7a0f595074f151c0aed377c9b9c \ + --hash=sha256:bc1bf2925a1ecd43da378f4db9e4f799775d6367bdb94671027b73b393a7c42c \ + --hash=sha256:bd4af7373a854424dabd882decdc5579653d7868b8fb26dc7d0e99f823aa5924 \ + --hash=sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34 \ + --hash=sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43 \ + --hash=sha256:c8098ddcc2a85b61647b2590f825f3db38891662cfc2fc776415143f599bb859 \ + --hash=sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673 \ + --hash=sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54 \ + --hash=sha256:d858aa552c999bc8a8d57426ed01e40bef403cd8ccdd0fc5f6f04a00414cac2a \ + --hash=sha256:e7d73685e87afe9f3b36c799222440d6cf362062f78be1013661b00c5c6f678b \ + --hash=sha256:f003ed9ad21d6a4713f0a9b5a7a0a79e08dd0f221aff4525a2be4c346ee60aab \ + --hash=sha256:f22ac1c3cac4dbc50079e965eba2c1058622631e526bd9afd45fedd49ba781fa \ + --hash=sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c \ + --hash=sha256:fca0e3a251908a499833aa292323f32437106001d436eca0e6e7833256674585 \ + --hash=sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d \ + --hash=sha256:fd66fc5d0da6d9815ba2cebeb4205f95818ff4b79c3ebe268e75d961704af52f + # via -r requirements.in +sympy==1.12 \ + --hash=sha256:c3588cd4295d0c0f603d0f2ae780587e64e2efeedb3521e46b9bb1d08d184fa5 \ + --hash=sha256:ebf595c8dac3e0fdc4152c51878b498396ec7f30e7a914d6071e674d49420fb8 + # via -r requirements.in +typing-extensions==4.11.0 \ + --hash=sha256:83f085bd5ca59c80295fc2a82ab5dac679cbe02b9f33f7d83af68e241bea51b0 \ + --hash=sha256:c1f94d72897edaf4ce775bb7558d5b79d8126906a14ea5ed1635921406c0387a + # via -r requirements.in diff --git a/requirements_lock_3_11.txt b/requirements_lock_3_11.txt new file mode 100644 index 00000000000..78862541e94 --- /dev/null +++ b/requirements_lock_3_11.txt @@ -0,0 +1,153 @@ +# +# This file is autogenerated by pip-compile with Python 3.11 +# by the following command: +# +# bazel run //:requirements.update +# +filelock==3.14.0 \ + --hash=sha256:43339835842f110ca7ae60f1e1c160714c5a6afd15a2873419ab185334975c0f \ + --hash=sha256:6ea72da3be9b8c82afd3edcf99f2fffbb5076335a5ae4d03248bb5b6c3eae78a + # via -r requirements.in +fsspec==2024.5.0 \ + --hash=sha256:1d021b0b0f933e3b3029ed808eb400c08ba101ca2de4b3483fbc9ca23fcee94a \ + --hash=sha256:e0fdbc446d67e182f49a70b82cf7889028a63588fde6b222521f10937b2b670c + # via -r requirements.in +jinja2==3.1.4 \ + --hash=sha256:4a3aee7acbbe7303aede8e9648d13b8bf88a429282aa6122a993f0ac800cb369 \ + --hash=sha256:bc5dd2abb727a5319567b7a813e6a2e7318c39f4f487cfe6c89c6f9c7d25197d + # via -r requirements.in +markupsafe==2.1.5 \ + --hash=sha256:00e046b6dd71aa03a41079792f8473dc494d564611a8f89bbbd7cb93295ebdcf \ + --hash=sha256:075202fa5b72c86ad32dc7d0b56024ebdbcf2048c0ba09f1cde31bfdd57bcfff \ + --hash=sha256:0e397ac966fdf721b2c528cf028494e86172b4feba51d65f81ffd65c63798f3f \ + --hash=sha256:17b950fccb810b3293638215058e432159d2b71005c74371d784862b7e4683f3 \ + --hash=sha256:1f3fbcb7ef1f16e48246f704ab79d79da8a46891e2da03f8783a5b6fa41a9532 \ + --hash=sha256:2174c595a0d73a3080ca3257b40096db99799265e1c27cc5a610743acd86d62f \ + --hash=sha256:2b7c57a4dfc4f16f7142221afe5ba4e093e09e728ca65c51f5620c9aaeb9a617 \ + --hash=sha256:2d2d793e36e230fd32babe143b04cec8a8b3eb8a3122d2aceb4a371e6b09b8df \ + --hash=sha256:30b600cf0a7ac9234b2638fbc0fb6158ba5bdcdf46aeb631ead21248b9affbc4 \ + --hash=sha256:397081c1a0bfb5124355710fe79478cdbeb39626492b15d399526ae53422b906 \ + --hash=sha256:3a57fdd7ce31c7ff06cdfbf31dafa96cc533c21e443d57f5b1ecc6cdc668ec7f \ + --hash=sha256:3c6b973f22eb18a789b1460b4b91bf04ae3f0c4234a0a6aa6b0a92f6f7b951d4 \ + --hash=sha256:3e53af139f8579a6d5f7b76549125f0d94d7e630761a2111bc431fd820e163b8 \ + --hash=sha256:4096e9de5c6fdf43fb4f04c26fb114f61ef0bf2e5604b6ee3019d51b69e8c371 \ + --hash=sha256:4275d846e41ecefa46e2015117a9f491e57a71ddd59bbead77e904dc02b1bed2 \ + --hash=sha256:4c31f53cdae6ecfa91a77820e8b151dba54ab528ba65dfd235c80b086d68a465 \ + --hash=sha256:4f11aa001c540f62c6166c7726f71f7573b52c68c31f014c25cc7901deea0b52 \ + --hash=sha256:5049256f536511ee3f7e1b3f87d1d1209d327e818e6ae1365e8653d7e3abb6a6 \ + --hash=sha256:58c98fee265677f63a4385256a6d7683ab1832f3ddd1e66fe948d5880c21a169 \ + --hash=sha256:598e3276b64aff0e7b3451b72e94fa3c238d452e7ddcd893c3ab324717456bad \ + --hash=sha256:5b7b716f97b52c5a14bffdf688f971b2d5ef4029127f1ad7a513973cfd818df2 \ + --hash=sha256:5dedb4db619ba5a2787a94d877bc8ffc0566f92a01c0ef214865e54ecc9ee5e0 \ + --hash=sha256:619bc166c4f2de5caa5a633b8b7326fbe98e0ccbfacabd87268a2b15ff73a029 \ + --hash=sha256:629ddd2ca402ae6dbedfceeba9c46d5f7b2a61d9749597d4307f943ef198fc1f \ + --hash=sha256:656f7526c69fac7f600bd1f400991cc282b417d17539a1b228617081106feb4a \ + --hash=sha256:6ec585f69cec0aa07d945b20805be741395e28ac1627333b1c5b0105962ffced \ + --hash=sha256:72b6be590cc35924b02c78ef34b467da4ba07e4e0f0454a2c5907f473fc50ce5 \ + --hash=sha256:7502934a33b54030eaf1194c21c692a534196063db72176b0c4028e140f8f32c \ + --hash=sha256:7a68b554d356a91cce1236aa7682dc01df0edba8d043fd1ce607c49dd3c1edcf \ + --hash=sha256:7b2e5a267c855eea6b4283940daa6e88a285f5f2a67f2220203786dfa59b37e9 \ + --hash=sha256:823b65d8706e32ad2df51ed89496147a42a2a6e01c13cfb6ffb8b1e92bc910bb \ + --hash=sha256:8590b4ae07a35970728874632fed7bd57b26b0102df2d2b233b6d9d82f6c62ad \ + --hash=sha256:8dd717634f5a044f860435c1d8c16a270ddf0ef8588d4887037c5028b859b0c3 \ + --hash=sha256:8dec4936e9c3100156f8a2dc89c4b88d5c435175ff03413b443469c7c8c5f4d1 \ + --hash=sha256:97cafb1f3cbcd3fd2b6fbfb99ae11cdb14deea0736fc2b0952ee177f2b813a46 \ + --hash=sha256:a17a92de5231666cfbe003f0e4b9b3a7ae3afb1ec2845aadc2bacc93ff85febc \ + --hash=sha256:a549b9c31bec33820e885335b451286e2969a2d9e24879f83fe904a5ce59d70a \ + --hash=sha256:ac07bad82163452a6884fe8fa0963fb98c2346ba78d779ec06bd7a6262132aee \ + --hash=sha256:ae2ad8ae6ebee9d2d94b17fb62763125f3f374c25618198f40cbb8b525411900 \ + --hash=sha256:b91c037585eba9095565a3556f611e3cbfaa42ca1e865f7b8015fe5c7336d5a5 \ + --hash=sha256:bc1667f8b83f48511b94671e0e441401371dfd0f0a795c7daa4a3cd1dde55bea \ + --hash=sha256:bec0a414d016ac1a18862a519e54b2fd0fc8bbfd6890376898a6c0891dd82e9f \ + --hash=sha256:bf50cd79a75d181c9181df03572cdce0fbb75cc353bc350712073108cba98de5 \ + --hash=sha256:bff1b4290a66b490a2f4719358c0cdcd9bafb6b8f061e45c7a2460866bf50c2e \ + --hash=sha256:c061bb86a71b42465156a3ee7bd58c8c2ceacdbeb95d05a99893e08b8467359a \ + --hash=sha256:c8b29db45f8fe46ad280a7294f5c3ec36dbac9491f2d1c17345be8e69cc5928f \ + --hash=sha256:ce409136744f6521e39fd8e2a24c53fa18ad67aa5bc7c2cf83645cce5b5c4e50 \ + --hash=sha256:d050b3361367a06d752db6ead6e7edeb0009be66bc3bae0ee9d97fb326badc2a \ + --hash=sha256:d283d37a890ba4c1ae73ffadf8046435c76e7bc2247bbb63c00bd1a709c6544b \ + --hash=sha256:d9fad5155d72433c921b782e58892377c44bd6252b5af2f67f16b194987338a4 \ + --hash=sha256:daa4ee5a243f0f20d528d939d06670a298dd39b1ad5f8a72a4275124a7819eff \ + --hash=sha256:db0b55e0f3cc0be60c1f19efdde9a637c32740486004f20d1cff53c3c0ece4d2 \ + --hash=sha256:e61659ba32cf2cf1481e575d0462554625196a1f2fc06a1c777d3f48e8865d46 \ + --hash=sha256:ea3d8a3d18833cf4304cd2fc9cbb1efe188ca9b5efef2bdac7adc20594a0e46b \ + --hash=sha256:ec6a563cff360b50eed26f13adc43e61bc0c04d94b8be985e6fb24b81f6dcfdf \ + --hash=sha256:f5dfb42c4604dddc8e4305050aa6deb084540643ed5804d7455b5df8fe16f5e5 \ + --hash=sha256:fa173ec60341d6bb97a89f5ea19c85c5643c1e7dedebc22f5181eb73573142c5 \ + --hash=sha256:fa9db3f79de01457b03d4f01b34cf91bc0048eb2c3846ff26f66687c2f6d16ab \ + --hash=sha256:fce659a462a1be54d2ffcacea5e3ba2d74daa74f30f5f143fe0c58636e355fdd \ + --hash=sha256:ffee1f21e5ef0d712f9033568f8344d5da8cc2869dbd08d87c84656e6a2d2f68 + # via + # -r requirements.in + # jinja2 +mpmath==1.3.0 \ + --hash=sha256:7a28eb2a9774d00c7bc92411c19a89209d5da7c4c9a9e227be8330a23a25b91f \ + --hash=sha256:a0b2b9fe80bbcd81a6647ff13108738cfb482d481d826cc0e02f5b35e5c88d2c + # via + # -r requirements.in + # sympy +networkx==3.3 \ + --hash=sha256:0c127d8b2f4865f59ae9cb8aafcd60b5c70f3241ebd66f7defad7c4ab90126c9 \ + --hash=sha256:28575580c6ebdaf4505b22c6256a2b9de86b316dc63ba9e93abde3d78dfdbcf2 + # via -r requirements.in +pyyaml==6.0.1 \ + --hash=sha256:04ac92ad1925b2cff1db0cfebffb6ffc43457495c9b3c39d3fcae417d7125dc5 \ + --hash=sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc \ + --hash=sha256:0d3304d8c0adc42be59c5f8a4d9e3d7379e6955ad754aa9d6ab7a398b59dd1df \ + --hash=sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741 \ + --hash=sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206 \ + --hash=sha256:18aeb1bf9a78867dc38b259769503436b7c72f7a1f1f4c93ff9a17de54319b27 \ + --hash=sha256:1d4c7e777c441b20e32f52bd377e0c409713e8bb1386e1099c2415f26e479595 \ + --hash=sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62 \ + --hash=sha256:1fe35611261b29bd1de0070f0b2f47cb6ff71fa6595c077e42bd0c419fa27b98 \ + --hash=sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696 \ + --hash=sha256:326c013efe8048858a6d312ddd31d56e468118ad4cdeda36c719bf5bb6192290 \ + --hash=sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9 \ + --hash=sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d \ + --hash=sha256:49a183be227561de579b4a36efbb21b3eab9651dd81b1858589f796549873dd6 \ + --hash=sha256:4fb147e7a67ef577a588a0e2c17b6db51dda102c71de36f8549b6816a96e1867 \ + --hash=sha256:50550eb667afee136e9a77d6dc71ae76a44df8b3e51e41b77f6de2932bfe0f47 \ + --hash=sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486 \ + --hash=sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6 \ + --hash=sha256:596106435fa6ad000c2991a98fa58eeb8656ef2325d7e158344fb33864ed87e3 \ + --hash=sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007 \ + --hash=sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938 \ + --hash=sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0 \ + --hash=sha256:704219a11b772aea0d8ecd7058d0082713c3562b4e271b849ad7dc4a5c90c13c \ + --hash=sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735 \ + --hash=sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d \ + --hash=sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28 \ + --hash=sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4 \ + --hash=sha256:9046c58c4395dff28dd494285c82ba00b546adfc7ef001486fbf0324bc174fba \ + --hash=sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8 \ + --hash=sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef \ + --hash=sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5 \ + --hash=sha256:afd7e57eddb1a54f0f1a974bc4391af8bcce0b444685d936840f125cf046d5bd \ + --hash=sha256:b1275ad35a5d18c62a7220633c913e1b42d44b46ee12554e5fd39c70a243d6a3 \ + --hash=sha256:b786eecbdf8499b9ca1d697215862083bd6d2a99965554781d0d8d1ad31e13a0 \ + --hash=sha256:ba336e390cd8e4d1739f42dfe9bb83a3cc2e80f567d8805e11b46f4a943f5515 \ + --hash=sha256:baa90d3f661d43131ca170712d903e6295d1f7a0f595074f151c0aed377c9b9c \ + --hash=sha256:bc1bf2925a1ecd43da378f4db9e4f799775d6367bdb94671027b73b393a7c42c \ + --hash=sha256:bd4af7373a854424dabd882decdc5579653d7868b8fb26dc7d0e99f823aa5924 \ + --hash=sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34 \ + --hash=sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43 \ + --hash=sha256:c8098ddcc2a85b61647b2590f825f3db38891662cfc2fc776415143f599bb859 \ + --hash=sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673 \ + --hash=sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54 \ + --hash=sha256:d858aa552c999bc8a8d57426ed01e40bef403cd8ccdd0fc5f6f04a00414cac2a \ + --hash=sha256:e7d73685e87afe9f3b36c799222440d6cf362062f78be1013661b00c5c6f678b \ + --hash=sha256:f003ed9ad21d6a4713f0a9b5a7a0a79e08dd0f221aff4525a2be4c346ee60aab \ + --hash=sha256:f22ac1c3cac4dbc50079e965eba2c1058622631e526bd9afd45fedd49ba781fa \ + --hash=sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c \ + --hash=sha256:fca0e3a251908a499833aa292323f32437106001d436eca0e6e7833256674585 \ + --hash=sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d \ + --hash=sha256:fd66fc5d0da6d9815ba2cebeb4205f95818ff4b79c3ebe268e75d961704af52f + # via -r requirements.in +sympy==1.12 \ + --hash=sha256:c3588cd4295d0c0f603d0f2ae780587e64e2efeedb3521e46b9bb1d08d184fa5 \ + --hash=sha256:ebf595c8dac3e0fdc4152c51878b498396ec7f30e7a914d6071e674d49420fb8 + # via -r requirements.in +typing-extensions==4.11.0 \ + --hash=sha256:83f085bd5ca59c80295fc2a82ab5dac679cbe02b9f33f7d83af68e241bea51b0 \ + --hash=sha256:c1f94d72897edaf4ce775bb7558d5b79d8126906a14ea5ed1635921406c0387a + # via -r requirements.in diff --git a/requirements_lock_3_8.txt b/requirements_lock_3_8.txt new file mode 100644 index 00000000000..022d1e07f3e --- /dev/null +++ b/requirements_lock_3_8.txt @@ -0,0 +1,153 @@ +# +# This file is autogenerated by pip-compile with Python 3.8 +# by the following command: +# +# bazel run //:requirements.update +# +filelock==3.14.0 \ + --hash=sha256:43339835842f110ca7ae60f1e1c160714c5a6afd15a2873419ab185334975c0f \ + --hash=sha256:6ea72da3be9b8c82afd3edcf99f2fffbb5076335a5ae4d03248bb5b6c3eae78a + # via -r requirements.in +fsspec==2024.5.0 \ + --hash=sha256:1d021b0b0f933e3b3029ed808eb400c08ba101ca2de4b3483fbc9ca23fcee94a \ + --hash=sha256:e0fdbc446d67e182f49a70b82cf7889028a63588fde6b222521f10937b2b670c + # via -r requirements.in +jinja2==3.1.4 \ + --hash=sha256:4a3aee7acbbe7303aede8e9648d13b8bf88a429282aa6122a993f0ac800cb369 \ + --hash=sha256:bc5dd2abb727a5319567b7a813e6a2e7318c39f4f487cfe6c89c6f9c7d25197d + # via -r requirements.in +markupsafe==2.1.5 \ + --hash=sha256:00e046b6dd71aa03a41079792f8473dc494d564611a8f89bbbd7cb93295ebdcf \ + --hash=sha256:075202fa5b72c86ad32dc7d0b56024ebdbcf2048c0ba09f1cde31bfdd57bcfff \ + --hash=sha256:0e397ac966fdf721b2c528cf028494e86172b4feba51d65f81ffd65c63798f3f \ + --hash=sha256:17b950fccb810b3293638215058e432159d2b71005c74371d784862b7e4683f3 \ + --hash=sha256:1f3fbcb7ef1f16e48246f704ab79d79da8a46891e2da03f8783a5b6fa41a9532 \ + --hash=sha256:2174c595a0d73a3080ca3257b40096db99799265e1c27cc5a610743acd86d62f \ + --hash=sha256:2b7c57a4dfc4f16f7142221afe5ba4e093e09e728ca65c51f5620c9aaeb9a617 \ + --hash=sha256:2d2d793e36e230fd32babe143b04cec8a8b3eb8a3122d2aceb4a371e6b09b8df \ + --hash=sha256:30b600cf0a7ac9234b2638fbc0fb6158ba5bdcdf46aeb631ead21248b9affbc4 \ + --hash=sha256:397081c1a0bfb5124355710fe79478cdbeb39626492b15d399526ae53422b906 \ + --hash=sha256:3a57fdd7ce31c7ff06cdfbf31dafa96cc533c21e443d57f5b1ecc6cdc668ec7f \ + --hash=sha256:3c6b973f22eb18a789b1460b4b91bf04ae3f0c4234a0a6aa6b0a92f6f7b951d4 \ + --hash=sha256:3e53af139f8579a6d5f7b76549125f0d94d7e630761a2111bc431fd820e163b8 \ + --hash=sha256:4096e9de5c6fdf43fb4f04c26fb114f61ef0bf2e5604b6ee3019d51b69e8c371 \ + --hash=sha256:4275d846e41ecefa46e2015117a9f491e57a71ddd59bbead77e904dc02b1bed2 \ + --hash=sha256:4c31f53cdae6ecfa91a77820e8b151dba54ab528ba65dfd235c80b086d68a465 \ + --hash=sha256:4f11aa001c540f62c6166c7726f71f7573b52c68c31f014c25cc7901deea0b52 \ + --hash=sha256:5049256f536511ee3f7e1b3f87d1d1209d327e818e6ae1365e8653d7e3abb6a6 \ + --hash=sha256:58c98fee265677f63a4385256a6d7683ab1832f3ddd1e66fe948d5880c21a169 \ + --hash=sha256:598e3276b64aff0e7b3451b72e94fa3c238d452e7ddcd893c3ab324717456bad \ + --hash=sha256:5b7b716f97b52c5a14bffdf688f971b2d5ef4029127f1ad7a513973cfd818df2 \ + --hash=sha256:5dedb4db619ba5a2787a94d877bc8ffc0566f92a01c0ef214865e54ecc9ee5e0 \ + --hash=sha256:619bc166c4f2de5caa5a633b8b7326fbe98e0ccbfacabd87268a2b15ff73a029 \ + --hash=sha256:629ddd2ca402ae6dbedfceeba9c46d5f7b2a61d9749597d4307f943ef198fc1f \ + --hash=sha256:656f7526c69fac7f600bd1f400991cc282b417d17539a1b228617081106feb4a \ + --hash=sha256:6ec585f69cec0aa07d945b20805be741395e28ac1627333b1c5b0105962ffced \ + --hash=sha256:72b6be590cc35924b02c78ef34b467da4ba07e4e0f0454a2c5907f473fc50ce5 \ + --hash=sha256:7502934a33b54030eaf1194c21c692a534196063db72176b0c4028e140f8f32c \ + --hash=sha256:7a68b554d356a91cce1236aa7682dc01df0edba8d043fd1ce607c49dd3c1edcf \ + --hash=sha256:7b2e5a267c855eea6b4283940daa6e88a285f5f2a67f2220203786dfa59b37e9 \ + --hash=sha256:823b65d8706e32ad2df51ed89496147a42a2a6e01c13cfb6ffb8b1e92bc910bb \ + --hash=sha256:8590b4ae07a35970728874632fed7bd57b26b0102df2d2b233b6d9d82f6c62ad \ + --hash=sha256:8dd717634f5a044f860435c1d8c16a270ddf0ef8588d4887037c5028b859b0c3 \ + --hash=sha256:8dec4936e9c3100156f8a2dc89c4b88d5c435175ff03413b443469c7c8c5f4d1 \ + --hash=sha256:97cafb1f3cbcd3fd2b6fbfb99ae11cdb14deea0736fc2b0952ee177f2b813a46 \ + --hash=sha256:a17a92de5231666cfbe003f0e4b9b3a7ae3afb1ec2845aadc2bacc93ff85febc \ + --hash=sha256:a549b9c31bec33820e885335b451286e2969a2d9e24879f83fe904a5ce59d70a \ + --hash=sha256:ac07bad82163452a6884fe8fa0963fb98c2346ba78d779ec06bd7a6262132aee \ + --hash=sha256:ae2ad8ae6ebee9d2d94b17fb62763125f3f374c25618198f40cbb8b525411900 \ + --hash=sha256:b91c037585eba9095565a3556f611e3cbfaa42ca1e865f7b8015fe5c7336d5a5 \ + --hash=sha256:bc1667f8b83f48511b94671e0e441401371dfd0f0a795c7daa4a3cd1dde55bea \ + --hash=sha256:bec0a414d016ac1a18862a519e54b2fd0fc8bbfd6890376898a6c0891dd82e9f \ + --hash=sha256:bf50cd79a75d181c9181df03572cdce0fbb75cc353bc350712073108cba98de5 \ + --hash=sha256:bff1b4290a66b490a2f4719358c0cdcd9bafb6b8f061e45c7a2460866bf50c2e \ + --hash=sha256:c061bb86a71b42465156a3ee7bd58c8c2ceacdbeb95d05a99893e08b8467359a \ + --hash=sha256:c8b29db45f8fe46ad280a7294f5c3ec36dbac9491f2d1c17345be8e69cc5928f \ + --hash=sha256:ce409136744f6521e39fd8e2a24c53fa18ad67aa5bc7c2cf83645cce5b5c4e50 \ + --hash=sha256:d050b3361367a06d752db6ead6e7edeb0009be66bc3bae0ee9d97fb326badc2a \ + --hash=sha256:d283d37a890ba4c1ae73ffadf8046435c76e7bc2247bbb63c00bd1a709c6544b \ + --hash=sha256:d9fad5155d72433c921b782e58892377c44bd6252b5af2f67f16b194987338a4 \ + --hash=sha256:daa4ee5a243f0f20d528d939d06670a298dd39b1ad5f8a72a4275124a7819eff \ + --hash=sha256:db0b55e0f3cc0be60c1f19efdde9a637c32740486004f20d1cff53c3c0ece4d2 \ + --hash=sha256:e61659ba32cf2cf1481e575d0462554625196a1f2fc06a1c777d3f48e8865d46 \ + --hash=sha256:ea3d8a3d18833cf4304cd2fc9cbb1efe188ca9b5efef2bdac7adc20594a0e46b \ + --hash=sha256:ec6a563cff360b50eed26f13adc43e61bc0c04d94b8be985e6fb24b81f6dcfdf \ + --hash=sha256:f5dfb42c4604dddc8e4305050aa6deb084540643ed5804d7455b5df8fe16f5e5 \ + --hash=sha256:fa173ec60341d6bb97a89f5ea19c85c5643c1e7dedebc22f5181eb73573142c5 \ + --hash=sha256:fa9db3f79de01457b03d4f01b34cf91bc0048eb2c3846ff26f66687c2f6d16ab \ + --hash=sha256:fce659a462a1be54d2ffcacea5e3ba2d74daa74f30f5f143fe0c58636e355fdd \ + --hash=sha256:ffee1f21e5ef0d712f9033568f8344d5da8cc2869dbd08d87c84656e6a2d2f68 + # via + # -r requirements.in + # jinja2 +mpmath==1.3.0 \ + --hash=sha256:7a28eb2a9774d00c7bc92411c19a89209d5da7c4c9a9e227be8330a23a25b91f \ + --hash=sha256:a0b2b9fe80bbcd81a6647ff13108738cfb482d481d826cc0e02f5b35e5c88d2c + # via + # -r requirements.in + # sympy +networkx==3.1 \ + --hash=sha256:4f33f68cb2afcf86f28a45f43efc27a9386b535d567d2127f8f61d51dec58d36 \ + --hash=sha256:de346335408f84de0eada6ff9fafafff9bcda11f0a0dfaa931133debb146ab61 + # via -r requirements.in +pyyaml==6.0.1 \ + --hash=sha256:04ac92ad1925b2cff1db0cfebffb6ffc43457495c9b3c39d3fcae417d7125dc5 \ + --hash=sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc \ + --hash=sha256:0d3304d8c0adc42be59c5f8a4d9e3d7379e6955ad754aa9d6ab7a398b59dd1df \ + --hash=sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741 \ + --hash=sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206 \ + --hash=sha256:18aeb1bf9a78867dc38b259769503436b7c72f7a1f1f4c93ff9a17de54319b27 \ + --hash=sha256:1d4c7e777c441b20e32f52bd377e0c409713e8bb1386e1099c2415f26e479595 \ + --hash=sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62 \ + --hash=sha256:1fe35611261b29bd1de0070f0b2f47cb6ff71fa6595c077e42bd0c419fa27b98 \ + --hash=sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696 \ + --hash=sha256:326c013efe8048858a6d312ddd31d56e468118ad4cdeda36c719bf5bb6192290 \ + --hash=sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9 \ + --hash=sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d \ + --hash=sha256:49a183be227561de579b4a36efbb21b3eab9651dd81b1858589f796549873dd6 \ + --hash=sha256:4fb147e7a67ef577a588a0e2c17b6db51dda102c71de36f8549b6816a96e1867 \ + --hash=sha256:50550eb667afee136e9a77d6dc71ae76a44df8b3e51e41b77f6de2932bfe0f47 \ + --hash=sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486 \ + --hash=sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6 \ + --hash=sha256:596106435fa6ad000c2991a98fa58eeb8656ef2325d7e158344fb33864ed87e3 \ + --hash=sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007 \ + --hash=sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938 \ + --hash=sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0 \ + --hash=sha256:704219a11b772aea0d8ecd7058d0082713c3562b4e271b849ad7dc4a5c90c13c \ + --hash=sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735 \ + --hash=sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d \ + --hash=sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28 \ + --hash=sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4 \ + --hash=sha256:9046c58c4395dff28dd494285c82ba00b546adfc7ef001486fbf0324bc174fba \ + --hash=sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8 \ + --hash=sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef \ + --hash=sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5 \ + --hash=sha256:afd7e57eddb1a54f0f1a974bc4391af8bcce0b444685d936840f125cf046d5bd \ + --hash=sha256:b1275ad35a5d18c62a7220633c913e1b42d44b46ee12554e5fd39c70a243d6a3 \ + --hash=sha256:b786eecbdf8499b9ca1d697215862083bd6d2a99965554781d0d8d1ad31e13a0 \ + --hash=sha256:ba336e390cd8e4d1739f42dfe9bb83a3cc2e80f567d8805e11b46f4a943f5515 \ + --hash=sha256:baa90d3f661d43131ca170712d903e6295d1f7a0f595074f151c0aed377c9b9c \ + --hash=sha256:bc1bf2925a1ecd43da378f4db9e4f799775d6367bdb94671027b73b393a7c42c \ + --hash=sha256:bd4af7373a854424dabd882decdc5579653d7868b8fb26dc7d0e99f823aa5924 \ + --hash=sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34 \ + --hash=sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43 \ + --hash=sha256:c8098ddcc2a85b61647b2590f825f3db38891662cfc2fc776415143f599bb859 \ + --hash=sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673 \ + --hash=sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54 \ + --hash=sha256:d858aa552c999bc8a8d57426ed01e40bef403cd8ccdd0fc5f6f04a00414cac2a \ + --hash=sha256:e7d73685e87afe9f3b36c799222440d6cf362062f78be1013661b00c5c6f678b \ + --hash=sha256:f003ed9ad21d6a4713f0a9b5a7a0a79e08dd0f221aff4525a2be4c346ee60aab \ + --hash=sha256:f22ac1c3cac4dbc50079e965eba2c1058622631e526bd9afd45fedd49ba781fa \ + --hash=sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c \ + --hash=sha256:fca0e3a251908a499833aa292323f32437106001d436eca0e6e7833256674585 \ + --hash=sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d \ + --hash=sha256:fd66fc5d0da6d9815ba2cebeb4205f95818ff4b79c3ebe268e75d961704af52f + # via -r requirements.in +sympy==1.12 \ + --hash=sha256:c3588cd4295d0c0f603d0f2ae780587e64e2efeedb3521e46b9bb1d08d184fa5 \ + --hash=sha256:ebf595c8dac3e0fdc4152c51878b498396ec7f30e7a914d6071e674d49420fb8 + # via -r requirements.in +typing-extensions==4.11.0 \ + --hash=sha256:83f085bd5ca59c80295fc2a82ab5dac679cbe02b9f33f7d83af68e241bea51b0 \ + --hash=sha256:c1f94d72897edaf4ce775bb7558d5b79d8126906a14ea5ed1635921406c0387a + # via -r requirements.in diff --git a/requirements_lock_3_9.txt b/requirements_lock_3_9.txt new file mode 100644 index 00000000000..a01cb47146d --- /dev/null +++ b/requirements_lock_3_9.txt @@ -0,0 +1,153 @@ +# +# This file is autogenerated by pip-compile with Python 3.9 +# by the following command: +# +# bazel run //:requirements.update +# +filelock==3.14.0 \ + --hash=sha256:43339835842f110ca7ae60f1e1c160714c5a6afd15a2873419ab185334975c0f \ + --hash=sha256:6ea72da3be9b8c82afd3edcf99f2fffbb5076335a5ae4d03248bb5b6c3eae78a + # via -r requirements.in +fsspec==2024.5.0 \ + --hash=sha256:1d021b0b0f933e3b3029ed808eb400c08ba101ca2de4b3483fbc9ca23fcee94a \ + --hash=sha256:e0fdbc446d67e182f49a70b82cf7889028a63588fde6b222521f10937b2b670c + # via -r requirements.in +jinja2==3.1.4 \ + --hash=sha256:4a3aee7acbbe7303aede8e9648d13b8bf88a429282aa6122a993f0ac800cb369 \ + --hash=sha256:bc5dd2abb727a5319567b7a813e6a2e7318c39f4f487cfe6c89c6f9c7d25197d + # via -r requirements.in +markupsafe==2.1.5 \ + --hash=sha256:00e046b6dd71aa03a41079792f8473dc494d564611a8f89bbbd7cb93295ebdcf \ + --hash=sha256:075202fa5b72c86ad32dc7d0b56024ebdbcf2048c0ba09f1cde31bfdd57bcfff \ + --hash=sha256:0e397ac966fdf721b2c528cf028494e86172b4feba51d65f81ffd65c63798f3f \ + --hash=sha256:17b950fccb810b3293638215058e432159d2b71005c74371d784862b7e4683f3 \ + --hash=sha256:1f3fbcb7ef1f16e48246f704ab79d79da8a46891e2da03f8783a5b6fa41a9532 \ + --hash=sha256:2174c595a0d73a3080ca3257b40096db99799265e1c27cc5a610743acd86d62f \ + --hash=sha256:2b7c57a4dfc4f16f7142221afe5ba4e093e09e728ca65c51f5620c9aaeb9a617 \ + --hash=sha256:2d2d793e36e230fd32babe143b04cec8a8b3eb8a3122d2aceb4a371e6b09b8df \ + --hash=sha256:30b600cf0a7ac9234b2638fbc0fb6158ba5bdcdf46aeb631ead21248b9affbc4 \ + --hash=sha256:397081c1a0bfb5124355710fe79478cdbeb39626492b15d399526ae53422b906 \ + --hash=sha256:3a57fdd7ce31c7ff06cdfbf31dafa96cc533c21e443d57f5b1ecc6cdc668ec7f \ + --hash=sha256:3c6b973f22eb18a789b1460b4b91bf04ae3f0c4234a0a6aa6b0a92f6f7b951d4 \ + --hash=sha256:3e53af139f8579a6d5f7b76549125f0d94d7e630761a2111bc431fd820e163b8 \ + --hash=sha256:4096e9de5c6fdf43fb4f04c26fb114f61ef0bf2e5604b6ee3019d51b69e8c371 \ + --hash=sha256:4275d846e41ecefa46e2015117a9f491e57a71ddd59bbead77e904dc02b1bed2 \ + --hash=sha256:4c31f53cdae6ecfa91a77820e8b151dba54ab528ba65dfd235c80b086d68a465 \ + --hash=sha256:4f11aa001c540f62c6166c7726f71f7573b52c68c31f014c25cc7901deea0b52 \ + --hash=sha256:5049256f536511ee3f7e1b3f87d1d1209d327e818e6ae1365e8653d7e3abb6a6 \ + --hash=sha256:58c98fee265677f63a4385256a6d7683ab1832f3ddd1e66fe948d5880c21a169 \ + --hash=sha256:598e3276b64aff0e7b3451b72e94fa3c238d452e7ddcd893c3ab324717456bad \ + --hash=sha256:5b7b716f97b52c5a14bffdf688f971b2d5ef4029127f1ad7a513973cfd818df2 \ + --hash=sha256:5dedb4db619ba5a2787a94d877bc8ffc0566f92a01c0ef214865e54ecc9ee5e0 \ + --hash=sha256:619bc166c4f2de5caa5a633b8b7326fbe98e0ccbfacabd87268a2b15ff73a029 \ + --hash=sha256:629ddd2ca402ae6dbedfceeba9c46d5f7b2a61d9749597d4307f943ef198fc1f \ + --hash=sha256:656f7526c69fac7f600bd1f400991cc282b417d17539a1b228617081106feb4a \ + --hash=sha256:6ec585f69cec0aa07d945b20805be741395e28ac1627333b1c5b0105962ffced \ + --hash=sha256:72b6be590cc35924b02c78ef34b467da4ba07e4e0f0454a2c5907f473fc50ce5 \ + --hash=sha256:7502934a33b54030eaf1194c21c692a534196063db72176b0c4028e140f8f32c \ + --hash=sha256:7a68b554d356a91cce1236aa7682dc01df0edba8d043fd1ce607c49dd3c1edcf \ + --hash=sha256:7b2e5a267c855eea6b4283940daa6e88a285f5f2a67f2220203786dfa59b37e9 \ + --hash=sha256:823b65d8706e32ad2df51ed89496147a42a2a6e01c13cfb6ffb8b1e92bc910bb \ + --hash=sha256:8590b4ae07a35970728874632fed7bd57b26b0102df2d2b233b6d9d82f6c62ad \ + --hash=sha256:8dd717634f5a044f860435c1d8c16a270ddf0ef8588d4887037c5028b859b0c3 \ + --hash=sha256:8dec4936e9c3100156f8a2dc89c4b88d5c435175ff03413b443469c7c8c5f4d1 \ + --hash=sha256:97cafb1f3cbcd3fd2b6fbfb99ae11cdb14deea0736fc2b0952ee177f2b813a46 \ + --hash=sha256:a17a92de5231666cfbe003f0e4b9b3a7ae3afb1ec2845aadc2bacc93ff85febc \ + --hash=sha256:a549b9c31bec33820e885335b451286e2969a2d9e24879f83fe904a5ce59d70a \ + --hash=sha256:ac07bad82163452a6884fe8fa0963fb98c2346ba78d779ec06bd7a6262132aee \ + --hash=sha256:ae2ad8ae6ebee9d2d94b17fb62763125f3f374c25618198f40cbb8b525411900 \ + --hash=sha256:b91c037585eba9095565a3556f611e3cbfaa42ca1e865f7b8015fe5c7336d5a5 \ + --hash=sha256:bc1667f8b83f48511b94671e0e441401371dfd0f0a795c7daa4a3cd1dde55bea \ + --hash=sha256:bec0a414d016ac1a18862a519e54b2fd0fc8bbfd6890376898a6c0891dd82e9f \ + --hash=sha256:bf50cd79a75d181c9181df03572cdce0fbb75cc353bc350712073108cba98de5 \ + --hash=sha256:bff1b4290a66b490a2f4719358c0cdcd9bafb6b8f061e45c7a2460866bf50c2e \ + --hash=sha256:c061bb86a71b42465156a3ee7bd58c8c2ceacdbeb95d05a99893e08b8467359a \ + --hash=sha256:c8b29db45f8fe46ad280a7294f5c3ec36dbac9491f2d1c17345be8e69cc5928f \ + --hash=sha256:ce409136744f6521e39fd8e2a24c53fa18ad67aa5bc7c2cf83645cce5b5c4e50 \ + --hash=sha256:d050b3361367a06d752db6ead6e7edeb0009be66bc3bae0ee9d97fb326badc2a \ + --hash=sha256:d283d37a890ba4c1ae73ffadf8046435c76e7bc2247bbb63c00bd1a709c6544b \ + --hash=sha256:d9fad5155d72433c921b782e58892377c44bd6252b5af2f67f16b194987338a4 \ + --hash=sha256:daa4ee5a243f0f20d528d939d06670a298dd39b1ad5f8a72a4275124a7819eff \ + --hash=sha256:db0b55e0f3cc0be60c1f19efdde9a637c32740486004f20d1cff53c3c0ece4d2 \ + --hash=sha256:e61659ba32cf2cf1481e575d0462554625196a1f2fc06a1c777d3f48e8865d46 \ + --hash=sha256:ea3d8a3d18833cf4304cd2fc9cbb1efe188ca9b5efef2bdac7adc20594a0e46b \ + --hash=sha256:ec6a563cff360b50eed26f13adc43e61bc0c04d94b8be985e6fb24b81f6dcfdf \ + --hash=sha256:f5dfb42c4604dddc8e4305050aa6deb084540643ed5804d7455b5df8fe16f5e5 \ + --hash=sha256:fa173ec60341d6bb97a89f5ea19c85c5643c1e7dedebc22f5181eb73573142c5 \ + --hash=sha256:fa9db3f79de01457b03d4f01b34cf91bc0048eb2c3846ff26f66687c2f6d16ab \ + --hash=sha256:fce659a462a1be54d2ffcacea5e3ba2d74daa74f30f5f143fe0c58636e355fdd \ + --hash=sha256:ffee1f21e5ef0d712f9033568f8344d5da8cc2869dbd08d87c84656e6a2d2f68 + # via + # -r requirements.in + # jinja2 +mpmath==1.3.0 \ + --hash=sha256:7a28eb2a9774d00c7bc92411c19a89209d5da7c4c9a9e227be8330a23a25b91f \ + --hash=sha256:a0b2b9fe80bbcd81a6647ff13108738cfb482d481d826cc0e02f5b35e5c88d2c + # via + # -r requirements.in + # sympy +networkx==3.2.1 \ + --hash=sha256:9f1bb5cf3409bf324e0a722c20bdb4c20ee39bf1c30ce8ae499c8502b0b5e0c6 \ + --hash=sha256:f18c69adc97877c42332c170849c96cefa91881c99a7cb3e95b7c659ebdc1ec2 + # via -r requirements.in +pyyaml==6.0.1 \ + --hash=sha256:04ac92ad1925b2cff1db0cfebffb6ffc43457495c9b3c39d3fcae417d7125dc5 \ + --hash=sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc \ + --hash=sha256:0d3304d8c0adc42be59c5f8a4d9e3d7379e6955ad754aa9d6ab7a398b59dd1df \ + --hash=sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741 \ + --hash=sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206 \ + --hash=sha256:18aeb1bf9a78867dc38b259769503436b7c72f7a1f1f4c93ff9a17de54319b27 \ + --hash=sha256:1d4c7e777c441b20e32f52bd377e0c409713e8bb1386e1099c2415f26e479595 \ + --hash=sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62 \ + --hash=sha256:1fe35611261b29bd1de0070f0b2f47cb6ff71fa6595c077e42bd0c419fa27b98 \ + --hash=sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696 \ + --hash=sha256:326c013efe8048858a6d312ddd31d56e468118ad4cdeda36c719bf5bb6192290 \ + --hash=sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9 \ + --hash=sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d \ + --hash=sha256:49a183be227561de579b4a36efbb21b3eab9651dd81b1858589f796549873dd6 \ + --hash=sha256:4fb147e7a67ef577a588a0e2c17b6db51dda102c71de36f8549b6816a96e1867 \ + --hash=sha256:50550eb667afee136e9a77d6dc71ae76a44df8b3e51e41b77f6de2932bfe0f47 \ + --hash=sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486 \ + --hash=sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6 \ + --hash=sha256:596106435fa6ad000c2991a98fa58eeb8656ef2325d7e158344fb33864ed87e3 \ + --hash=sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007 \ + --hash=sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938 \ + --hash=sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0 \ + --hash=sha256:704219a11b772aea0d8ecd7058d0082713c3562b4e271b849ad7dc4a5c90c13c \ + --hash=sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735 \ + --hash=sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d \ + --hash=sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28 \ + --hash=sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4 \ + --hash=sha256:9046c58c4395dff28dd494285c82ba00b546adfc7ef001486fbf0324bc174fba \ + --hash=sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8 \ + --hash=sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef \ + --hash=sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5 \ + --hash=sha256:afd7e57eddb1a54f0f1a974bc4391af8bcce0b444685d936840f125cf046d5bd \ + --hash=sha256:b1275ad35a5d18c62a7220633c913e1b42d44b46ee12554e5fd39c70a243d6a3 \ + --hash=sha256:b786eecbdf8499b9ca1d697215862083bd6d2a99965554781d0d8d1ad31e13a0 \ + --hash=sha256:ba336e390cd8e4d1739f42dfe9bb83a3cc2e80f567d8805e11b46f4a943f5515 \ + --hash=sha256:baa90d3f661d43131ca170712d903e6295d1f7a0f595074f151c0aed377c9b9c \ + --hash=sha256:bc1bf2925a1ecd43da378f4db9e4f799775d6367bdb94671027b73b393a7c42c \ + --hash=sha256:bd4af7373a854424dabd882decdc5579653d7868b8fb26dc7d0e99f823aa5924 \ + --hash=sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34 \ + --hash=sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43 \ + --hash=sha256:c8098ddcc2a85b61647b2590f825f3db38891662cfc2fc776415143f599bb859 \ + --hash=sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673 \ + --hash=sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54 \ + --hash=sha256:d858aa552c999bc8a8d57426ed01e40bef403cd8ccdd0fc5f6f04a00414cac2a \ + --hash=sha256:e7d73685e87afe9f3b36c799222440d6cf362062f78be1013661b00c5c6f678b \ + --hash=sha256:f003ed9ad21d6a4713f0a9b5a7a0a79e08dd0f221aff4525a2be4c346ee60aab \ + --hash=sha256:f22ac1c3cac4dbc50079e965eba2c1058622631e526bd9afd45fedd49ba781fa \ + --hash=sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c \ + --hash=sha256:fca0e3a251908a499833aa292323f32437106001d436eca0e6e7833256674585 \ + --hash=sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d \ + --hash=sha256:fd66fc5d0da6d9815ba2cebeb4205f95818ff4b79c3ebe268e75d961704af52f + # via -r requirements.in +sympy==1.12 \ + --hash=sha256:c3588cd4295d0c0f603d0f2ae780587e64e2efeedb3521e46b9bb1d08d184fa5 \ + --hash=sha256:ebf595c8dac3e0fdc4152c51878b498396ec7f30e7a914d6071e674d49420fb8 + # via -r requirements.in +typing-extensions==4.11.0 \ + --hash=sha256:83f085bd5ca59c80295fc2a82ab5dac679cbe02b9f33f7d83af68e241bea51b0 \ + --hash=sha256:c1f94d72897edaf4ce775bb7558d5b79d8126906a14ea5ed1635921406c0387a + # via -r requirements.in diff --git a/scripts/apply_patches.sh b/scripts/apply_patches.sh index 923b68c79d4..7ba0a3ef8e3 100755 --- a/scripts/apply_patches.sh +++ b/scripts/apply_patches.sh @@ -7,7 +7,7 @@ XDIR=$CDIR/.. PTDIR=$XDIR/.. OPENXLADIR=$XDIR/third_party/xla -TORCH_PIN="$XDIR/torch_patches/.torch_pin" +TORCH_PIN="$XDIR/.torch_pin" if [ -f "$TORCH_PIN" ]; then CID=$(cat "$TORCH_PIN") # If starts with # and it's not merged into master, fetch from origin diff --git a/setup.py b/setup.py index d45b0b7fc3c..6f81877d0d2 100644 --- a/setup.py +++ b/setup.py @@ -64,10 +64,10 @@ base_dir = os.path.dirname(os.path.abspath(__file__)) -_date = '20240409' +_date = '20240527' _libtpu_version = f'0.1.dev{_date}' _libtpu_storage_path = f'https://storage.googleapis.com/cloud-tpu-tpuvm-artifacts/wheels/libtpu-nightly/libtpu_nightly-{_libtpu_version}-py3-none-any.whl' -_jax_version = f'0.4.27.dev{_date}' +_jax_version = f'0.4.29.dev{_date}' def _get_build_mode(): @@ -223,6 +223,10 @@ def bazel_build(self, ext): f"--symlink_prefix={os.path.join(self.build_temp, 'bazel-')}" ] + build_cpp_tests = build_util.check_env_flag('BUILD_CPP_TESTS', default='0') + if build_cpp_tests: + bazel_argv.append('//:cpp_tests') + import torch cxx_abi = os.getenv('CXX_ABI') or getattr(torch._C, '_GLIBCXX_USE_CXX11_ABI', None) diff --git a/test/benchmarks/run_tests.sh b/test/benchmarks/run_tests.sh index 7d404a7ee7f..fce6140a4fe 100755 --- a/test/benchmarks/run_tests.sh +++ b/test/benchmarks/run_tests.sh @@ -9,7 +9,7 @@ export PYTHONPATH=$PYTHONPATH:$CDIR/../../benchmarks/ # Note [Keep Going] # -# Set the `CONTINUE_ON_ERROR` flag to `true` to make the CircleCI tests continue on error. +# Set the `CONTINUE_ON_ERROR` flag to `true` to make the CI tests continue on error. # This will allow you to see all the failures on your PR, not stopping with the first # test failure like the default behavior. CONTINUE_ON_ERROR="${CONTINUE_ON_ERROR:-0}" @@ -39,10 +39,14 @@ function run_make_tests { } function run_python_tests { - python3 "$CDIR/test_experiment_runner.py" - python3 "$CDIR/test_benchmark_experiment.py" - python3 "$CDIR/test_benchmark_model.py" - python3 "$CDIR/test_result_analyzer.py" + # HACK: don't confuse local `torch_xla` folder with installed package + # Python 3.11 has the permanent fix: https://stackoverflow.com/a/73636559 + pushd $CDIR + python3 "test_experiment_runner.py" + python3 "test_benchmark_experiment.py" + python3 "test_benchmark_model.py" + python3 "test_result_analyzer.py" + popd } function run_tests { diff --git a/test/benchmarks/test_benchmark_experiment.py b/test/benchmarks/test_benchmark_experiment.py index 06c004bcf1e..461df56687f 100644 --- a/test/benchmarks/test_benchmark_experiment.py +++ b/test/benchmarks/test_benchmark_experiment.py @@ -6,15 +6,16 @@ class BenchmarkExperimentTest(unittest.TestCase): def test_to_dict(self): - be = BenchmarkExperiment("cpu", "PJRT", "some xla_flags", "openxla", + be = BenchmarkExperiment("cpu", "PJRT", "some xla_flags", "openxla", None, "train", "123") actual = be.to_dict() - self.assertEqual(7, len(actual)) + self.assertEqual(8, len(actual)) self.assertEqual("cpu", actual["accelerator"]) self.assertTrue("accelerator_model" in actual) self.assertEqual("PJRT", actual["xla"]) self.assertEqual("some xla_flags", actual["xla_flags"]) self.assertEqual("openxla", actual["dynamo"]) + self.assertEqual(None, actual["torch_xla2"]) self.assertEqual("train", actual["test"]) self.assertEqual("123", actual["batch_size"]) diff --git a/test/benchmarks/test_experiment_runner.py b/test/benchmarks/test_experiment_runner.py index 3f6a32a168e..81386d7d82d 100644 --- a/test/benchmarks/test_experiment_runner.py +++ b/test/benchmarks/test_experiment_runner.py @@ -29,10 +29,10 @@ def test_dummy_dry_run(self): expected_in_stderr = [ "Number of selected experiment configs: 4", "Number of selected model configs: 1", - "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cpu\", \"xla\": \"PJRT\", \"xla_flags\": null, \"dynamo\": \"openxla\", \"test\": \"eval\"}", - "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cpu\", \"xla\": \"PJRT\", \"xla_flags\": null, \"dynamo\": \"openxla\", \"test\": \"train\"}", - "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cpu\", \"xla\": null, \"xla_flags\": null, \"dynamo\": \"inductor\", \"test\": \"eval\"}", - "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cpu\", \"xla\": null, \"xla_flags\": null, \"dynamo\": \"inductor\", \"test\": \"train\"}", + "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cpu\", \"xla\": \"PJRT\", \"xla_flags\": null, \"dynamo\": \"openxla\", \"torch_xla2\": null, \"test\": \"eval\"}", + "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cpu\", \"xla\": \"PJRT\", \"xla_flags\": null, \"dynamo\": \"openxla\", \"torch_xla2\": null, \"test\": \"train\"}", + "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cpu\", \"xla\": null, \"xla_flags\": null, \"dynamo\": \"inductor\", \"torch_xla2\": null, \"test\": \"eval\"}", + "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cpu\", \"xla\": null, \"xla_flags\": null, \"dynamo\": \"inductor\", \"torch_xla2\": null, \"test\": \"train\"}", ] for expected in expected_in_stderr: self.assertIn(expected, child.stderr) @@ -57,10 +57,10 @@ def test_dummy_dry_run_cuda(self): expected_in_stderr = [ "Number of selected experiment configs: 4", "Number of selected model configs: 1", - "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": \"PJRT\", \"xla_flags\": null, \"dynamo\": \"openxla\", \"test\": \"eval\"}", - "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": \"PJRT\", \"xla_flags\": null, \"dynamo\": \"openxla\", \"test\": \"train\"}", - "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": null, \"xla_flags\": null, \"dynamo\": \"inductor\", \"test\": \"eval\"}", - "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": null, \"xla_flags\": null, \"dynamo\": \"inductor\", \"test\": \"train\"}", + "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": \"PJRT\", \"xla_flags\": null, \"dynamo\": \"openxla\", \"torch_xla2\": null, \"test\": \"eval\"}", + "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": \"PJRT\", \"xla_flags\": null, \"dynamo\": \"openxla\", \"torch_xla2\": null, \"test\": \"train\"}", + "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": null, \"xla_flags\": null, \"dynamo\": \"inductor\", \"torch_xla2\": null, \"test\": \"eval\"}", + "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": null, \"xla_flags\": null, \"dynamo\": \"inductor\", \"torch_xla2\": null, \"test\": \"train\"}", ] for expected in expected_in_stderr: self.assertIn(expected, child.stderr) @@ -85,8 +85,8 @@ def test_dummy_dry_run_inductor_cuda(self): expected_in_stderr = [ "Number of selected experiment configs: 2", "Number of selected model configs: 1", - "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": null, \"xla_flags\": null, \"dynamo\": \"inductor\", \"test\": \"eval\"}", - "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": null, \"xla_flags\": null, \"dynamo\": \"inductor\", \"test\": \"train\"}", + "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": null, \"xla_flags\": null, \"dynamo\": \"inductor\", \"torch_xla2\": null, \"test\": \"eval\"}", + "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": null, \"xla_flags\": null, \"dynamo\": \"inductor\", \"torch_xla2\": null, \"test\": \"train\"}", ] for expected in expected_in_stderr: self.assertIn(expected, child.stderr) @@ -113,11 +113,11 @@ def test_dummy_openxla_eval_train_cuda(self): expected_in_stderr = [ "Number of selected experiment configs: 5", "Number of selected model configs: 1", - "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": \"PJRT\", \"xla_flags\": null, \"dynamo\": \"openxla_eval\", \"test\": \"eval\"}", - "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": \"PJRT\", \"xla_flags\": null, \"dynamo\": \"openxla\", \"test\": \"train\"}", - "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": \"PJRT\", \"xla_flags\": null, \"dynamo\": \"openxla\", \"test\": \"eval\"}", - "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": null, \"xla_flags\": null, \"dynamo\": \"inductor\", \"test\": \"eval\"}", - "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": null, \"xla_flags\": null, \"dynamo\": \"inductor\", \"test\": \"train\"}", + "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": \"PJRT\", \"xla_flags\": null, \"dynamo\": \"openxla_eval\", \"torch_xla2\": null, \"test\": \"eval\"}", + "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": \"PJRT\", \"xla_flags\": null, \"dynamo\": \"openxla\", \"torch_xla2\": null, \"test\": \"train\"}", + "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": \"PJRT\", \"xla_flags\": null, \"dynamo\": \"openxla\", \"torch_xla2\": null, \"test\": \"eval\"}", + "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": null, \"xla_flags\": null, \"dynamo\": \"inductor\", \"torch_xla2\": null, \"test\": \"eval\"}", + "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": null, \"xla_flags\": null, \"dynamo\": \"inductor\", \"torch_xla2\": null, \"test\": \"train\"}", ] for expected in expected_in_stderr: self.assertIn(expected, child.stderr) @@ -139,15 +139,15 @@ def test_dummy_dynamo_none_cuda(self): expected_in_stderr = [ "Number of selected experiment configs: 9", "Number of selected model configs: 1", - "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": \"PJRT\", \"xla_flags\": null, \"dynamo\": null, \"test\": \"eval\"}", - "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": \"PJRT\", \"xla_flags\": null, \"dynamo\": null, \"test\": \"train\"}", - "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": \"PJRT\", \"xla_flags\": null, \"dynamo\": \"openxla_eval\", \"test\": \"eval\"}", - "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": \"PJRT\", \"xla_flags\": null, \"dynamo\": \"openxla\", \"test\": \"eval\"}", - "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": \"PJRT\", \"xla_flags\": null, \"dynamo\": \"openxla\", \"test\": \"train\"}", - "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": null, \"xla_flags\": null, \"dynamo\": null, \"test\": \"eval\"}", - "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": null, \"xla_flags\": null, \"dynamo\": null, \"test\": \"train\"}", - "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": null, \"xla_flags\": null, \"dynamo\": \"inductor\", \"test\": \"eval\"}", - "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": null, \"xla_flags\": null, \"dynamo\": \"inductor\", \"test\": \"train\"}", + "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": \"PJRT\", \"xla_flags\": null, \"dynamo\": null, \"torch_xla2\": null, \"test\": \"eval\"}", + "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": \"PJRT\", \"xla_flags\": null, \"dynamo\": null, \"torch_xla2\": null, \"test\": \"train\"}", + "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": \"PJRT\", \"xla_flags\": null, \"dynamo\": \"openxla_eval\", \"torch_xla2\": null, \"test\": \"eval\"}", + "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": \"PJRT\", \"xla_flags\": null, \"dynamo\": \"openxla\", \"torch_xla2\": null, \"test\": \"eval\"}", + "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": \"PJRT\", \"xla_flags\": null, \"dynamo\": \"openxla\", \"torch_xla2\": null, \"test\": \"train\"}", + "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": null, \"xla_flags\": null, \"dynamo\": null, \"torch_xla2\": null, \"test\": \"eval\"}", + "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": null, \"xla_flags\": null, \"dynamo\": null, \"torch_xla2\": null, \"test\": \"train\"}", + "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": null, \"xla_flags\": null, \"dynamo\": \"inductor\", \"torch_xla2\": null, \"test\": \"eval\"}", + "--model-config={\"model_name\": \"dummy\"} --experiment-config={\"accelerator\": \"cuda\", \"xla\": null, \"xla_flags\": null, \"dynamo\": \"inductor\", \"torch_xla2\": null, \"test\": \"train\"}", ] for expected in expected_in_stderr: self.assertIn(expected, child.stderr) diff --git a/test/cpp/run_tests.sh b/test/cpp/run_tests.sh index 74244322840..d6b492dc694 100755 --- a/test/cpp/run_tests.sh +++ b/test/cpp/run_tests.sh @@ -5,7 +5,7 @@ BUILDTYPE="opt" VERB= FILTER= LOGFILE=/tmp/pytorch_cpp_test.log -XLA_EXPERIMENTAL="nonzero:masked_select" +XLA_EXPERIMENTAL="nonzero:masked_select:nms" BAZEL_REMOTE_CACHE="0" BAZEL_VERB="test" diff --git a/test/cpp/test_aten_xla_tensor_4.cpp b/test/cpp/test_aten_xla_tensor_4.cpp index ff6130ca1b9..7a02a1079a6 100644 --- a/test/cpp/test_aten_xla_tensor_4.cpp +++ b/test/cpp/test_aten_xla_tensor_4.cpp @@ -504,6 +504,19 @@ TEST_F(AtenXlaTensorTest, TestDivScalar) { ExpectCounterChanged("xla::div", cpp_test::GetIgnoredCounters()); } +TEST_F(AtenXlaTensorTest, TestDivScalarHalfOverflow) { + torch::Tensor input = torch::rand({3, 4}, torch::TensorOptions(torch::kHalf)); + torch::Scalar other = torch::Scalar(100000); + torch::Tensor out = torch::div(input, other); + ForEachDevice([&](const torch::Device& device) { + torch::Tensor xla_input = CopyToDevice(input, device); + torch::Tensor xla_out = torch::div(xla_input, other); + AllClose(out, xla_out); + }); + ExpectCounterNotChanged("aten::.*", cpp_test::GetIgnoredCounters()); + ExpectCounterChanged("xla::div", cpp_test::GetIgnoredCounters()); +} + TEST_F(AtenXlaTensorTest, TestDivScalarInPlace) { for (torch::ScalarType scalar_type : {torch::kFloat}) { torch::Tensor a = diff --git a/test/cpp/test_aten_xla_tensor_5.cpp b/test/cpp/test_aten_xla_tensor_5.cpp index 4070779529f..07e4c2dae86 100644 --- a/test/cpp/test_aten_xla_tensor_5.cpp +++ b/test/cpp/test_aten_xla_tensor_5.cpp @@ -267,6 +267,27 @@ TEST_F(AtenXlaTensorTest, TestEmbedding) { }); } +TEST_F(AtenXlaTensorTest, TestEmbeddingBag) { + torch::Tensor weight = + torch::rand({32, 4}, torch::TensorOptions(torch::kFloat)); + torch::Tensor indices = + torch::randint(0, 31, {10}, torch::TensorOptions(torch::kLong)); + torch::Tensor offsets = torch::arange(0, 10, 3); + auto out = torch::embedding_bag(weight, indices, offsets); + torch::Tensor result = std::get<0>(out); + ForEachDevice([&](const torch::Device& device) { + torch::Tensor xla_weight = CopyToDevice(weight, device); + torch::Tensor xla_indices = CopyToDevice(indices, device); + torch::Tensor xla_offsets = CopyToDevice(offsets, device); + auto xla_out = torch::embedding_bag(xla_weight, xla_indices, xla_offsets); + torch::Tensor xla_result = std::get<0>(xla_out); + AllClose(result, xla_result); + ExpectCounterNotChanged("aten::.*", cpp_test::GetIgnoredCounters()); + ExpectCounterChanged("xla::_embedding_bag_forward_only", + cpp_test::GetIgnoredCounters()); + }); +} + TEST_F(AtenXlaTensorTest, TestOneHot) { int num_classes = 5; torch::Tensor input = diff --git a/test/debug_tool/extract_debug_helper.py b/test/debug_tool/extract_debug_helper.py index 31e72fdda51..af82545192a 100644 --- a/test/debug_tool/extract_debug_helper.py +++ b/test/debug_tool/extract_debug_helper.py @@ -28,6 +28,14 @@ class GraphInfo(NamedTuple): num_output: int +class PostCompilationInfo(NamedTuple): + input_size: str + output_size: str + aliased_size: str + intermediate_size: str + program_size: str + + def extract_graph_infos(lines): infos = [] for i in range(len(lines)): @@ -42,6 +50,28 @@ def extract_graph_infos(lines): return infos +def extract_post_compilation_analysis(lines): + infos = [] + i = 0 + while i < len(lines): + if 'Post Compilation Analysis' in lines[i].decode(): + input_size = lines[i + 1].decode().split('Graph input size: ')[1].strip() + output_size = lines[i + + 2].decode().split('Graph output size: ')[1].strip() + aliased_size = lines[i + + 3].decode().split('Aliased Input size: ')[1].strip() + intermediate_size = lines[i + 4].decode().split( + 'Intermediate tensor size: ')[1].strip() + program_size = lines[i + 5].decode().split( + 'Compiled program size: ')[1].strip() + infos.append( + PostCompilationInfo(input_size, output_size, aliased_size, + intermediate_size, program_size)) + i += 7 + i += 1 + return infos + + def extract_python_frames(lines): frames = [] current_frame = '' diff --git a/test/debug_tool/test_mp_pt_xla_debug.py b/test/debug_tool/test_mp_pt_xla_debug.py index 7ab7f12e740..15f82d11fe1 100644 --- a/test/debug_tool/test_mp_pt_xla_debug.py +++ b/test/debug_tool/test_mp_pt_xla_debug.py @@ -32,14 +32,14 @@ def _mp_fn(index): # only the local master process should dump the executation analysis assert (len(causes) == 1) assert ('user mark_step' in causes[0]) - assert (len(frames) == 2) + assert (len(frames) == 3) max_frame = os.getenv('PT_XLA_DEBUG_MAX_FRAME', 8) # Additonal lines are # 1. Python Frame Triggered Execution: # 2. .... # 3. empty line assert (len(frames[0].split('\n')) == max_frame + 3) - assert (len(frames[1].split('\n')) == max_frame + 3) + assert (len(frames[2].split('\n')) == max_frame + 3) if __name__ == '__main__': diff --git a/test/debug_tool/test_pt_xla_debug.py b/test/debug_tool/test_pt_xla_debug.py index 98a694796a0..ed83b236a11 100644 --- a/test/debug_tool/test_pt_xla_debug.py +++ b/test/debug_tool/test_pt_xla_debug.py @@ -9,15 +9,20 @@ import torch_xla.distributed.parallel_loader as pl import unittest from extract_debug_helper import (check_env_flag, extract_execution_cause, - extract_compilation_cause, GraphInfo, - extract_graph_infos, extract_python_frames) + extract_compilation_cause, + extract_graph_infos, extract_python_frames, + extract_post_compilation_analysis) class PtXLADebugTest(unittest.TestCase): @classmethod def setUpClass(cls): - if not check_env_flag('PT_XLA_DEBUG'): + pt_xla_debug_enabled = xu.getenv_as('PT_XLA_DEBUG', bool, False) + cls.debug_level = xu.getenv_as('PT_XLA_DEBUG_LEVEL', int, -1) + cls.debug_level = 100 if (cls.debug_level == -1 and + pt_xla_debug_enabled) else cls.debug_level + if not check_env_flag('PT_XLA_DEBUG') and cls.debug_level == -1: assert False, "This test should be run with PT_XLA_DEBUG" cls.debug_file_name = os.getenv('PT_XLA_DEBUG_FILE') if not cls.debug_file_name: @@ -33,19 +38,33 @@ def test_user_mark_step(self): executation_causes = extract_execution_cause(lines) compilation_causes = extract_compilation_cause(lines) graph_infos = extract_graph_infos(lines) + post_compilation_infos = extract_post_compilation_analysis(lines) - self.assertEqual(len(executation_causes), 1) - self.assertIn('user mark_step', executation_causes[0]) + self.assertEqual(len(post_compilation_infos), 1) + self.assertIn('GB', post_compilation_infos[0].input_size) + self.assertIn('GB', post_compilation_infos[0].output_size) + self.assertIn('GB', post_compilation_infos[0].aliased_size) + self.assertIn('GB', post_compilation_infos[0].intermediate_size) + self.assertIn('GB', post_compilation_infos[0].program_size) + + if self.debug_level > 1: + self.assertEqual(len(executation_causes), 1) + self.assertIn('user mark_step', executation_causes[0]) + else: + self.assertEqual(len(executation_causes), 0) self.assertEqual(len(compilation_causes), 1) self.assertIn('user mark_step', compilation_causes[0]) - self.assertEqual(len(graph_infos), 2) - # one graph info from compilation, one from execution, hash should match - self.assertEqual(graph_infos[0].hash, graph_infos[1].hash) + if self.debug_level > 1: + self.assertEqual(len(graph_infos), 2) + # one graph info from compilation, one from execution, hash should match + self.assertEqual(graph_infos[0].hash, graph_infos[1].hash) + else: + self.assertEqual(len(graph_infos), 1) # this graph has one input(random seed) and one output(t1) - self.assertEqual(graph_infos[1].num_input, 1) - self.assertEqual(graph_infos[1].num_output, 1) + self.assertEqual(graph_infos[0].num_input, 1) + self.assertEqual(graph_infos[0].num_output, 1) open(self.debug_file_name, 'w').close() def test_step_trace(self): @@ -58,20 +77,26 @@ def test_step_trace(self): compilation_causes = extract_compilation_cause(lines) graph_infos = extract_graph_infos(lines) - self.assertEqual(len(causes), 1) - self.assertIn('mark_step when exiting a profiler StepTrace region', - causes[0]) + if self.debug_level > 1: + self.assertEqual(len(causes), 1) + self.assertIn('mark_step when exiting a profiler StepTrace region', + causes[0]) + else: + self.assertEqual(len(causes), 0) self.assertEqual(len(compilation_causes), 1) self.assertIn('mark_step when exiting a profiler StepTrace region', compilation_causes[0]) - self.assertEqual(len(graph_infos), 2) - # one graph info from compilation, one from execution, hash should match - self.assertEqual(graph_infos[0].hash, graph_infos[1].hash) + if self.debug_level > 1: + self.assertEqual(len(graph_infos), 2) + # one graph info from compilation, one from execution, hash should match + self.assertEqual(graph_infos[0].hash, graph_infos[1].hash) + else: + self.assertEqual(len(graph_infos), 1) # this graph has one input(random seed) and one output(t1) - self.assertEqual(graph_infos[1].num_input, 1) - self.assertEqual(graph_infos[1].num_output, 1) + self.assertEqual(graph_infos[0].num_input, 1) + self.assertEqual(graph_infos[0].num_output, 1) open(self.debug_file_name, 'w').close() def test_dynamo(self): @@ -89,11 +114,14 @@ def toy_program(t1): compilation_causes = extract_compilation_cause(lines) graph_infos = extract_graph_infos(lines) - self.assertEqual(len(executation_causes), 2) - self.assertIn('mark_step when dynamo processing input graphs', - executation_causes[0]) - self.assertIn('dynamo is executing a compiled program', - executation_causes[1]) + if self.debug_level > 1: + self.assertEqual(len(executation_causes), 2) + self.assertIn('mark_step when dynamo processing input graphs', + executation_causes[0]) + self.assertIn('dynamo is executing a compiled program', + executation_causes[1]) + else: + self.assertEqual(len(executation_causes), 0) self.assertEqual(len(compilation_causes), 2) self.assertIn('mark_step when dynamo processing input graphs', @@ -101,17 +129,24 @@ def toy_program(t1): self.assertIn('dynamo is compiling a FX graph to HLO', compilation_causes[1]) - # one graph info from compilation, one from execution, hash should match - self.assertEqual(graph_infos[0].hash, graph_infos[1].hash) + if self.debug_level > 1: + # one graph info from compilation, one from execution, hash should match + self.assertEqual(graph_infos[0].hash, graph_infos[1].hash) # this graph has one input(random seed) and one output(t1) - self.assertEqual(graph_infos[1].num_input, 1) - self.assertEqual(graph_infos[1].num_output, 1) - - # one graph info from dynamo compilation, one from dynamo execution, hash should match - self.assertEqual(graph_infos[2].hash, graph_infos[3].hash) - # this graph has two input(t1, 100) and one output - self.assertEqual(graph_infos[3].num_input, 2) - self.assertEqual(graph_infos[3].num_output, 1) + self.assertEqual(graph_infos[0].num_input, 1) + self.assertEqual(graph_infos[0].num_output, 1) + + if self.debug_level > 1: + # one graph info from dynamo compilation, one from dynamo execution, hash should match + self.assertEqual(graph_infos[2].hash, graph_infos[3].hash) + # this graph has two input(t1, 100) and one output + self.assertEqual(graph_infos[3].num_input, 2) + self.assertEqual(graph_infos[3].num_output, 1) + else: + # this graph has two input(t1, 100) and one output + self.assertEqual(graph_infos[1].num_input, 2) + self.assertEqual(graph_infos[1].num_output, 1) + open(self.debug_file_name, 'w').close() def test_parallel_loader(self): @@ -140,22 +175,26 @@ def test_parallel_loader(self): compilation_causes = extract_compilation_cause(lines) graph_infos = extract_graph_infos(lines) - self.assertEqual(len(executation_causes), batch_size) - for cause in executation_causes: - self.assertIn('mark_step in parallel loader at step end', cause) + if self.debug_level > 1: + self.assertEqual(len(executation_causes), batch_size) + for cause in executation_causes: + self.assertIn('mark_step in parallel loader at step end', cause) + else: + self.assertEqual(len(executation_causes), 0) # We should only compile once. self.assertEqual(len(compilation_causes), 1) self.assertIn('mark_step in parallel loader at step end', compilation_causes[0]) - self.assertEqual(len(graph_infos), batch_size + 1) - # one graph info from compilation, batch size from execution, hash should match - for i in range(batch_size + 1): - self.assertEqual(graph_infos[0].hash, graph_infos[i].hash) - # this graph has two input(data, 100) and one output(dummy) - self.assertEqual(graph_infos[i].num_input, 2) - self.assertEqual(graph_infos[i].num_output, 1) + if self.debug_level > 1: + self.assertEqual(len(graph_infos), batch_size + 1) + # one graph info from compilation, batch size from execution, hash should match + for i in range(batch_size + 1): + self.assertEqual(graph_infos[0].hash, graph_infos[i].hash) + # this graph has two input(data, 100) and one output(dummy) + self.assertEqual(graph_infos[i].num_input, 2) + self.assertEqual(graph_infos[i].num_output, 1) open(self.debug_file_name, 'w').close() def test_print(self): @@ -168,19 +207,22 @@ def test_print(self): compilation_causes = extract_compilation_cause(lines) graph_infos = extract_graph_infos(lines) - self.assertEqual(len(executation_causes), 1) - self.assertIn('user code trying to access tensor value', - executation_causes[0]) + if self.debug_level > 1: + self.assertEqual(len(executation_causes), 1) + self.assertIn('user code trying to access tensor value', + executation_causes[0]) + # one graph info from compilation, one from execution, hash should match + self.assertEqual(graph_infos[0].hash, graph_infos[1].hash) + else: + self.assertEqual(len(executation_causes), 0) self.assertEqual(len(compilation_causes), 1) self.assertIn('user code trying to access tensor value', compilation_causes[0]) - # one graph info from compilation, one from execution, hash should match - self.assertEqual(graph_infos[0].hash, graph_infos[1].hash) # this graph has one input(random seed) and one output(t1) - self.assertEqual(graph_infos[1].num_input, 1) - self.assertEqual(graph_infos[1].num_output, 1) + self.assertEqual(graph_infos[0].num_input, 1) + self.assertEqual(graph_infos[0].num_output, 1) open(self.debug_file_name, 'w').close() def test_frame(self): @@ -191,15 +233,20 @@ def test_frame(self): lines = f.readlines() frames = extract_python_frames(lines) - # one for compilation, one for execution - self.assertEqual(len(frames), 2) + # one for compilation, one for post-compilation analysis, one for execution + if self.debug_level > 1: + self.assertEqual(len(frames), 3) + else: + self.assertEqual(len(frames), 2) max_frame = os.getenv('PT_XLA_DEBUG_MAX_FRAME', 8) # Additonal lines are # 1. Python Frame Triggered Execution: # 2. .... # 3. empty line self.assertEqual(len(frames[0].split('\n')), max_frame + 3) - self.assertEqual(len(frames[1].split('\n')), max_frame + 3) + # second frame will be empty from the post-compilation-analysis + if self.debug_level > 1: + self.assertEqual(len(frames[2].split('\n')), max_frame + 3) # Check mark_step is the first frame self.assertIn('mark_step', frames[0].split('\n')[1]) diff --git a/test/dynamo/test_dynamo.py b/test/dynamo/test_dynamo.py index e7ac2681d5a..3a3eb3d43f1 100644 --- a/test/dynamo/test_dynamo.py +++ b/test/dynamo/test_dynamo.py @@ -152,7 +152,7 @@ def test_simple_model(self): # Tests that the dynamo bridge automatically moves tensors to XLA device, # then back to the original device. - @unittest.skipIf(xr.device_type() != "CUDA", + @unittest.skipIf(xr.device_type() != "CUDA" or not torch.cuda.is_available(), f"GPU tests should only run on GPU devices.") def test_simple_model_automoves_tensors(self): x = torch.tensor(100.0).to(device="cuda") @@ -489,13 +489,13 @@ def test_resnet18(self): # Graph 1: forward # Graph 2: backward # Graph 3: sync input for backward - self.assertEqual(met.metric_data('CompileTime')[0], 3) + self.assertLessEqual(met.metric_data('CompileTime')[0], 3) # We execute 3 graphs per step. - self.assertEqual(met.metric_data('ExecuteTime')[0], sample_count * 3) + self.assertLessEqual(met.metric_data('ExecuteTime')[0], sample_count * 3) # one for each forward and one for each backward - self.assertEqual( + self.assertLessEqual( met.metric_data('RunCachedGraphInputData')[0], sample_count * 2) - self.assertEqual( + self.assertLessEqual( met.metric_data('RunCachedGraphOutputData')[0], sample_count * 2) @@ -641,10 +641,7 @@ def test_all_cpu_tensor(self): # there should be 18 paramters + 1 input self.assertGreater(len(w), 15) self.assertIn('Found tensor with shape torch.Size', str(w[0].message)) - # no XLA operation should happens except a empty mark_step. Partitioner should offload all CPU - # ops to CPU. - self.assertEqual(len(met.counter_names()), 1) - self.assertIn('MarkStep', met.counter_names()) + self.assertLessEqual(len(met.counter_names()), 1) class DynamoOperationsTests(test_utils.XlaTestCase): diff --git a/test/pjrt/test_runtime_tpu.py b/test/pjrt/test_runtime_tpu.py index 0def33ae275..e460864291b 100644 --- a/test/pjrt/test_runtime_tpu.py +++ b/test/pjrt/test_runtime_tpu.py @@ -7,6 +7,7 @@ import torch from absl.testing import absltest, parameterized +import torch_xla import torch_xla.core.xla_env_vars as xenv import torch_xla.core.xla_model as xm import torch_xla.debug.metrics as met @@ -206,7 +207,8 @@ def _runtime_device_attributes(): def test_runtime_device_attributes(self): result = pjrt.run_multiprocess(self._runtime_device_attributes) for device in result.values(): - self.assertCountEqual(['coords', 'core_on_chip'], list(device.keys())) + self.assertCountEqual(['coords', 'core_on_chip', 'num_cores'], + list(device.keys())) self.assertIsInstance(device['coords'], list) self.assertIsInstance(device['core_on_chip'], int) @@ -218,7 +220,7 @@ def test_global_runtime_device_attributes(self): results = pjrt.run_multiprocess(self._global_runtime_device_attributes) for result in results.values(): for device in result: - self.assertCountEqual(['coords', 'core_on_chip', 'name'], + self.assertCountEqual(['coords', 'core_on_chip', 'name', 'num_cores'], list(device.keys())) self.assertIsInstance(device['coords'], list) self.assertIsInstance(device['core_on_chip'], int) @@ -251,6 +253,16 @@ def test_execute_time_metric(self): f"Expected exectue time of {i} to take more than " f"{expected_time_seconds} seconds, got {v / 1e9} seconds") + @staticmethod + def _memory_usage(): + return xm.get_memory_info(torch_xla.device()) + + def test_memory_usage(self): + results = pjrt.run_multiprocess(self._memory_usage) + for usage in results.values(): + self.assertIn('bytes_used', usage) + self.assertIn('bytes_limit', usage) + if __name__ == '__main__': absltest.main() diff --git a/test/pytorch_test_base.py b/test/pytorch_test_base.py index 88ad0f6bc3d..3a6dcdd96c6 100644 --- a/test/pytorch_test_base.py +++ b/test/pytorch_test_base.py @@ -70,6 +70,7 @@ 'test_pdist_norm_backward_xla', # pdist_single 'test_pdist_norm_forward_xla', # pdist_single 'test_nuclear_norm_axes_small_brute_force', + 'test_nondeterministic_alert_EmbeddingBag_max_xla', # FIXME: implement embedding_bag_backward 'test_mul_intertype_scalar', 'test_masked_select_discontiguous', # FIXME: wrong result 'test_memory_format_type', diff --git a/test/run_tests.sh b/test/run_tests.sh index 4d4bd530e27..409c36c9c27 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -8,7 +8,7 @@ VERBOSITY=2 # Note [Keep Going] # -# Set the `CONTINUE_ON_ERROR` flag to `true` to make the CircleCI tests continue on error. +# Set the `CONTINUE_ON_ERROR` flag to `true` to make the CI tests continue on error. # This will allow you to see all the failures on your PR, not stopping with the first # test failure like the default behavior. CONTINUE_ON_ERROR="${CONTINUE_ON_ERROR:-0}" @@ -104,7 +104,7 @@ function run_xla_hlo_debug { function run_dynamic { echo "Running in DynamicShape mode: $@" - XLA_EXPERIMENTAL="nonzero:masked_select:masked_scatter" run_test "$@" + XLA_EXPERIMENTAL="nonzero:masked_select:masked_scatter:nms" run_test "$@" } function run_eager_debug { @@ -127,6 +127,11 @@ function run_pt_xla_debug { PT_XLA_DEBUG=1 PT_XLA_DEBUG_FILE="/tmp/pt_xla_debug.txt" run_test "$@" } +function run_pt_xla_debug_level1 { + echo "Running in save tensor file mode: $@" + PT_XLA_DEBUG_LEVEL=1 PT_XLA_DEBUG_FILE="/tmp/pt_xla_debug.txt" run_test "$@" +} + function run_torchrun { if [ -x "$(command -v nvidia-smi)" ] && [ "$XLA_CUDA" != "0" ]; then echo "Running torchrun test for GPU $@" @@ -162,10 +167,10 @@ function run_xla_op_tests1 { run_dynamic "$CDIR/ds/test_dynamic_shapes.py" run_dynamic "$CDIR/ds/test_dynamic_shape_models.py" "$@" --verbosity=$VERBOSITY run_eager_debug "$CDIR/test_operations.py" "$@" --verbosity=$VERBOSITY - run_test "$CDIR/test_grad_checkpoint.py" run_test "$CDIR/test_operations.py" "$@" --verbosity=$VERBOSITY run_test_without_functionalization "$CDIR/test_operations.py" "$@" --verbosity=$VERBOSITY run_pt_xla_debug "$CDIR/debug_tool/test_pt_xla_debug.py" + run_pt_xla_debug_level1 "$CDIR/debug_tool/test_pt_xla_debug.py" run_test "$CDIR/test_async_closures.py" run_test "$CDIR/test_hlo_metadata.py" run_test "$CDIR/test_profiler.py" @@ -210,8 +215,9 @@ function run_xla_op_tests3 { run_test "$CDIR/stablehlo/test_exports.py" run_test "$CDIR/stablehlo/test_export_fx_passes.py" run_test "$CDIR/stablehlo/test_implicit_broadcasting.py" - run_test "$CDIR/stablehlo/test_mark_pattern.py" + run_test "$CDIR/stablehlo/test_composite.py" run_test "$CDIR/stablehlo/test_pt2e_qdq.py" + run_test "$CDIR/stablehlo/test_stablehlo_custom_call.py" run_xla_hlo_debug "$CDIR/stablehlo/test_stablehlo_inference.py" run_test "$CDIR/stablehlo/test_stablehlo_compile.py" run_test "$CDIR/stablehlo/test_unbounded_dynamism.py" diff --git a/test/spmd/test_dynamo_spmd.py b/test/spmd/test_dynamo_spmd.py index 0595f502da0..d1f6cdc3dce 100644 --- a/test/spmd/test_dynamo_spmd.py +++ b/test/spmd/test_dynamo_spmd.py @@ -205,6 +205,8 @@ def test_dynamo_spmd_mark_sharding_outside_of_compile(self): dynamo_res = dynamo_linear(xla_x) self.assertEqual(met.metric_data('CompileTime')[0], compile_count) + # https://github.com/pytorch/xla/pull/6921#issuecomment-2062106737 + @unittest.skip("Failing in CI") def test_mark_sharding_inside_compile(self): met.clear_counters() device = xm.xla_device() diff --git a/test/spmd/test_fsdp_v2.py b/test/spmd/test_fsdp_v2.py index ae997892547..cc161d0f1a3 100644 --- a/test/spmd/test_fsdp_v2.py +++ b/test/spmd/test_fsdp_v2.py @@ -26,13 +26,13 @@ def setUpClass(cls): def test_fsdp_v2_basic(self): model = self.SimpleLinear().to(xm.xla_device()) mesh = self._get_mesh((self.n_devices, 1), None, ('fsdp', 'tensor')) - model.fc1 = FSDPv2(model.fc1, mesh) - model.fc2 = FSDPv2(model.fc2, mesh) - model = FSDPv2(model, mesh) + model.fc1 = FSDPv2(model.fc1, mesh=mesh) + model.fc2 = FSDPv2(model.fc2, mesh=mesh) + model = FSDPv2(model, mesh=mesh) # Make sure all weights are sharded. if self.n_devices > 1: - annotation = '{devices=[%d,1]%s}' % (self.n_devices, ','.join( + annotation = '{devices=[1,%d]%s}' % (self.n_devices, ','.join( [str(i) for i in range(self.n_devices)])) self.assertEqual(annotation, torch_xla._XLAC._get_xla_sharding_spec(model.fc1.weight)) @@ -67,9 +67,9 @@ def test_fsdp_v2_output_correctness(self): model = copy.deepcopy(model_expected) mesh = self._get_mesh((self.n_devices, 1), None, ('fsdp', 'tensor')) - model.fc1 = FSDPv2(model.fc1, mesh) - model.fc2 = FSDPv2(model.fc2, mesh) - model = FSDPv2(model, mesh) + model.fc1 = FSDPv2(model.fc1, mesh=mesh) + model.fc2 = FSDPv2(model.fc2, mesh=mesh) + model = FSDPv2(model, mesh=mesh) x_expected = torch.randn(16, 128).to(xm.xla_device()) @@ -87,7 +87,7 @@ def test_fsdp_v2_auto_wrap_basic(self): transformer_auto_wrap_policy, transformer_layer_cls={torch.nn.Linear}, ) - model = FSDPv2(model, mesh, auto_wrap_policy=auto_wrap_policy) + model = FSDPv2(model, mesh=mesh, auto_wrap_policy=auto_wrap_policy) self.assertTrue(isinstance(model.fc1, FSDPv2)) self.assertTrue(isinstance(model.fc2, FSDPv2)) @@ -106,7 +106,7 @@ def auto_wrapper_callable(m, *args, **kwargs): model = FSDPv2( model, - mesh, + mesh=mesh, auto_wrap_policy=auto_wrap_policy, auto_wrapper_callable=auto_wrapper_callable) @@ -139,6 +139,64 @@ def test_fsdp_v2_cpu_model(self): self.assertEqual( str(list(model._orig_module.parameters())[0].device), "xla:0") + @unittest.skipIf(xr.device_type() != 'TPU', "This test only works on TPU.") + def test_fsdp_v2_multi_slice(self): + model = self.SimpleLinear().to(xm.xla_device()) + mesh = self._get_mesh((2, self.n_devices // 2, 1), None, + ('data', 'fsdp', 'tensor')) + model = FSDPv2(model, mesh=mesh, extra_data_axis="data") + + # Make sure all weights are sharded. + annotation = '{devices=[1,2,2]0,2,1,3 last_tile_dim_replicate}' + if self.n_devices == 8: + annotation = '{devices=[1,4,2]0,4,1,5,2,6,3,7 last_tile_dim_replicate}' + self.assertEqual(annotation, + torch_xla._XLAC._get_xla_sharding_spec(model.fc1.weight)) + self.assertEqual(annotation, + torch_xla._XLAC._get_xla_sharding_spec(model.fc2.weight)) + + x = torch.randn(16, 128).to(xm.xla_device()) + xs.mark_sharding(x, mesh, (('data', 'fsdp'), None)) + output = model(x) + # Make sure output are sharded. + annotation = '{devices=[4,1]0,1,2,3}' + if self.n_devices == 8: + annotation = '{devices=[8,1]0,1,2,3,4,5,6,7}' + self.assertEqual(annotation, torch_xla._XLAC._get_xla_sharding_spec(x)) + self.assertEqual(annotation, torch_xla._XLAC._get_xla_sharding_spec(output)) + + # Make sure the model can execute without error. + xm.mark_step() + xm.wait_device_ops() + + @unittest.skipIf(xr.device_type() != 'TPU', "This test only works on TPU.") + def test_fsdp_v2_multi_slice_output_correctness(self): + model_expected = self.SimpleLinear().to(xm.xla_device()) + + model = copy.deepcopy(model_expected) + mesh = self._get_mesh((2, self.n_devices // 2, 1), None, + ('data', 'fsdp', 'tensor')) + model = FSDPv2(model, mesh=mesh, extra_data_axis="data") + + x_expected = torch.randn(16, 128).to(xm.xla_device()) + + x = copy.deepcopy(x_expected) + xs.mark_sharding(x, mesh, (('data', 'fsdp'), None)) + + output_expected = model_expected(x_expected) + output = model(x) + self.assertTrue(torch.allclose(output_expected.cpu(), output.cpu())) + + def test_fsdp_v2_multi_slice_error(self): + model = self.SimpleLinear().to(xm.xla_device()) + xs.set_global_mesh( + self._get_mesh((2, self.n_devices // 2, 1), None, + ('data', 'fsdp', 'tensor'))) + + with self.assertRaisesRegex(ValueError, + "The provided ddp axis is not in the mesh."): + model = FSDPv2(model, extra_data_axis='ddp') + if __name__ == '__main__': test = unittest.main() diff --git a/test/spmd/test_xla_distributed_checkpoint.py b/test/spmd/test_xla_distributed_checkpoint.py index a78057210ab..a035a3f11bd 100644 --- a/test/spmd/test_xla_distributed_checkpoint.py +++ b/test/spmd/test_xla_distributed_checkpoint.py @@ -17,11 +17,13 @@ import torch_xla.distributed.spmd as xs from torch.distributed.checkpoint._fsspec_filesystem import * +from collections.abc import Iterable + from torch.distributed.checkpoint.default_planner import ( create_default_local_save_plan, create_default_global_save_plan, ) -from torch_xla.experimental.distributed_checkpoint import SPMDLoadPlanner, SPMDSavePlanner, CheckpointManager +from torch_xla.experimental.distributed_checkpoint import SPMDLoadPlanner, SPMDSavePlanner, CheckpointManager, prime_optimizer from torch_xla.experimental.distributed_checkpoint._helpers import ( _sharded_cpu_state_dict, _CpuShards, _is_sharded_tensor) @@ -68,6 +70,33 @@ def _same_shard_data(self, shards, others) -> bool: return False return True + def _assert_same_state_dict(self, sd1, sd2, keypath=""): + assert type(sd1) == type( + sd2), f"Different types in state_dict: {sd1} vs {sd2}" + + if isinstance(sd1, torch.Tensor): + assert sd1.device == sd2.device, f"Tensors on different devices at {keypath}: {sd1} vs {sd2}" + if sd1.device == xm.xla_device(): + sharding1 = torch_xla._XLAC._get_xla_sharding_spec(sd1) + sharding2 = torch_xla._XLAC._get_xla_sharding_spec(sd2) + assert sharding1 == sharding2, f"Different sharding on tensors at {keypath}: {sharding1} vs {sharding2}" + assert torch.equal( + sd1, sd2), f"Different tensors at {keypath}:\n{sd1} vs {sd2}" + + elif isinstance(sd1, dict): + assert sd1.keys() == sd2.keys( + ), f"Different keys at {keypath}: {sd1} vs {sd2}" + for key in sd1: + self._assert_same_state_dict( + sd1[key], sd2[key], keypath=f'{keypath}.{key}') + + elif isinstance(sd1, Iterable): + for ind, (a, b) in enumerate(zip(sd1, sd2)): + self._assert_same_state_dict(a, b, keypath=f'{keypath}[{ind}]') + + else: + assert sd1 == sd2, f"Different value at {keypath}: {sd1} vs {sd2}" + class EndToEndCheckpointTest(DistributedCheckpointTestBase): @@ -357,7 +386,7 @@ class CheckpointManagerTest(DistributedCheckpointTestBase): def setUp(self): super().setUp() - # Initialize the a minimal process group + # Initialize a minimal process group dist.init_process_group( backend='gloo', init_method='tcp://localhost:8932', @@ -565,6 +594,68 @@ def test_auto_checkpoint(self, tmpdir): self.assertTrue(chkpt_mgr.reached_preemption(step)) +@unittest.skipIf(xr.device_type() != 'TPU', + 'TPU required for worker IP discovery') +class OptimizerCheckpointTest(DistributedCheckpointTestBase): + + def setUp(self): + super().setUp() + # Initialize a minimal process group + dist.init_process_group( + backend='gloo', + init_method='tcp://localhost:8932', + world_size=1, + rank=0) + + def tearDown(self): + super().tearDown() + # Destroy the CPU process group after the test + dist.destroy_process_group() + + def _get_model_and_optimizer(self, optim_cls): + model = self._get_sharded_model() + optim = optim_cls(params=model.parameters()) + return model, optim + + def _run_train_step(self, model, optim): + torch.manual_seed(42) + model(torch.ones(10, 128).to('xla')).square().sum().backward() + optim.step() + xm.mark_step() + + def _test_optimizer(self, tmpdir, optim_cls): + model, optim = self._get_model_and_optimizer(optim_cls) + self._run_train_step(model, optim) + + # Take a checkpoint including the optimizer + chkpt_mgr = CheckpointManager(tmpdir, 1) + state_dict = {'model': model.state_dict(), 'optim': optim.state_dict()} + chkpt_mgr.save(0, state_dict, force=True) + + # Load the checkpoint into a new model and optimizer + new_model, new_optim = self._get_model_and_optimizer(optim_cls) + prime_optimizer(new_optim) + new_state_dict = { + 'model': new_model.state_dict(), + 'optim': new_optim.state_dict() + } + chkpt_mgr.restore(0, new_state_dict) + self._assert_same_state_dict(state_dict, new_state_dict) + + new_model.load_state_dict(new_state_dict['model']) + new_optim.load_state_dict(new_state_dict['optim']) + self._assert_same_state_dict(new_model.state_dict(), model.state_dict()) + self._assert_same_state_dict(new_optim.state_dict(), optim.state_dict()) + + @run_with_tmpdir + def test_sgd(self, tmpdir): + self._test_optimizer(tmpdir, torch.optim.SGD) + + @run_with_tmpdir + def test_adamw(self, tmpdir): + self._test_optimizer(tmpdir, torch.optim.AdamW) + + if __name__ == '__main__': test = unittest.main() sys.exit(0 if test.result.wasSuccessful() else 1) diff --git a/test/stablehlo/test_mark_pattern.py b/test/stablehlo/test_composite.py similarity index 100% rename from test/stablehlo/test_mark_pattern.py rename to test/stablehlo/test_composite.py diff --git a/test/stablehlo/test_export_fx_passes.py b/test/stablehlo/test_export_fx_passes.py index d1e731abd6e..82650997316 100644 --- a/test/stablehlo/test_export_fx_passes.py +++ b/test/stablehlo/test_export_fx_passes.py @@ -18,7 +18,7 @@ class ExportFxPassTest(unittest.TestCase): def test_decompose_dynamic_shape_select(self): args = (torch.rand((10, 197, 768)), 1, 0) - dynamic_shapes = ([{0: Dim("bs")}, None, None],) + dynamic_shapes = (({0: Dim("bs")}, None, None),) m = wrap_func_as_nn_module(torch.ops.aten.select.int) ep = export(m, args, dynamic_shapes=dynamic_shapes) out1 = ep.module()(*args) @@ -55,7 +55,7 @@ def forward(self, x): def test_embedding_indices_flatten(self): args = (torch.rand((20, 768)), torch.randint(0, 15, (3, 10)).to(torch.int64)) - dynamic_shapes = ([None, {0: Dim("bs")}],) + dynamic_shapes = ((None, {0: Dim("bs")}),) m = wrap_func_as_nn_module(torch.ops.aten.embedding.default) ep = export(m, args, dynamic_shapes=dynamic_shapes) print(ep) diff --git a/test/stablehlo/test_exports.py b/test/stablehlo/test_exports.py index a08b65d1ffe..6208ae1ca52 100644 --- a/test/stablehlo/test_exports.py +++ b/test/stablehlo/test_exports.py @@ -45,7 +45,7 @@ def test_interpolate(self): exported = torch.export.export(model, arg) shlo = exported_program_to_stablehlo(exported) ans2 = shlo(*arg).cpu().to(torch.float32) - self.assertTrue(torch.allclose(ans, ans2, atol=1e-5)) + torch.testing.assert_close(ans, ans2, rtol=1e-5, atol=1e-4) def test_constant(self): diff --git a/test/stablehlo/test_mlir_debuginfo.py b/test/stablehlo/test_mlir_debuginfo.py index 42ebfaefbdb..fc81a43c20a 100644 --- a/test/stablehlo/test_mlir_debuginfo.py +++ b/test/stablehlo/test_mlir_debuginfo.py @@ -1,10 +1,11 @@ -import unittest import re +import unittest import torch import torch_xla import torch_xla.experimental.xla_mlir_debuginfo -from torch_xla.stablehlo import exported_program_to_stablehlo +from torch_xla.stablehlo import (StableHLOExportOptions, + exported_program_to_stablehlo) class XlaMlirDebuginfoTest(unittest.TestCase): @@ -28,6 +29,31 @@ def forward(self, x, y): self.assertTrue(re.search(r'stablehlo.add.+\"MY_ADD\"', mlir_text)) self.assertTrue(re.search(r'stablehlo.sub.+\"MY_SUB\"', mlir_text)) + def test_export_node_metadata(self): + + class M(torch.nn.Module): + + def __init__(self): + super().__init__() + self.fc1 = torch.nn.Linear(in_features=4, out_features=16, bias=True) + self.fc2 = torch.nn.Linear(in_features=16, out_features=10, bias=True) + + def forward(self, x): + x = self.fc1(x) + x = self.fc2(x) + return torch.relu(x) + + args = (torch.rand(2, 4),) + ep = torch.export.export(M(), args) + export_options = StableHLOExportOptions() + export_options.export_node_metadata = True + shlo = exported_program_to_stablehlo(ep, options=export_options) + shlo_text = shlo.get_stablehlo_text() + print(shlo_text) + self.assertTrue('stack_trace' in shlo_text) + self.assertTrue('nn_module_stack' in shlo_text) + self.assertTrue('source_fn_stack' in shlo_text) + if __name__ == '__main__': test = unittest.main() diff --git a/test/stablehlo/test_pt2e_qdq.py b/test/stablehlo/test_pt2e_qdq.py index da3341957ee..ea3f6cac067 100644 --- a/test/stablehlo/test_pt2e_qdq.py +++ b/test/stablehlo/test_pt2e_qdq.py @@ -126,8 +126,10 @@ def test_resnet18_per_channel(self): quantizer = XNNPACKQuantizer().set_global( get_symmetric_quantization_config(is_per_channel=True)) m = prepare_pt2e(m, quantizer) - - # Step 3: Quantize the model + # Step 3: Run through example inputs, otherwise per-channel + # quant may have scalar scale/zero_point + m(*args) + # Step 4: Quantize the model m = convert_pt2e(m, fold_quantize=False) # Trace with torch/xla and export stablehlo diff --git a/test/stablehlo/test_stablehlo_custom_call.py b/test/stablehlo/test_stablehlo_custom_call.py new file mode 100644 index 00000000000..7291608e506 --- /dev/null +++ b/test/stablehlo/test_stablehlo_custom_call.py @@ -0,0 +1,121 @@ +import re +import unittest + +import torch +import torch_xla +import torch_xla.core.xla_model as xm +import torch_xla.experimental.stablehlo_custom_call +from torch.library import Library, impl, impl_abstract +from torch_xla.experimental.stablehlo_custom_call import stablehlo_custom_call +from torch_xla.stablehlo import (StableHLOExportOptions, + exported_program_to_stablehlo) + +m = Library("my_custom_library", "DEF") + + +class StableHLOCustomCallExportTest(unittest.TestCase): + + def test_single_output(self): + + m.define("custom_op(Tensor input) -> Tensor") + + @impl(m, "custom_op", "Meta") + def custom_op_meta(x): + return torch.empty_like(x) + + class M(torch.nn.Module): + + def forward(self, x): + x = torch.sin(x) + x = torch.ops.my_custom_library.custom_op(x) + x = torch.cos(x) + x = torch.ops.my_custom_library.custom_op(x) + x = torch.sin(x) + return x + + options = StableHLOExportOptions() + options.custom_ops_allowed_in_graph.add("my_custom_library") + ep = torch.export.export(M(), (torch.randn(3, 3),)) + shlo_module = exported_program_to_stablehlo(ep, options) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search( + r"stablehlo.custom_call.*@my_custom_library\.custom_op\.default", + shlo_text) is not None) + self.assertTrue( + re.search(r"tensor<3x3xf32>.*->.*tensor<3x3xf32>", shlo_text) + is not None) + self.assertTrue(shlo_text.count("@my_custom_library.custom_op.default", 2)) + + def test_multiple_input_output(self): + + m.define("custom_op2(Tensor input, Tensor input) -> (Tensor, Tensor)") + + @impl(m, "custom_op2", "Meta") + def custom_op2_meta(x, y): + return torch.empty_like(x), torch.empty(y.shape[1:], device='meta') + + class M(torch.nn.Module): + + def forward(self, x, y): + x = torch.sin(x) + x, y = torch.ops.my_custom_library.custom_op2(x, y) + x = torch.cos(x) + x, y = torch.ops.my_custom_library.custom_op2(x, y) + y = torch.sin(y) + return x, y + + options = StableHLOExportOptions() + options.custom_ops_allowed_in_graph.add("my_custom_library") + ep = torch.export.export(M(), (torch.randn(3, 3), torch.randn(5, 5))) + shlo_module = exported_program_to_stablehlo(ep, options) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search( + r"stablehlo.custom_call.*@my_custom_library\.custom_op2\.default", + shlo_text) is not None) + self.assertTrue( + re.search( + r"tensor<3x3xf32>.*tensor<5x5xf32>.*->.*tuple, tensor<5xf32>>", + shlo_text) is not None) + self.assertTrue(shlo_text.count("@my_custom_library.custom_op2.default", 2)) + + def test_stable_custom_call_api(self): + + m.define("custom_op3(Tensor input) -> Tensor") + + @impl(m, "custom_op3", "Meta") + def custom_op3_meta(x): + return torch.empty(x.shape[1:], device='meta') + + @impl(m, "custom_op3", "XLA") + def custom_op3_xla(x): + res = stablehlo_custom_call((x,), "custom_op3", [x.shape[1:]], + [torch.int8], True, "backend_config", 1) + return res + + class M(torch.nn.Module): + + def forward(self, x): + x = torch.sin(x) + x = torch.ops.my_custom_library.custom_op3(x) + x = torch.cos(x) + return x + + ep = torch.export.export(M(), (torch.randn(3, 3),)) + shlo_module = exported_program_to_stablehlo(ep) + shlo_text = shlo_module.get_stablehlo_text() + self.assertTrue( + re.search(r"stablehlo.custom_call.*@custom_op3", shlo_text) is not None) + self.assertTrue( + re.search(r"tensor<3x3xf32>.*->.*tensor<3xi8>", shlo_text) is not None) + self.assertTrue("backend_config = \"backend_config\"" in shlo_text) + self.assertTrue("has_side_effect = true" in shlo_text) + # TODO: api version lost during conversion, or not shown in txt format. + # self.assertTrue("api_version = 1" in shlo_text) + + +if __name__ == "__main__": + + test = unittest.main() + sys.exit(0 if test.result.wasSuccessful() else 1) diff --git a/test/stablehlo/test_unbounded_dynamism.py b/test/stablehlo/test_unbounded_dynamism.py index e185a47007e..3cd17a7fe34 100644 --- a/test/stablehlo/test_unbounded_dynamism.py +++ b/test/stablehlo/test_unbounded_dynamism.py @@ -27,7 +27,7 @@ class UnboundedDynamismExportTest(unittest.TestCase): def test_add(self): args = (torch.rand((10, 197, 768)), torch.rand((10, 197, 768))) - dynamic_shapes = ([{0: Dim("dim")}, {0: Dim("dim")}],) + dynamic_shapes = (({0: Dim("dim")}, {0: Dim("dim")}),) m = wrap_func_as_nn_module(torch.ops.aten.add.Tensor) ep = export(m, args=args, dynamic_shapes=dynamic_shapes) shlo_module = exported_program_to_stablehlo(ep) @@ -45,7 +45,7 @@ def test_add(self): def test_add_scalar(self): args = (torch.rand((10, 197, 768)), 0.345) - dynamic_shapes = ([{0: Dim("dim")}, None],) + dynamic_shapes = (({0: Dim("dim")}, None),) m = wrap_func_as_nn_module(torch.ops.aten.add.Tensor) ep = export(m, args=args, dynamic_shapes=dynamic_shapes) shlo_module = exported_program_to_stablehlo(ep) @@ -62,7 +62,7 @@ def test_add_scalar(self): def test_addmm(self): args = (torch.rand((5)), torch.rand((10, 5)), torch.rand((5, 5))) - dynamic_shapes = ([None, {0: Dim("dim")}, None],) + dynamic_shapes = ((None, {0: Dim("dim")}, None),) m = wrap_func_as_nn_module(torch.ops.aten.addmm.default) ep = export(m, args=args, dynamic_shapes=dynamic_shapes) shlo_module = exported_program_to_stablehlo(ep) @@ -83,7 +83,7 @@ def test_bmm(self): torch.rand((24, 197, 64)), torch.rand((24, 64, 197)), ) - dynamic_shapes = ([{0: Dim("dim")}, {0: Dim("dim")}],) + dynamic_shapes = (({0: Dim("dim")}, {0: Dim("dim")}),) m = wrap_func_as_nn_module(torch.ops.aten.bmm.default) ep = export(m, args=args, dynamic_shapes=dynamic_shapes) shlo_module = exported_program_to_stablehlo(ep) @@ -104,7 +104,7 @@ def test_bmm_dynamic_out_dim(self): torch.rand((8, 128, 256)), torch.rand((8, 256, 3)), ) - dynamic_shapes = ([None, {2: Dim("dim")}],) + dynamic_shapes = ((None, {2: Dim("dim")}),) m = wrap_func_as_nn_module(torch.ops.aten.bmm.default) ep = export(m, args=args, dynamic_shapes=dynamic_shapes) shlo_module = exported_program_to_stablehlo(ep) @@ -125,7 +125,7 @@ def test_bmm_dynamic_reduction_dim(self): torch.rand((8, 128, 3)), torch.rand((8, 3, 256)), ) - dynamic_shapes = ([{2: Dim("dim")}, {1: Dim("dim")}],) + dynamic_shapes = (({2: Dim("dim")}, {1: Dim("dim")}),) m = wrap_func_as_nn_module(torch.ops.aten.bmm.default) ep = export(m, args=args, dynamic_shapes=dynamic_shapes) shlo_module = exported_program_to_stablehlo(ep) @@ -143,7 +143,7 @@ def test_bmm_dynamic_reduction_dim(self): def test_cat(self): args = (torch.rand((10, 1, 768)), torch.rand((10, 196, 768))) - dynamic_shapes = ([{0: Dim("dim")}, {0: Dim("dim")}],) + dynamic_shapes = (({0: Dim("dim")}, {0: Dim("dim")}),) m = wrap_func_as_nn_module( lambda x, y: torch.ops.aten.cat.default([x, y], 1)) ep = export(m, args=args, dynamic_shapes=dynamic_shapes) @@ -166,7 +166,7 @@ def test_conv(self): torch.rand((5, 3, 16, 16)), torch.rand((5)), ) - dynamic_shapes = ([{0: Dim("dim")}, None, None],) + dynamic_shapes = (({0: Dim("dim")}, None, None),) m = wrap_func_as_nn_module( lambda x, y, z: torch.ops.aten.convolution.default( x, @@ -197,7 +197,7 @@ def test_conv1d(self): torch.rand((3, 1, 800)), torch.rand((512, 1, 10)), ) - dynamic_shapes = ([{0: Dim("dim")}, None],) + dynamic_shapes = (({0: Dim("dim")}, None),) # dynamic_shapes = None m = wrap_func_as_nn_module(lambda x, y: torch.ops.aten.convolution.default( x, @@ -225,7 +225,7 @@ def test_conv1d(self): def test_cumsum(self): args = (torch.rand((10, 5)), 1) - dynamic_shapes = ([{0: Dim("dim")}, None],) + dynamic_shapes = (({0: Dim("dim")}, None),) m = wrap_func_as_nn_module(torch.ops.aten.cumsum.default) ep = export(m, args=args, dynamic_shapes=dynamic_shapes) shlo_module = exported_program_to_stablehlo(ep) @@ -242,7 +242,7 @@ def test_cumsum(self): def test_div(self): args = (torch.rand((10, 12, 197)), torch.rand((10, 12, 197))) - dynamic_shapes = ([{0: Dim("dim")}, {0: Dim("dim")}],) + dynamic_shapes = (({0: Dim("dim")}, {0: Dim("dim")}),) m = wrap_func_as_nn_module(torch.ops.aten.div.Tensor) ep = export(m, args=args, dynamic_shapes=dynamic_shapes) shlo_module = exported_program_to_stablehlo(ep) @@ -260,7 +260,7 @@ def test_div(self): def test_div_scalar(self): args = (torch.rand((10, 12, 197)), 8.0) - dynamic_shapes = ([{0: Dim("dim")}, None],) + dynamic_shapes = (({0: Dim("dim")}, None),) m = wrap_func_as_nn_module(torch.ops.aten.div.Tensor) ep = export(m, args=args, dynamic_shapes=dynamic_shapes) shlo_module = exported_program_to_stablehlo(ep) @@ -277,7 +277,7 @@ def test_div_scalar(self): def test_gelu(self): args = (torch.rand((3, 5)),) - dynamic_shapes = ([{0: Dim("dim")}],) + dynamic_shapes = (({0: Dim("dim")},),) m = wrap_func_as_nn_module(torch.ops.aten.gelu) ep = export(m, args=args, dynamic_shapes=dynamic_shapes) shlo_module = exported_program_to_stablehlo(ep) @@ -342,7 +342,7 @@ def forward(self, x): def test_mul(self): args = (torch.rand((10, 2, 768)), torch.rand((10, 2, 768))) - dynamic_shapes = ([{0: Dim("dim")}, {0: Dim("dim")}],) + dynamic_shapes = (({0: Dim("dim")}, {0: Dim("dim")}),) m = wrap_func_as_nn_module(torch.ops.aten.mul.Tensor) ep = export(m, args=args, dynamic_shapes=dynamic_shapes) shlo_module = exported_program_to_stablehlo(ep) @@ -360,7 +360,7 @@ def test_mul(self): def test_mul_scalar(self): args = (torch.rand((10, 2, 768)), 0.125) - dynamic_shapes = ([{0: Dim("dim")}, None],) + dynamic_shapes = (({0: Dim("dim")}, None),) m = wrap_func_as_nn_module(torch.ops.aten.mul.Tensor) ep = export(m, args=args, dynamic_shapes=dynamic_shapes) shlo_module = exported_program_to_stablehlo(ep) @@ -483,7 +483,7 @@ def forward(self, x, weight, bias): def test_permute(self): args = (torch.rand((10, 197, 12, 64)),) - dynamic_shapes = ([{0: Dim("dim")}],) + dynamic_shapes = (({0: Dim("dim")},),) m = wrap_func_as_nn_module( lambda x: torch.ops.aten.permute.default(x, [0, 2, 1, 3])) ep = export(m, args=args, dynamic_shapes=dynamic_shapes) @@ -502,7 +502,7 @@ def test_permute(self): def test_select(self): args = (torch.rand((10, 197, 768)), 1, 0) - dynamic_shapes = ([{0: Dim("dim")}, None, None],) + dynamic_shapes = (({0: Dim("dim")}, None, None),) m = wrap_func_as_nn_module(torch.ops.aten.select.int) ep = export(m, args=args, dynamic_shapes=dynamic_shapes) shlo_module = exported_program_to_stablehlo(ep) @@ -519,7 +519,7 @@ def test_select(self): def test_slice(self): args = (torch.rand((10, 3, 224, 224)), 0, 0, 9223372036854775807) - dynamic_shapes = ([{0: Dim("dim")}, None, None, None],) + dynamic_shapes = (({0: Dim("dim")}, None, None, None),) m = wrap_func_as_nn_module(torch.ops.aten.slice.Tensor) ep = export(m, args=args, dynamic_shapes=dynamic_shapes) shlo_module = exported_program_to_stablehlo(ep) @@ -537,7 +537,7 @@ def test_slice(self): def test_slice_2(self): args = (torch.rand((10, 3, 224, 224)), 1, 0, 2) - dynamic_shapes = ([{0: Dim("dim")}, None, None, None],) + dynamic_shapes = (({0: Dim("dim")}, None, None, None),) m = wrap_func_as_nn_module(torch.ops.aten.slice.Tensor) ep = export(m, args=args, dynamic_shapes=dynamic_shapes) shlo_module = exported_program_to_stablehlo(ep) @@ -555,7 +555,7 @@ def test_slice_2(self): def test_softmax(self): args = (torch.rand((10, 12, 197, 197)), -1, False) - dynamic_shapes = ([{0: Dim("dim")}, None, None],) + dynamic_shapes = (({0: Dim("dim")}, None, None),) m = wrap_func_as_nn_module(torch.ops.aten._softmax.default) ep = export(m, args=args, dynamic_shapes=dynamic_shapes) shlo_module = exported_program_to_stablehlo(ep) @@ -573,7 +573,7 @@ def test_softmax(self): def test_sub(self): args = (torch.rand((10, 1, 1, 10)), torch.rand((10, 1, 1, 10))) - dynamic_shapes = ([{0: Dim("dim")}, {0: Dim("dim")}],) + dynamic_shapes = (({0: Dim("dim")}, {0: Dim("dim")}),) m = wrap_func_as_nn_module(torch.ops.aten.sub.Tensor) ep = export(m, args=args, dynamic_shapes=dynamic_shapes) shlo_module = exported_program_to_stablehlo(ep) @@ -591,7 +591,7 @@ def test_sub(self): def test_softmax_reduce_on_dynamic_dim(self): args = (torch.rand((1, 8, 128, 3)), -1, False) - dynamic_shapes = ([{3: Dim("dim")}, None, None],) + dynamic_shapes = (({3: Dim("dim")}, None, None),) m = wrap_func_as_nn_module(torch.ops.aten._softmax.default) ep = export(m, args=args, dynamic_shapes=dynamic_shapes) shlo_module = exported_program_to_stablehlo(ep) @@ -609,7 +609,7 @@ def test_softmax_reduce_on_dynamic_dim(self): @unittest.skip("Converted StableHLO contains i1 dtype, not expected.") def test_index(self): args = (torch.rand((2, 10)), torch.arange(5)) - dynamic_shapes = ([None, {0: Dim("dim")}],) + dynamic_shapes = ((None, {0: Dim("dim")}),) m = wrap_func_as_nn_module( lambda x, y: torch.ops.aten.index.Tensor(x, [None, y])) ep = export(m, args=args, dynamic_shapes=dynamic_shapes) @@ -628,7 +628,7 @@ def test_index(self): def test_sub_scalar(self): args = (1.0, torch.rand((10, 1, 1, 10))) - dynamic_shapes = ([None, {0: Dim("dim")}],) + dynamic_shapes = ((None, {0: Dim("dim")}),) m = wrap_func_as_nn_module(torch.ops.aten.sub.Tensor) ep = export(m, args=args, dynamic_shapes=dynamic_shapes) shlo_module = exported_program_to_stablehlo(ep) @@ -670,7 +670,7 @@ def forward(self, x): def test_transpose_on_dynamic_dim(self): args = (torch.rand((1, 8, 3, 256)),) - dynamic_shapes = ([{2: Dim("dim")}],) + dynamic_shapes = (({2: Dim("dim")},),) m = wrap_func_as_nn_module( lambda x: torch.ops.aten.transpose.int(x, -2, -1)) ep = export(m, args=args, dynamic_shapes=dynamic_shapes) @@ -688,7 +688,7 @@ def test_transpose_on_dynamic_dim(self): def test_unsqueeze_1(self): args = (torch.rand((3, 10)),) - dynamic_shapes = ([{0: Dim("dim")}],) + dynamic_shapes = (({0: Dim("dim")},),) m = wrap_func_as_nn_module(lambda x: torch.ops.aten.unsqueeze.default(x, 1)) ep = export(m, args=args, dynamic_shapes=dynamic_shapes) shlo_module = exported_program_to_stablehlo(ep) @@ -705,7 +705,7 @@ def test_unsqueeze_1(self): def test_unsqueeze_2(self): args = (torch.rand((1, 1, 3, 256)),) - dynamic_shapes = ([{2: Dim("dim")}],) + dynamic_shapes = (({2: Dim("dim")},),) m = wrap_func_as_nn_module(lambda x: torch.ops.aten.unsqueeze.default(x, 2)) ep = export(m, args=args, dynamic_shapes=dynamic_shapes) shlo_module = exported_program_to_stablehlo(ep) diff --git a/test/test_devices.py b/test/test_devices.py index e1fc804736d..259f0046623 100644 --- a/test/test_devices.py +++ b/test/test_devices.py @@ -2,7 +2,10 @@ from absl.testing import absltest, parameterized import torch +from torch import nn +from torch.utils.data import TensorDataset, DataLoader import torch_xla as xla +import torch_xla.core.xla_model as xm import torch_xla.runtime as xr import torch_xla.debug.metrics as met @@ -14,8 +17,8 @@ def setUpClass(cls): xr.set_device_type('CPU') os.environ['CPU_NUM_DEVICES'] = '4' - def tearDown(self): - met.clear_metrics() + def setUp(self): + met.clear_all() @parameterized.parameters((None, torch.device('xla:0')), (0, torch.device('xla:0')), @@ -40,6 +43,56 @@ def test_sync(self): self.assertEqual(met.counter_value('MarkStep'), 1) + def test_step(self): + with xla.step(): + torch.ones((3, 3), device=xla.device()) + + self.assertEqual(met.counter_value('MarkStep'), 2) + + def test_step_exception(self): + with self.assertRaisesRegex(RuntimeError, 'Expected error'): + with xla.step(): + torch.ones((3, 3), device=xla.device()) + raise RuntimeError('Expected error') + + self.assertEqual(met.counter_value('MarkStep'), 2) + + # Should roughly match example given in README + def test_trivial_model(self): + + class TrivialModel(nn.Module): + + def __init__(self): + super().__init__() + self.linear = nn.Linear(10, 10) + + def forward(self, x): + return self.linear(x) + + model = TrivialModel().to(xla.device()) + + batch_size = 16 + num_samples = 100 + + input_data = torch.randn(num_samples, 10) + target_data = torch.randn(num_samples, 10) + + # Create a DataLoader + dataset = TensorDataset(input_data, target_data) + loader = DataLoader(dataset, batch_size=batch_size, shuffle=True) + + loss_fn = nn.MSELoss() + optimizer = torch.optim.SGD(model.parameters(), lr=0.01) + + for inputs, labels in loader: + with xla.step(): + inputs, labels = inputs.to(xla.device()), labels.to(xla.device()) + optimizer.zero_grad() + outputs = model(inputs) + loss = loss_fn(outputs, labels) + loss.backward() + xm.optimizer_step(optimizer) + if __name__ == "__main__": absltest.main() diff --git a/test/test_gmm.py b/test/test_gmm.py new file mode 100644 index 00000000000..b594a85c065 --- /dev/null +++ b/test/test_gmm.py @@ -0,0 +1,460 @@ +import logging +import unittest + +from typing import Optional, Union, Callable + +import torch +import torch_xla +import torch_xla.core.xla_model as xm +import torch_xla.debug.metrics as met +from torch_xla.experimental.custom_kernel import gmm, _make_group_metadata, _histogram, tgmm, gmm_backward, GMM +from torch_xla import runtime as xr +from torch_xla._internal import tpu + +import numpy as np + +if xr.device_type() == 'TPU': + from torch_xla.experimental.custom_kernel import jax_import_guard + jax_import_guard() + import jax + import jax.numpy as jnp + from jax.experimental import pallas as pl + + +class MegabloxTest(unittest.TestCase): + + def _reference_gmm(self, lhs: torch.Tensor, rhs: torch.Tensor, + group_sizes: torch.Tensor) -> torch.Tensor: + start = 0 + out = [] + for i, size in enumerate(group_sizes): + result = lhs[start:start + size, :] @ rhs[i, :, :] + out.append(result) + start += group_sizes[i] + return torch.cat(out) + + def _reference_tgmm(self, lhs: torch.Tensor, rhs: torch.Tensor, + group_sizes: torch.Tensor) -> torch.Tensor: + start = 0 + out = [] + for i, size in enumerate(group_sizes): + result = lhs[:, start:start + size] @ rhs[start:start + size, :] + out.append(result) + start += group_sizes[i] + return torch.stack(out) + + def _group_sizes_strategy(self, m: int, num_groups: int) -> torch.Tensor: + # Randomly sample the ends of the groups in the m-dimension. Let the fuzzer + # sample with replacement so that it's possible to get zero-sized groups. Get + # 'num_groups - 1' run ends. The final group will end at 'm'. + ends_no_final = np.sort( + np.array( + [np.random.randint(low=0, high=m) for _ in range(num_groups - 1)], + dtype=np.int32, + ),) + ends = np.concatenate([ends_no_final, np.array([m], dtype=np.int32)]) + + # Calculate the run starts by shifting ends 1 to the right. The first run + # starts at zero. + starts = np.concatenate([np.zeros(1, dtype=np.int32), ends_no_final]) + return torch.from_numpy(ends - starts).to(torch.int32) + + def _init_test_cases(self): + self.tests_cases = [] + self.tests_cases.append({ + 'dtype': torch.float32, + 'm': 128, + 'k': 128, + 'n': 128, + 'num_groups': 1 + }) + self.tests_cases.append({ + 'dtype': torch.float32, + 'm': 256, + 'k': 128, + 'n': 128, + 'num_groups': 1 + }) + self.tests_cases.append({ + 'dtype': torch.float32, + 'm': 128, + 'k': 256, + 'n': 128, + 'num_groups': 8 + }) + self.tests_cases.append({ + 'dtype': torch.float32, + 'm': 512, + 'k': 128, + 'n': 256, + 'num_groups': 2 + }) + + @unittest.skipIf(xr.device_type() != 'TPU', "This test only works on TPU.") + def test_gmm(self): + met.clear_all() + jax.config.update('jax_default_matmul_precision', jax.lax.Precision.HIGHEST) + + self._init_test_cases() + for test_case in self.tests_cases: + num_groups = test_case['num_groups'] + k = test_case['k'] + m = test_case['m'] + n = test_case['n'] + lhs_dtype = rhs_dtype = test_case['dtype'] + + lhs = torch.rand(m, k, dtype=lhs_dtype) + rhs = torch.rand(num_groups, k, n, dtype=rhs_dtype) + group_sizes = self._group_sizes_strategy(m=m, num_groups=num_groups) + ref_out = self._reference_gmm(lhs, rhs, group_sizes) + + out = gmm(lhs.to("xla"), rhs.to("xla"), group_sizes.to("xla")) + self.assertTrue(torch.allclose(ref_out, out.cpu())) + + # Make sure gmm doesn't fallback. + self.assertNotIn("aten::", met.short_metrics_report()) + jax.config.update('jax_default_matmul_precision', jax.lax.Precision.DEFAULT) + + @unittest.skipIf(xr.device_type() != 'TPU', "This test only works on TPU.") + def test_gmm_bf16(self): + met.clear_all() + + self._init_test_cases() + for test_case in self.tests_cases: + num_groups = test_case['num_groups'] + k = test_case['k'] + m = test_case['m'] + n = test_case['n'] + lhs_dtype = rhs_dtype = torch.bfloat16 + + lhs = torch.rand(m, k, dtype=lhs_dtype) + rhs = torch.rand(num_groups, k, n, dtype=rhs_dtype) + group_sizes = self._group_sizes_strategy(m=m, num_groups=num_groups) + ref_out = self._reference_gmm(lhs, rhs, group_sizes) + + out = gmm(lhs.to("xla"), rhs.to("xla"), group_sizes.to("xla")) + + self.assertTrue(torch.allclose(ref_out, out.cpu())) + + # Make sure gmm doesn't fallback. + self.assertNotIn("aten::", met.short_metrics_report()) + + @unittest.skipIf(xr.device_type() != 'TPU', "This test only works on TPU.") + def test_make_group_metadata(self): + from jax.experimental.pallas.ops.tpu.megablox.gmm import make_group_metadata as jax_make_group_metadata + met.clear_all() + + test_grids = [ + { + 'group_sizes': [8, 8, 8, 8], + 'm': 32, + 'tm': 8 + }, + { + 'group_sizes': [2, 14, 8, 8], + 'm': 32, + 'tm': 8 + }, + { + 'group_sizes': [16, 0, 8, 8], + 'm': 32, + 'tm': 8 + }, + { + 'group_sizes': [2, 0, 14, 16], + 'm': 32, + 'tm': 8 + }, + { + 'group_sizes': [8, 12, 0, 12], + 'm': 32, + 'tm': 8 + }, + { + 'group_sizes': [6, 12, 0, 14], + 'm': 32, + 'tm': 8 + }, + { + 'group_sizes': [6, 12, 0, 14], + 'm': 32, + 'tm': 4 + }, + { + 'group_sizes': [377, 588, 153, 1638, 3261, 5890, 996, 3481], + 'm': 16384, + 'tm': 128 + }, + ] + + for test_grid in test_grids: + jax_meta, jax_num_tiles = jax_make_group_metadata( + group_sizes=jnp.array(test_grid['group_sizes']), + m=test_grid['m'], + tm=test_grid['tm'], + start_group=0, + num_nonzero_groups=len(test_grid['group_sizes']), + ) + + torch_meta = _make_group_metadata( + group_sizes=torch.tensor(test_grid['group_sizes']).to( + torch.int32).to("xla"), + m=test_grid['m'], + tm=test_grid['tm'], + visit_empty_groups=True, + ) + + for i in range(len(jax_meta)): + self.assertTrue( + torch.all( + torch.from_numpy(np.array(jax_meta[i])) == torch_meta[i].cpu())) + self.assertEqual(jax_num_tiles, torch_meta[-1].cpu().item()) + + # Make sure _make_group_metadata doesn't fallback. + self.assertNotIn("aten::", met.short_metrics_report()) + + def test_histogram(self): + test_grids = [ + { + 'input': [1, 4, 4, 1, 2, 3], + 'min': 1, + 'max': 4, + }, + { + 'input': [1, 4, 4, 1, 2, 3], + 'min': 2, + 'max': 3, + }, + { + 'input': [1, 4, 4, 1, 2, 3], + 'min': 0, + 'max': 5, + }, + { + 'input': [], + 'min': 0, + 'max': 5, + }, + ] + + for test_grid in test_grids: + torch_chart = torch.histc( + torch.tensor(test_grid['input'], dtype=torch.float), + bins=test_grid['max'] - test_grid['min'] + 1, + min=test_grid['min'], + max=test_grid['max'], + ) + + chart = _histogram( + torch.tensor(test_grid['input'], dtype=torch.int32).to("xla"), + min=test_grid['min'], + max=test_grid['max'], + ) + + self.assertTrue(torch.all(torch_chart == chart.cpu())) + + def test_histogram_raise(self): + with self.assertRaisesRegex(AssertionError, + "input must be of torch.int32 dtype."): + _histogram( + torch.tensor([1, 4, 4, 1, 2, 3], dtype=torch.float), + min=4, + max=5, + ) + + with self.assertRaisesRegex(AssertionError, + "min must be less than or equal to max."): + _histogram( + torch.tensor([1, 4, 4, 1, 2, 3], dtype=torch.int32), + min=4, + max=3, + ) + + def test_sorting_input(self): + met.clear_all() + top2 = torch.tensor([[0, 2], [1, 3], [1, 2], [2, 3]]).to("xla") + + # We want to create one big batch of tokens that has all top-k choices in it. + # Our tokens will thus be duplicated k-times in the batch. To do this we, + # first flatten the expert choices list and argsort it. This gives us an array + # of length B * K. We then create a tiled arange of size B * K and index + # into the expert choices list. This will give us the set of indices we need + # to gather from the xs to create this big batch. + top_flat = top2.flatten() + lhs_order = top_flat.argsort() + lhs_reverse_order = lhs_order.argsort() + lhs_indices = torch.arange( + top2.shape[0], device="xla").repeat_interleave(2)[lhs_order] + group_sizes = _histogram(top_flat.to(torch.int32), 0, 3) + xm.mark_step() + + # Make sure it doesn't fallback. + self.assertNotIn("aten::", met.short_metrics_report()) + self.assertTrue( + torch.all(lhs_indices == torch.tensor([0, 1, 2, 0, 3, 2, 1, 3], + device="xla"))) + self.assertTrue( + torch.all(group_sizes == torch.tensor([1, 2, 3, 2], device="xla"))) + + @unittest.skipIf(xr.device_type() != 'TPU', "This test only works on TPU.") + def test_tgmm(self): + met.clear_all() + jax.config.update('jax_default_matmul_precision', jax.lax.Precision.HIGHEST) + + self._init_test_cases() + for test_case in self.tests_cases: + num_groups = test_case['num_groups'] + k = test_case['k'] + m = test_case['m'] + n = test_case['n'] + lhs_dtype = rhs_dtype = test_case['dtype'] + + lhs = torch.rand(k, m, dtype=lhs_dtype) + rhs = torch.rand(m, n, dtype=rhs_dtype) + group_sizes = self._group_sizes_strategy(m=m, num_groups=num_groups) + ref_out = self._reference_tgmm(lhs, rhs, group_sizes) + + out = tgmm(lhs.to("xla"), rhs.to("xla"), group_sizes.to("xla")) + self.assertTrue(torch.allclose(ref_out, out.cpu())) + + # Make sure tgmm doesn't fallback. + self.assertNotIn("aten::", met.short_metrics_report()) + jax.config.update('jax_default_matmul_precision', jax.lax.Precision.DEFAULT) + + @unittest.skipIf(xr.device_type() != 'TPU', "This test only works on TPU.") + def test_tgmm_bf16(self): + met.clear_all() + + self._init_test_cases() + for test_case in self.tests_cases: + num_groups = test_case['num_groups'] + k = test_case['k'] + m = test_case['m'] + n = test_case['n'] + lhs_dtype = rhs_dtype = torch.bfloat16 + + lhs = torch.rand(k, m, dtype=lhs_dtype) + rhs = torch.rand(m, n, dtype=rhs_dtype) + group_sizes = self._group_sizes_strategy(m=m, num_groups=num_groups) + ref_out = self._reference_tgmm(lhs, rhs, group_sizes) + + out = tgmm(lhs.to("xla"), rhs.to("xla"), group_sizes.to("xla")) + self.assertTrue(torch.allclose(ref_out, out.cpu())) + + # Make sure tgmm doesn't fallback. + self.assertNotIn("aten::", met.short_metrics_report()) + + @unittest.skipIf(xr.device_type() != 'TPU', "This test only works on TPU.") + def test_gmm_backward(self): + self._init_test_cases() + for test_case in self.tests_cases: + num_groups = test_case['num_groups'] + k = test_case['k'] + m = test_case['m'] + n = test_case['n'] + lhs_dtype = rhs_dtype = torch.bfloat16 + + lhs = torch.rand(m, k, dtype=lhs_dtype, requires_grad=True) + rhs = torch.rand(num_groups, k, n, dtype=rhs_dtype, requires_grad=True) + group_sizes = self._group_sizes_strategy(m=m, num_groups=num_groups) + lhs.retain_grad() + rhs.retain_grad() + + ref_out = self._reference_gmm(lhs, rhs, group_sizes) + ref_out.sum().backward() + + ref_out_backward = torch.ones_like(ref_out) + grad_lhs, grad_rhs = gmm_backward( + ref_out_backward.to("xla"), lhs.to("xla"), rhs.to("xla"), + group_sizes.to("xla")) + + self.assertTrue(torch.allclose(lhs.grad, grad_lhs.cpu())) + self.assertTrue(torch.allclose(rhs.grad, grad_rhs.cpu())) + + # Make sure gmm doesn't fallback. + self.assertNotIn("aten::", met.short_metrics_report()) + + @unittest.skipIf(xr.device_type() != 'TPU', "This test only works on TPU.") + def test_gmm_backward_2(self): + self._init_test_cases() + for test_case in self.tests_cases: + num_groups = test_case['num_groups'] + k = test_case['k'] + m = test_case['m'] + n = test_case['n'] + lhs_dtype = rhs_dtype = torch.bfloat16 + + torch.manual_seed(42) + lhs = torch.rand(m, k, dtype=lhs_dtype, requires_grad=True) + rhs = torch.rand(num_groups, k, n, dtype=rhs_dtype, requires_grad=True) + group_sizes = self._group_sizes_strategy(m=m, num_groups=num_groups) + lhs.retain_grad() + rhs.retain_grad() + + ref_out = self._reference_gmm(lhs, rhs, group_sizes) + ref_out.sum().backward() + + torch.manual_seed(42) + lhs_xla = torch.rand(m, k, dtype=lhs_dtype, requires_grad=True).to("xla") + rhs_xla = torch.rand( + num_groups, k, n, dtype=rhs_dtype, requires_grad=True).to("xla") + lhs_xla.retain_grad() + rhs_xla.retain_grad() + + out = GMM.apply(lhs_xla, rhs_xla, group_sizes.to("xla")) + out.sum().backward() + + self.assertTrue(torch.allclose(ref_out, out.cpu())) + self.assertTrue(torch.allclose(lhs.grad, lhs_xla.grad.cpu())) + self.assertTrue(torch.allclose(rhs.grad, rhs_xla.grad.cpu())) + + # Make sure gmm doesn't fallback. + self.assertNotIn("aten::", met.short_metrics_report()) + + @unittest.skipIf(xr.device_type() != 'TPU', "This test only works on TPU.") + def test_gmm_backward_3(self): + self._init_test_cases() + for test_case in self.tests_cases: + num_groups = test_case['num_groups'] + k = test_case['k'] + m = test_case['m'] + n = test_case['n'] + lhs_dtype = rhs_dtype = torch.bfloat16 + + torch.manual_seed(42) + lhs = torch.rand(m, k, dtype=lhs_dtype, requires_grad=True) + rhs = torch.rand(num_groups, k, n, dtype=rhs_dtype, requires_grad=True) + group_sizes = self._group_sizes_strategy(m=m, num_groups=num_groups) + lhs.retain_grad() + rhs.retain_grad() + + ref_out = self._reference_gmm(lhs, rhs, group_sizes) + ref_out.sum().backward() + + torch.manual_seed(42) + lhs_xla = torch.rand(m, k, dtype=lhs_dtype, requires_grad=True).to("xla") + rhs_xla = torch.rand( + num_groups, k, n, dtype=rhs_dtype, requires_grad=True).to("xla") + lhs_xla.retain_grad() + rhs_xla.retain_grad() + + out = GMM.apply(lhs_xla, rhs_xla, group_sizes.to("xla")) + grad_out = torch.ones_like(out) + torch.autograd.backward([out], [grad_out, lhs_xla, rhs_xla]) + + self.assertTrue(torch.allclose(ref_out, out.cpu())) + self.assertTrue(torch.allclose(lhs.grad, lhs_xla.grad.cpu())) + self.assertTrue(torch.allclose(rhs.grad, rhs_xla.grad.cpu())) + + # Make sure gmm doesn't fallback. + self.assertNotIn("aten::", met.short_metrics_report()) + + +if __name__ == '__main__': + logging.getLogger().setLevel(logging.INFO) + torch.set_default_dtype(torch.float32) + torch.manual_seed(42) + torch_xla._XLAC._xla_set_use_full_mat_mul_precision( + use_full_mat_mul_precision=True) + test = unittest.main() + sys.exit(0 if test.result.wasSuccessful() else 1) diff --git a/test/test_input_output_aliases.py b/test/test_input_output_aliases.py index c7c04f781c3..b2c5fc50b21 100644 --- a/test/test_input_output_aliases.py +++ b/test/test_input_output_aliases.py @@ -38,6 +38,50 @@ def test_aliasing_with_cloned(self): torch.allclose(t1 - 1, t1_cloned) self.assertEqual(met.metric_data("InputOutputAliasCount")[1], 1.0) + def test_aliasing_across_mark_step(self): + xla_device = xm.xla_device() + met.clear_all() + t1 = torch.randn(4, 5).to(xla_device) + t1 += 1 + xm.mark_step() + self.assertEqual(met.metric_data("InputOutputAliasCount")[1], 1.0) + t1 *= 100 + xm.mark_step() + self.assertEqual(met.metric_data("InputOutputAliasCount")[1], 2.0) + + def test_aliasing_with_multiple_inplace_update(self): + BATCH_SIZE = 1 + SEQ_LEN = 128 + NUM_KV_HEADS = 16 + HEAD_SIZE = 256 + BLOCK_SIZE = 16 + DTYPE = torch.bfloat16 + num_blocks = 1024 + device = xm.xla_device() + key = torch.randn( + BATCH_SIZE * SEQ_LEN, + NUM_KV_HEADS, + HEAD_SIZE, + device=device, + dtype=DTYPE) + k_cache = torch.randn( + num_blocks * BLOCK_SIZE, + NUM_KV_HEADS, + HEAD_SIZE, + device=device, + dtype=DTYPE) + slot_mapping = torch.randint( + 0, num_blocks, (BATCH_SIZE, SEQ_LEN), device=device, dtype=torch.int64) + # materalize k_cache to device data + xm.mark_step() + met.clear_all() + for _ in range(10): + k_cache.index_copy_(0, slot_mapping.flatten(), key) + xm.mark_step() + xm.wait_device_ops() + self.assertEqual(met.metric_data("InputOutputAliasCount")[1], 1.0) + torch.allclose(k_cache[slot_mapping[0][0]].cpu(), key[0].cpu()) + if __name__ == '__main__': test = unittest.main() diff --git a/test/test_metrics.py b/test/test_metrics.py index 87c45949b32..409876d8d9d 100644 --- a/test/test_metrics.py +++ b/test/test_metrics.py @@ -9,6 +9,11 @@ import unittest +def XLAExperimentalContains(feat): + experimental = os.environ.get("XLA_EXPERIMENTAL", "").split(":") + return feat in experimental + + class MetricsTest(unittest.TestCase): def test_clear_counters(self): @@ -205,6 +210,55 @@ def test_pybind_increment_counter(self): torch_xla._XLAC._xla_increment_counter('FakeCounter', 2) self.assertEqual(met.counter_value('FakeCounter'), 2) + def test_get_fallback_ops(self): + + def getAndAssertFallbackOpsLenEquals(count): + fallback_ops = met.executed_fallback_ops() + fallback_ops_number = len(fallback_ops) + self.assertEqual( + fallback_ops_number, + count, + msg=f"found {fallback_ops_number}: {fallback_ops}") + return fallback_ops + + # Reset all metrics, and make sure we don't start with any fallback ops. + met.clear_all() + getAndAssertFallbackOpsLenEquals(0) + + # Create N boxes in the format XYXY. + # This should not run any fallback ops. + N = 10 + x = torch.rand(N, 1).to(xm.xla_device()) + y = torch.rand(N, 1).to(xm.xla_device()) + width = torch.rand(N, 1).to(xm.xla_device()) + height = torch.rand(N, 1).to(xm.xla_device()) + xys = torch.cat((x, x + width, y, y - height), dim=1) + getAndAssertFallbackOpsLenEquals(0) + + # tensor.item() is a fallback operation. + xys[0, 0].item() + ops = getAndAssertFallbackOpsLenEquals(1) + self.assertEqual(ops[0], "aten::_local_scalar_dense") + + # Reset all metrics, and make sure we also don't retrieve any + # fallback operations. + met.clear_all() + getAndAssertFallbackOpsLenEquals(0) + + if not XLAExperimentalContains("nms"): + # Run torchvision operations as fallback. + import torchvision + scores = torch.rand(N).to(xm.xla_device()) + # NMS doesn't have a PyTorch/XLA implementation without dynamic shapes. + torchvision.ops.nms(xys, scores, 0.5) + # remove_small_boxes is not implemented in C++. It calls other PyTorch + # operations. One of them, nonzero, is a fallback operation. + torchvision.ops.remove_small_boxes( + xys, torch.median(torch.stack((width, height)))) + ops = getAndAssertFallbackOpsLenEquals(3) + self.assertEqual( + set(ops), {"aten::nonzero", "aten::median", "torchvision::nms"}) + if __name__ == '__main__': test = unittest.main() diff --git a/test/test_operations.py b/test/test_operations.py index 7fb9f5bc3e3..b4a1838a5a5 100644 --- a/test/test_operations.py +++ b/test/test_operations.py @@ -13,6 +13,7 @@ parser.add_argument('--verbosity', type=int, default=0) FLAGS, leftovers = parser.parse_known_args() sys.argv = [sys.argv[0]] + leftovers +from absl.testing import absltest, parameterized # Normal imports section starts here. import collections @@ -28,6 +29,11 @@ import torch.nn as nn import torch.nn.functional as F import torch.optim as optim +from torch.testing._internal.common_device_type import dtypes +from torch.testing._internal.common_dtype import ( + all_types_and_complex_and, + all_types_and, +) import torch_xla import torch_xla.core.xla_builder as xb import torch_xla.core.xla_op_registry as xor @@ -40,6 +46,7 @@ import torch_xla.distributed.spmd as xs from torch_xla import runtime as xr import torch_xla.test.test_utils as xtu +import torch_xla.utils.dlpack as xdlpack import torch_xla.utils.utils as xu import torch_xla.utils.serialization as xser import torch_xla.core.xla_model as xm @@ -88,6 +95,12 @@ def onlyOnCUDA(fn): return unittest.skipIf(accelerator != "cuda", "PJRT_DEVICE=CUDA required")(fn) +def onlyIfXLAExperimentalContains(feat): + experimental = os.environ.get("XLA_EXPERIMENTAL", "").split(":") + return unittest.skipIf(feat not in experimental, + f"XLA_EXPERIMENTAL={feat} required") + + def _gen_tensor(*args, **kwargs): return torch.randn(*args, **kwargs) @@ -1361,6 +1374,19 @@ def test_fn(t, c): ), dtype=torch.int64) self.runAtenTest([token_type_ids, cat_ids], test_fn) + def test_one_hot_no_fallback(self): + + def test_fn(t): + met.clear_all() + res = F.one_hot(t, num_classes=5) + # make sure there is no graph break + assert 'aten::' not in met.short_metrics_report() + return res + + t1 = torch.arange(0, 5) % 3 + + self.runAtenTest([t1], test_fn) + @skipIfFunctionalizationEnabled("views do not exist") def test_save_view_alias_check(self): @@ -1976,6 +2002,86 @@ def foo(x): for dtype in test_dtypes: test(dtype) + def test_gelu_backward_different_types(self): + + def foo(grad, inp): + return torch.ops.aten.gelu_backward.default(grad, inp) + + grad = torch.rand(10, 10, dtype=torch.bfloat16) + inp = torch.rand(10, 10) + + Xgrad = grad.to(xm.xla_device()) + Xinp = inp.to(xm.xla_device()) + + r = foo(grad, inp) + Xr = foo(Xgrad, Xinp) + + self.assertEqual(r, Xr.cpu()) + + def test_stack_different_types(self): + + def foo(t0, t1): + return torch.stack([t0, t1]) + + t0 = torch.rand(10, 10, dtype=torch.bfloat16) + t1 = torch.rand(10, 10) + + Xt0 = t0.to(xm.xla_device()) + Xt1 = t1.to(xm.xla_device()) + + r = foo(t0, t1) + Xr = foo(Xt0, Xt1) + + self.assertEqual(r, Xr.cpu()) + + def test_index_zero_tensor_by_zero_tensor(self): + + # Test if simple one-tensor indexing works. + # Should return a non-permuted tensor. + def f1(x, i): + return x[i] + + # Test if scattered two-tensor indexing works. + # Should return a permuted tensor, with indexed dimensions first. + def f2(x, i0, i1): + return x[:, i0, :, i1] + + cases = { + f1: [ + ((0,), (0,)), + ((0, 10), (0, 5, 5)), + ((0, 3, 3), (5, 5, 0)), + ], + f2: [ + ((10, 0, 10, 10), (5, 0, 5), (5, 1, 1)), + ((0, 0, 10, 0), (5, 5, 0), (5, 5, 1)), + ] + } + + def make_tensor(shape): + return torch.rand(shape) + + def make_index(shape): + return torch.randint(0, 100, shape, dtype=torch.long) + + def test(f, xshape, ishapes): + x = make_tensor(xshape) + ilist = [make_index(s) for s in ishapes] + + Xx = x.to(xm.xla_device()) + Xilist = [i.to(xm.xla_device()) for i in ilist] + + out = f(x, *ilist) + Xout = f(Xx, *Xilist) + + self.assertEqual(out, Xout.cpu()) + + for xshape, ishape in cases[f1]: + test(f1, xshape, (ishape,)) + + for xshape, i0shape, i1shape in cases[f2]: + test(f2, xshape, (i0shape, i1shape)) + class MNISTComparator(nn.Module): @@ -2416,6 +2522,195 @@ def test_aten_move_scalar_cuda_to_xla(self): # Has a different execution path than other tensors. self._test_move_tensor_cuda_to_xla(torch.tensor(42)) + def test_unsafe_buffer_pointer(self): + xla_device = xm.xla_device() + xla_tensor_0 = torch.tensor(42).to(xla_device) + # `mark_step` ensures xtensor->CurrentDataHandle() != nullptr + xm.mark_step() + buf_ptr_0 = torch_xla._XLAC._unsafe_buffer_pointer(xla_tensor_0) + self.assertGreaterEqual(buf_ptr_0, 0) + + # xtensor->CurrentDataHandle() == nullptr but xtensor->CurrentIrValue().node != nullptr and device_data != nullptr + xla_tensor_1 = torch.tensor(42, device=xm.xla_device()) + buf_ptr_1 = torch_xla._XLAC._unsafe_buffer_pointer(xla_tensor_1) + self.assertGreaterEqual(buf_ptr_1, 0) + + # xtensor->CurrentDataHandle() == nullptr but xtensor->CurrentIrValue().node != nullptr and device_data != nullptr + xla_tensor_2 = torch.ones((5, 5)).to(xla_device) + buf_ptr_2 = torch_xla._XLAC._unsafe_buffer_pointer(xla_tensor_2) + self.assertGreaterEqual(buf_ptr_2, 0) + + xla_tensor_3 = torch.arange(5, device=xm.xla_device()) + xm.mark_step() + # Without the `wait_device_ops()`, the pjrt buffer (pjrt_data->buffer) at https://github.com/pytorch/xla/blob/e3fc03314dab5f44e3ed9ccbba6c15fbca3285cd/torch_xla/csrc/runtime/pjrt_computation_client.cc#L467 will be nullptr. + xm.wait_device_ops() + buf_ptr_3 = torch_xla._XLAC._unsafe_buffer_pointer(xla_tensor_3) + self.assertGreaterEqual(buf_ptr_3, 0) + + +class TestDLPack(parameterized.TestCase): + + def _test_dlpack_capsule_conversion_helper(self, xla_tensor): + dlpt = xdlpack.to_dlpack(xla_tensor) # dlpt1 has type PyCapsule + xla_tensor2 = xdlpack.from_dlpack(dlpt) + + self.assertEqual(xla_tensor.device, xla_tensor2.device) + self.assertTrue(torch.allclose(xla_tensor.cpu(), xla_tensor2.cpu())) + self.assertRaisesRegex(RuntimeError, + "DLTensor capsule can be consumed only once", + lambda: xdlpack.from_dlpack(dlpt)) + + self.assertEqual( + torch_xla._XLAC._unsafe_buffer_pointer(xla_tensor), + torch_xla._XLAC._unsafe_buffer_pointer(xla_tensor2)) + + @onlyIfTorchSupportsCUDA + @onlyIfPJRTDeviceIsCUDA + @parameterized.parameters(*all_types_and(torch.half, torch.bfloat16)) + def test_dlpack_roundtrip_tensor(self, dtype): + xla_device = xm.xla_device() + # xtensor->CurrentDataHandle() == nullptr but xtensor->CurrentIrValue().node != nullptr and device_data != nullptr + # xla_tensor_2 uses XLANativeFunctions::_to_copy + xla_tensor_2 = torch.arange(5, dtype=dtype).to(xla_device) + self._test_dlpack_capsule_conversion_helper(xla_tensor_2) + + # xla_tensor_3 uses arange_out IR node. + xla_tensor_3 = torch.arange(5, dtype=dtype, device=xm.xla_device()) + xm.mark_step() + self._test_dlpack_capsule_conversion_helper(xla_tensor_3) + + @onlyIfTorchSupportsCUDA + @onlyIfPJRTDeviceIsCUDA + @parameterized.parameters(*all_types_and_complex_and(torch.half, + torch.bfloat16, + torch.bool, torch.uint16, + torch.uint32, + torch.uint64)) + def test_dlpack_roundtrip_scalar(self, dtype): + xla_device = xm.xla_device() + xla_tensor_0 = torch.tensor(42, dtype=dtype).to(xla_device) + # `mark_step` ensures xtensor->CurrentDataHandle() != nullptr + xm.mark_step() + self._test_dlpack_capsule_conversion_helper(xla_tensor_0) + + xla_tensor_1 = torch.tensor(42, dtype=dtype).to(xla_device) + # xtensor->CurrentDataHandle() == nullptr but xtensor->CurrentIrValue().node != nullptr and device_data != nullptr + self._test_dlpack_capsule_conversion_helper(xla_tensor_1) + + @onlyIfTorchSupportsCUDA + @onlyIfPJRTDeviceIsCUDA + def test_dlpack_roundtrip_bool(self): + xla_tensor = torch.ones(1, dtype=torch.bool).to(xm.xla_device()) + self._test_dlpack_capsule_conversion_helper(xla_tensor) + + @onlyIfTorchSupportsCUDA + @onlyIfPJRTDeviceIsCUDA + def test_dlpack_pytorch_cuda_to_xla(self): + t1_cuda = torch.arange(5).cuda() + dlt1 = torch.utils.dlpack.to_dlpack(t1_cuda) + xla_t1 = xdlpack.from_dlpack(dlt1) + self.assertEqual(xla_t1.device.type, 'xla') + self.assertEqual(xla_t1.device.index, t1_cuda.device.index) + t1_cuda[0] = t1_cuda[0] + 20 + self.assertTrue(torch.allclose(xla_t1.cpu(), t1_cuda.cpu())) + + t2_cuda = torch.tensor(5).cuda() + dlt2 = torch.utils.dlpack.to_dlpack(t2_cuda) + xla_t2 = xdlpack.from_dlpack(dlt2) + self.assertEqual(xla_t2.device.type, 'xla') + self.assertEqual(xla_t2.device.index, t2_cuda.device.index) + t2_cuda.fill_(6) + self.assertTrue(torch.allclose(xla_t2.cpu(), t2_cuda.cpu())) + + cuda1 = torch.device('cuda:1') + t3_cuda = torch.tensor(5, device=cuda1) + dlt3 = torch.utils.dlpack.to_dlpack(t3_cuda) + xla_t3 = xdlpack.from_dlpack(dlt3) + self.assertEqual(xla_t3.device.type, 'xla') + self.assertEqual( + xla_t3.device.index, + t3_cuda.device.index, + msg='both value should 1. xla_t3.device should be xla:1.') + t3_cuda.fill_(6) + self.assertTrue(torch.allclose(xla_t3.cpu(), t3_cuda.cpu())) + + @onlyIfTorchSupportsCUDA + @onlyIfPJRTDeviceIsCUDA + def test_dlpack_pytorch_cuda_to_xla_protocol_conversion(self): + # Unlike the test_dlpack_pytorch_cuda_to_xla, + # torch_cuda_tensor has attribute __dlpack__ and __dlpack_device__. + # From cuda tensors to xla tensors, the synchronization is handdled implicitly. + t1_cuda = torch.arange(5).cuda() + xla_t1 = xdlpack.from_dlpack(t1_cuda) + self.assertEqual(xla_t1.device.type, 'xla') + self.assertEqual(xla_t1.device.index, t1_cuda.device.index) + t1_cuda[0] = t1_cuda[0] + 20 + self.assertTrue(torch.allclose(xla_t1.cpu(), t1_cuda.cpu())) + + t2_cuda = torch.tensor(5).cuda() + xla_t2 = xdlpack.from_dlpack(t2_cuda) + self.assertEqual(xla_t2.device.type, 'xla') + self.assertEqual(xla_t2.device.index, t2_cuda.device.index) + t2_cuda.fill_(6) + self.assertTrue(torch.allclose(xla_t2.cpu(), t2_cuda.cpu())) + + cuda1 = torch.device('cuda:1') + t3_cuda = torch.tensor(5, device=cuda1) + xla_t3 = xdlpack.from_dlpack(t3_cuda) + self.assertEqual(xla_t3.device.type, 'xla') + self.assertEqual( + xla_t3.device.index, + t3_cuda.device.index, + msg='both value should 1. xla_t3.device should be xla:1.') + t3_cuda.fill_(6) + self.assertTrue(torch.allclose(xla_t3.cpu(), t3_cuda.cpu())) + + @onlyIfTorchSupportsCUDA + @onlyIfPJRTDeviceIsCUDA + def test_dlpack_xla_to_pytorch_cuda(self): + xla_t1 = torch.arange(5).to(xm.xla_device()) + dlt1 = xdlpack.to_dlpack(xla_t1) + cuda_t1 = torch.utils.dlpack.from_dlpack(dlt1) + self.assertEqual(cuda_t1.device.type, 'cuda') + self.assertEqual(cuda_t1.device.index, xla_t1.device.index) + cuda_t1[0] = cuda_t1[0] + 20 + self.assertTrue(torch.allclose(xla_t1.cpu(), cuda_t1.cpu())) + + @onlyIfTorchSupportsCUDA + @onlyIfPJRTDeviceIsCUDA + def test_dlpack_non_default_layout(self): + cuda_t = torch.arange(25, device=torch.device('cuda')).reshape(5, 5) + + t1 = cuda_t.t() + xla_t1 = xdlpack.from_dlpack(t1.__dlpack__()) + self.assertEqual(xla_t1.device.type, 'xla') + self.assertEqual(xla_t1.device.index, t1.device.index) + self.assertTrue(torch.allclose(t1.cpu(), xla_t1.cpu())) + + t2 = cuda_t[0] + xla_t2 = xdlpack.from_dlpack(t2.__dlpack__()) + self.assertEqual(xla_t2.device.type, 'xla') + self.assertEqual(xla_t2.device.index, t2.device.index) + self.assertTrue(torch.allclose(t2.cpu(), xla_t2.cpu())) + + t3 = cuda_t[:, 0] + self.assertRaisesRegex( + RuntimeError, + r"Only DLPack tensors with trivial \(compact\) striding are supported", + lambda: xdlpack.from_dlpack(t3.__dlpack__())) + + t4 = cuda_t[1, :] + xla_t4 = xdlpack.from_dlpack(t4.__dlpack__()) + self.assertEqual(xla_t4.device.type, 'xla') + self.assertEqual(xla_t4.device.index, t4.device.index) + self.assertTrue(torch.allclose(t4.cpu(), xla_t4.cpu())) + + t5 = cuda_t[1] + xla_t5 = xdlpack.from_dlpack(t5.__dlpack__()) + self.assertEqual(xla_t5.device.type, 'xla') + self.assertEqual(xla_t5.device.index, t5.device.index) + self.assertTrue(torch.allclose(t5.cpu(), xla_t5.cpu())) + class SimpleModelWithDropout(torch.nn.Module): @@ -2454,6 +2749,7 @@ def test_dropout(self): # These tests were extracted and adapted from torchvision. # Source: vision/test/test_ops.py +@onlyIfXLAExperimentalContains("nms") class TestNMS(test_utils.XlaTestCase): def _reference_nms(self, boxes, scores, iou_threshold): @@ -2530,6 +2826,54 @@ def fn(boxes, scores): self.runAtenTest((boxes, scores), fn) +class TestHelperFunction(test_utils.XlaTestCase): + + def test_repeat_truncated(self): + from torch_xla.experimental.custom_kernel import repeat_with_fixed_output_size + met.clear_all() + device = torch_xla.device() + total_repeat_length = 20 + input = torch.randn(10).to(device) + repeats = torch.tensor([0, 1, 2, 0, 4, 0, 6, 7, 8, 9]).to(device) + res = repeat_with_fixed_output_size(input, repeats, total_repeat_length) + # make sure there is no graph break + assert 'aten::' not in met.short_metrics_report() + expected = torch.repeat_interleave(input, repeats)[:total_repeat_length] + self.assertTrue(torch.allclose(res.cpu(), expected.cpu())) + + def test_repeat_extended(self): + from torch_xla.experimental.custom_kernel import repeat_with_fixed_output_size + met.clear_all() + device = torch_xla.device() + total_repeat_length = 100 + input = torch.randn(10).to(device) + repeats = torch.tensor([0, 5, 2, 0, 4, 9, 6, 7, 8, 0]).to(device) + res = repeat_with_fixed_output_size(input, repeats, total_repeat_length) + # make sure there is no graph break + assert 'aten::' not in met.short_metrics_report() + base = torch.repeat_interleave(input, repeats)[:total_repeat_length] + # remaining space will be filled with last value in `input`. + expected = torch.cat( + (base, + torch.repeat_interleave(input[-1], + total_repeat_length - base.size()[0]))) + self.assertTrue(torch.allclose(res.cpu(), expected.cpu())) + + def test_repeat_special(self): + from torch_xla.experimental.custom_kernel import repeat_with_fixed_output_size + met.clear_all() + device = torch_xla.device() + total_repeat_length = 135 + num_groups = 8 + input = torch.arange(num_groups, dtype=torch.int32).to(device) + repeats = torch.tensor([3, 6, 2, 14, 27, 47, 8, 28]).to(device) + res = repeat_with_fixed_output_size(input, repeats, total_repeat_length) + # make sure there is no graph break + assert 'aten::' not in met.short_metrics_report() + expected = torch.repeat_interleave(input, repeats)[:total_repeat_length] + self.assertTrue(torch.allclose(res.cpu(), expected.cpu())) + + if __name__ == '__main__': torch.set_default_dtype(torch.float32) torch.manual_seed(42) diff --git a/test/test_ops.py b/test/test_ops.py index 12b874593bd..3b098e85f93 100644 --- a/test/test_ops.py +++ b/test/test_ops.py @@ -225,6 +225,7 @@ def __new__(cls, name, variant_test_name=""): AllowedOpInfoEntry('norm', 'fro'), AllowedOpInfoEntry('special.erfcx'), AllowedOpInfoEntry('_native_batch_norm_legit'), + AllowedOpInfoEntry('full'), # Duplicate Redundant entries for this test. # AllowedOpInfoEntry('polygamma', 'polygamma_n_1'), @@ -393,7 +394,7 @@ def _cpu(t): return tuple(map(to_cpu, x)) elif isinstance(x, dict): return {k: to_cpu(v) for k, v in x.items()} - elif isinstance(x, (numbers.Number, bool, str)): + elif isinstance(x, (numbers.Number, bool, str, torch.dtype)): return x # Passthrough None because some functions wrapped with type promotion @@ -426,5 +427,4 @@ def test_reference_eager(self, device, dtype, op): instantiate_device_type_tests(TestOpInfo, globals()) if __name__ == '__main__': - #run_tests() unittest.main() diff --git a/test/test_pallas.py b/test/test_pallas.py index 2902b5e21ba..25c487912cf 100644 --- a/test/test_pallas.py +++ b/test/test_pallas.py @@ -10,6 +10,8 @@ from torch_xla import runtime as xr from torch_xla._internal import tpu +import numpy as np + if xr.device_type() == 'TPU': from torch_xla.experimental.custom_kernel import jax_import_guard jax_import_guard() @@ -20,12 +22,52 @@ class PallasTest(unittest.TestCase): - def _attention(self, q, k, v): + # This is to create a diagonal mask where only elements within the same segment + # can attend to each other. Since the mask is to mask out the unrelevant parts, + # therefore we use != instead of ==. + def _make_attention_mask_from_segment_ids(self, q_segment_ids, + kv_segment_ids): + return q_segment_ids.view(q_segment_ids.shape[0], 1, + q_segment_ids.shape[1], 1) != kv_segment_ids.view( + kv_segment_ids.shape[0], 1, 1, + kv_segment_ids.shape[1]) + + def _attention(self, q, k, v, *, attn_mask=None): attn_weight = q @ k.transpose(-2, -1) + if attn_mask is not None: + # Masked out the unrelevant parts. + attn_weight = attn_weight.masked_fill(attn_mask, + torch.finfo(attn_weight.dtype).min) attn_weight = nn.functional.softmax(attn_weight, dim=-1) attn_output = attn_weight @ v return attn_output + # The following helper functions prefixed with _pagedattention are used for PagedAttention unit tests + # Reference: https://github.com/google/jax/blob/main/tests/pallas/paged_attention_kernel_test.py + def _pagedattention_generate_qkv( + self, + seq_lens, + page_size, + max_seq_len, + num_kv_heads, + num_heads, + head_dim, + dtype=torch.float32, + ): + assert max_seq_len % page_size == 0 + pages_per_sequence = max_seq_len // page_size + batch_size = len(seq_lens) + total_pages = batch_size * pages_per_sequence + k_pages = torch.randn( + num_kv_heads, total_pages, page_size, head_dim, dtype=dtype) + v_pages = torch.randn( + num_kv_heads, total_pages, page_size, head_dim, dtype=dtype) + page_indices = torch.randperm( + batch_size * pages_per_sequence, dtype=torch.int32) + page_indices = page_indices.reshape(batch_size, pages_per_sequence) + q = torch.randn(batch_size, num_heads, head_dim, dtype=dtype) + return q, k_pages, v_pages, page_indices + @unittest.skipIf(xr.device_type() != 'TPU', "This test only works on TPU.") def test_tpu_custom_call_pallas_add(self): # This payload is generated by the following Pallas code: @@ -417,6 +459,7 @@ def test__flash_attention_bwd_dkv(self): @unittest.skipIf(xr.device_type() != 'TPU' or tpu.version() < 3, "This test only works on TPUv3+.") def test_flash_attention_backward(self): + jax.config.update('jax_default_matmul_precision', jax.lax.Precision.HIGHEST) from torch_xla.experimental.custom_kernel import flash_attention torch.manual_seed(42) @@ -449,9 +492,375 @@ def test_flash_attention_backward(self): loss.backward() xm.mark_step() - mse = torch.nn.MSELoss() for i in [(q, q_grad), (k, k_grad), (v, v_grad)]: - self.assertTrue(mse(i[0].grad.cpu(), i[1].cpu()) < 1e-4) + self.assertTrue(torch.allclose(i[0].grad.cpu(), i[1].cpu(), atol=1e-05)) + jax.config.update('jax_default_matmul_precision', jax.lax.Precision.DEFAULT) + + @unittest.skipIf(xr.device_type() != 'TPU' or tpu.version() < 4, + "This test only works on TPUv4+.") + def test_paged_attention_wrapper(self): + from torch_xla.experimental.custom_kernel import paged_attention + from jax.experimental.pallas.ops.tpu.paged_attention.paged_attention_kernel import paged_attention as jax_paged_attention + + max_kv_len = 2048 + block_size = 512 + page_size = 64 + num_kv_heads = 8 + q_kv_head_ratio = 8 + head_dim = 256 + dtype = torch.float32 + seq_lens = torch.tensor([0, 3, 256, 513, 1023, 2048], dtype=torch.int32) + + q, k_pages, v_pages, page_indices = self._pagedattention_generate_qkv( + seq_lens, + page_size, + max_kv_len, + num_kv_heads, + num_kv_heads * q_kv_head_ratio, + head_dim, + ) + + q_xla = q.to("xla") + k_pages_xla = k_pages.to("xla") + v_pages_xla = v_pages.to("xla") + seq_lens_xla = seq_lens.to("xla") + page_indices_xla = page_indices.to("xla") + + output = paged_attention( + q_xla, + k_pages_xla, + v_pages_xla, + seq_lens_xla, + page_indices_xla, + pages_per_compute_block=block_size // page_size, + ) + + q_jax = jnp.array(q.numpy(), dtype=jnp.float32) + k_pages_jax = jnp.array(k_pages.numpy(), dtype=jnp.float32) + v_pages_jax = jnp.array(v_pages.numpy(), dtype=jnp.float32) + seq_lens_jax = jnp.array(seq_lens.numpy(), dtype=jnp.int32) + page_indices_jax = jnp.array(page_indices.numpy(), dtype=jnp.int32) + expected_output = torch.from_numpy( + np.array( + jax_paged_attention( + q_jax, + k_pages_jax, + v_pages_jax, + seq_lens_jax, + page_indices_jax, + pages_per_compute_block=block_size // page_size, + ))) + + self.assertTrue( + torch.allclose( + output.cpu()[seq_lens > 0], + expected_output.cpu()[seq_lens > 0], + atol=1e-5, + rtol=1e-5)) + + @unittest.skipIf(xr.device_type() != 'TPU' or tpu.version() < 4, + "This test only works on TPUv4+.") + def test_paged_attention_wrapper_with_megacore_modes(self): + from torch_xla.experimental.custom_kernel import paged_attention + from jax.experimental.pallas.ops.tpu.paged_attention.paged_attention_kernel import paged_attention as jax_paged_attention + + max_kv_len = 2048 + block_size = 512 + page_size = 64 + num_kv_heads = 8 + q_kv_head_ratio = 8 + head_dim = 256 + dtype = torch.float32 + seq_lens = torch.tensor([0, 3, 256, 513, 1023, 2048], dtype=torch.int32) + + q, k_pages, v_pages, page_indices = self._pagedattention_generate_qkv( + seq_lens, + page_size, + max_kv_len, + num_kv_heads, + num_kv_heads * q_kv_head_ratio, + head_dim, + ) + + q_xla = q.to("xla") + k_pages_xla = k_pages.to("xla") + v_pages_xla = v_pages.to("xla") + seq_lens_xla = seq_lens.to("xla") + page_indices_xla = page_indices.to("xla") + + outputs = [] + for megacore_mode in ['kv_head', 'batch', None]: + outputs.append( + paged_attention( + q_xla, + k_pages_xla, + v_pages_xla, + seq_lens_xla, + page_indices_xla, + pages_per_compute_block=block_size // page_size, + megacore_mode=megacore_mode)) + + q_jax = jnp.array(q.numpy(), dtype=jnp.float32) + k_pages_jax = jnp.array(k_pages.numpy(), dtype=jnp.float32) + v_pages_jax = jnp.array(v_pages.numpy(), dtype=jnp.float32) + seq_lens_jax = jnp.array(seq_lens.numpy(), dtype=jnp.int32) + page_indices_jax = jnp.array(page_indices.numpy(), dtype=jnp.int32) + expected_outputs = [] + for megacore_mode in ['kv_head', 'batch', None]: + expected_outputs.append( + torch.from_numpy( + np.array( + jax_paged_attention( + q_jax, + k_pages_jax, + v_pages_jax, + seq_lens_jax, + page_indices_jax, + pages_per_compute_block=block_size // page_size, + megacore_mode=megacore_mode)))) + + for output, expected_output in zip(outputs, expected_outputs): + self.assertTrue( + torch.allclose( + output.cpu()[seq_lens > 0], + expected_output.cpu()[seq_lens > 0], + atol=1e-5, + rtol=1e-5)) + + @unittest.skipIf(xr.device_type() != 'TPU' or tpu.version() < 4, + "This test only works on TPUv4+.") + def test_paged_attention_wrapper_with_dynamo(self): + from torch_xla.experimental.custom_kernel import paged_attention + from jax.experimental.pallas.ops.tpu.paged_attention.paged_attention_kernel import paged_attention as jax_paged_attention + + max_kv_len = 2048 + block_size = 512 + page_size = 64 + num_kv_heads = 8 + q_kv_head_ratio = 8 + head_dim = 256 + dtype = torch.float32 + seq_lens = torch.tensor([0, 3, 256, 513, 1023, 2048], dtype=torch.int32) + + q, k_pages, v_pages, page_indices = self._pagedattention_generate_qkv( + seq_lens, + page_size, + max_kv_len, + num_kv_heads, + num_kv_heads * q_kv_head_ratio, + head_dim, + ) + + q_xla = q.to("xla") + k_pages_xla = k_pages.to("xla") + v_pages_xla = v_pages.to("xla") + seq_lens_xla = seq_lens.to("xla") + page_indices_xla = page_indices.to("xla") + + def paged_attention_wrapper(q, k, v, seq_lens, page_indices, + pages_per_compute_block): + return torch.ops.xla.paged_attention( + q, + k, + v, + seq_lens, + page_indices, + pages_per_compute_block=pages_per_compute_block, + ) + + compiled_paged_attention = torch.compile( + paged_attention_wrapper, backend="openxla") + + output = compiled_paged_attention( + q_xla, + k_pages_xla, + v_pages_xla, + seq_lens_xla, + page_indices_xla, + pages_per_compute_block=block_size // page_size, + ) + + q_jax = jnp.array(q.numpy(), dtype=jnp.float32) + k_pages_jax = jnp.array(k_pages.numpy(), dtype=jnp.float32) + v_pages_jax = jnp.array(v_pages.numpy(), dtype=jnp.float32) + seq_lens_jax = jnp.array(seq_lens.numpy(), dtype=jnp.int32) + page_indices_jax = jnp.array(page_indices.numpy(), dtype=jnp.int32) + expected_output = torch.from_numpy( + np.array( + jax_paged_attention( + q_jax, + k_pages_jax, + v_pages_jax, + seq_lens_jax, + page_indices_jax, + pages_per_compute_block=block_size // page_size, + ))) + + self.assertTrue( + torch.allclose( + output.cpu()[seq_lens > 0], + expected_output.cpu()[seq_lens > 0], + atol=1e-5, + rtol=1e-5)) + + @unittest.skipIf(xr.device_type() != 'TPU' or tpu.version() < 3, + "This test only works on TPUv3+.") + def test_flash_attention_wrapper_segment_ids_1(self): + from torch_xla.experimental.custom_kernel import flash_attention + from jax.experimental.pallas.ops.tpu.flash_attention import flash_attention as jax_flash_attention, SegmentIds + + q = torch.randn(3, 2, 128, 4) + k = torch.randn(3, 2, 128, 4) + v = torch.randn(3, 2, 128, 4) + zeros = torch.zeros(3, 32) + segment_ids = torch.cat([zeros, zeros + 1, zeros + 2, zeros + 3], dim=1) + o = flash_attention( + q.to("xla"), k.to("xla"), v.to("xla"), False, segment_ids.to("xla"), + segment_ids.to("xla")) + + jax_q = jnp.array(q.numpy(), dtype=jnp.float32) + jax_k = jnp.array(k.numpy(), dtype=jnp.float32) + jax_v = jnp.array(v.numpy(), dtype=jnp.float32) + jax_segment_ids = jnp.array(segment_ids.numpy(), dtype=jnp.float32) + expected_o = torch.from_numpy( + np.array( + jax_flash_attention( + jax_q, + jax_k, + jax_v, + segment_ids=SegmentIds(jax_segment_ids, jax_segment_ids), + ))) + + self.assertTrue(torch.allclose(o.cpu(), expected_o.cpu(), atol=1e-05)) + + @unittest.skipIf(xr.device_type() != 'TPU' or tpu.version() < 3, + "This test only works on TPUv3+.") + def test_flash_attention_wrapper_segment_ids_2(self): + jax.config.update('jax_default_matmul_precision', jax.lax.Precision.HIGHEST) + from torch_xla.experimental.custom_kernel import flash_attention + + q = torch.randn(3, 2, 128, 4).to("xla") + k = torch.randn(3, 2, 128, 4).to("xla") + v = torch.randn(3, 2, 128, 4).to("xla") + zeros = torch.zeros(3, 32).to("xla") + segment_ids = torch.cat([zeros, zeros + 1, zeros + 2, zeros + 3], dim=1) + o = flash_attention(q, k, v, False, segment_ids, segment_ids) + + expected_o = self._attention( + q, + k, + v, + attn_mask=self._make_attention_mask_from_segment_ids( + segment_ids, segment_ids)) + self.assertTrue(torch.allclose(o.cpu(), expected_o.cpu(), atol=1e-05)) + jax.config.update('jax_default_matmul_precision', jax.lax.Precision.DEFAULT) + + @unittest.skipIf(xr.device_type() != 'TPU' or tpu.version() < 3, + "This test only works on TPUv3+.") + def test_flash_attention_backward_segment_ids(self): + jax.config.update('jax_default_matmul_precision', jax.lax.Precision.HIGHEST) + from torch_xla.experimental.custom_kernel import flash_attention + + torch.manual_seed(42) + q = torch.randn(4, 2, 128, 8, requires_grad=True).to("xla") + k = torch.randn(4, 2, 128, 8, requires_grad=True).to("xla") + v = torch.randn(4, 2, 128, 8, requires_grad=True).to("xla") + zeros = torch.zeros(4, 32).to("xla") + segment_ids = torch.cat([zeros, zeros + 1, zeros + 2, zeros + 3], dim=1) + q.retain_grad() + k.retain_grad() + v.retain_grad() + + o = flash_attention(q, k, v, False, segment_ids, segment_ids) + loss = o.sum() + loss.backward() + xm.mark_step() + + q_grad = q.grad + k_grad = k.grad + v_grad = v.grad + + torch.manual_seed(42) + q = torch.randn(4, 2, 128, 8, requires_grad=True).to("xla") + k = torch.randn(4, 2, 128, 8, requires_grad=True).to("xla") + v = torch.randn(4, 2, 128, 8, requires_grad=True).to("xla") + zeros = torch.zeros(4, 32).to("xla") + segment_ids = torch.cat([zeros, zeros + 1, zeros + 2, zeros + 3], dim=1) + q.retain_grad() + k.retain_grad() + v.retain_grad() + + o = self._attention( + q, + k, + v, + attn_mask=self._make_attention_mask_from_segment_ids( + segment_ids, segment_ids)) + loss = o.sum() + loss.backward() + xm.mark_step() + + for i in [(q, q_grad), (k, k_grad), (v, v_grad)]: + self.assertTrue(torch.allclose(i[0].grad.cpu(), i[1].cpu(), atol=1e-05)) + jax.config.update('jax_default_matmul_precision', jax.lax.Precision.DEFAULT) + + @unittest.skipIf(xr.device_type() != 'TPU' or tpu.version() < 3, + "This test only works on TPUv3+.") + def test_flash_attention_wrapper_sm_scale(self): + jax.config.update('jax_default_matmul_precision', jax.lax.Precision.HIGHEST) + from torch_xla.experimental.custom_kernel import flash_attention + + q = torch.randn(3, 2, 128, 4).to("xla") + k = torch.randn(3, 2, 128, 4).to("xla") + v = torch.randn(3, 2, 128, 4).to("xla") + sm_scale = 0.7 + o = flash_attention(q, k, v, False, None, None, sm_scale) + + expected_o = self._attention(q * sm_scale, k, v) + self.assertTrue(torch.allclose(o.cpu(), expected_o.cpu(), atol=1e-05)) + jax.config.update('jax_default_matmul_precision', jax.lax.Precision.DEFAULT) + + @unittest.skipIf(xr.device_type() != 'TPU' or tpu.version() < 3, + "This test only works on TPUv3+.") + def test_flash_attention_sm_scale_backward(self): + jax.config.update('jax_default_matmul_precision', jax.lax.Precision.HIGHEST) + from torch_xla.experimental.custom_kernel import flash_attention + + torch.manual_seed(42) + q = torch.randn(4, 2, 128, 8, requires_grad=True).to("xla") + k = torch.randn(4, 2, 128, 8, requires_grad=True).to("xla") + v = torch.randn(4, 2, 128, 8, requires_grad=True).to("xla") + sm_scale = 0.7 + q.retain_grad() + k.retain_grad() + v.retain_grad() + + o = flash_attention(q, k, v, False, None, None, sm_scale) + loss = o.sum() + loss.backward() + xm.mark_step() + + q_grad = q.grad + k_grad = k.grad + v_grad = v.grad + + torch.manual_seed(42) + q = torch.randn(4, 2, 128, 8, requires_grad=True).to("xla") + k = torch.randn(4, 2, 128, 8, requires_grad=True).to("xla") + v = torch.randn(4, 2, 128, 8, requires_grad=True).to("xla") + q.retain_grad() + k.retain_grad() + v.retain_grad() + + o = self._attention(q * sm_scale, k, v) + loss = o.sum() + loss.backward() + xm.mark_step() + + # Hmm, the gradients are the same even the autograd graph seems different. + for i in [(q, q_grad), (k, k_grad), (v, v_grad)]: + self.assertTrue(torch.allclose(i[0].grad.cpu(), i[1].cpu(), atol=1e-05)) + jax.config.update('jax_default_matmul_precision', jax.lax.Precision.DEFAULT) if __name__ == '__main__': diff --git a/test/test_pallas_spmd.py b/test/test_pallas_spmd.py new file mode 100644 index 00000000000..33434594191 --- /dev/null +++ b/test/test_pallas_spmd.py @@ -0,0 +1,110 @@ +import logging +import os +import unittest + +import torch +from torch import nn as nn + +import torch_xla +import torch_xla.core.xla_model as xm +import torch_xla.distributed.spmd as xs +from torch_xla import runtime as xr +from torch_xla._internal import tpu + +if xr.device_type() == 'TPU': + from torch_xla.experimental.custom_kernel import flash_attention + from torch_xla.experimental.custom_kernel import jax_import_guard + jax_import_guard() + import jax + import jax.numpy as jnp + from jax.experimental import pallas as pl + + +class PallasTest(unittest.TestCase): + + def _attention(self, q, k, v): + attn_weight = q @ k.transpose(-2, -1) + attn_weight = nn.functional.softmax(attn_weight, dim=-1) + attn_output = attn_weight @ v + return attn_output + + @unittest.skipIf(xr.device_type() != 'TPU' or tpu.version() < 3, + "This test only works on TPUv3+.") + def test_flash_attention_spmd_data_parallel(self): + jax.config.update('jax_default_matmul_precision', jax.lax.Precision.HIGHEST) + n_devices = xr.global_runtime_device_count() + xs.set_global_mesh(xs.Mesh(range(n_devices), (n_devices, 1, 1, 1))) + + q = torch.randn(4, 2, 128, 4).to("xla") + k = torch.randn(4, 2, 128, 4).to("xla") + v = torch.randn(4, 2, 128, 4).to("xla") + + o = flash_attention(q, k, v, partition_spec=range(n_devices)) + self.assertEqual( + torch_xla._XLAC._get_xla_sharding_spec(o), + f"{{devices=[{n_devices},1,1,1]0,1,2,3}}") + + expected_o = self._attention(q, k, v) + self.assertTrue(torch.allclose(o.cpu(), expected_o.cpu(), atol=1e-05)) + jax.config.update('jax_default_matmul_precision', jax.lax.Precision.DEFAULT) + + @unittest.skipIf(xr.device_type() != 'TPU' or tpu.version() < 3, + "This test only works on TPUv3+.") + def test_flash_attention_backward_spmd_data_parallel(self): + jax.config.update('jax_default_matmul_precision', jax.lax.Precision.HIGHEST) + n_devices = xr.global_runtime_device_count() + xs.set_global_mesh(xs.Mesh(range(n_devices), (n_devices, 1, 1, 1))) + + torch.manual_seed(42) + q = torch.randn(4, 2, 128, 8, requires_grad=True).to("xla") + k = torch.randn(4, 2, 128, 8, requires_grad=True).to("xla") + v = torch.randn(4, 2, 128, 8, requires_grad=True).to("xla") + q.retain_grad() + k.retain_grad() + v.retain_grad() + + o = flash_attention(q, k, v, partition_spec=range(n_devices)) + loss = o.sum() + loss.backward() + xm.mark_step() + + q_grad = q.grad + k_grad = k.grad + v_grad = v.grad + self.assertEqual( + torch_xla._XLAC._get_xla_sharding_spec(q_grad), + f"{{devices=[{n_devices},1,1,1]0,1,2,3}}") + self.assertEqual( + torch_xla._XLAC._get_xla_sharding_spec(k_grad), + f"{{devices=[{n_devices},1,1,1]0,1,2,3}}") + self.assertEqual( + torch_xla._XLAC._get_xla_sharding_spec(v_grad), + f"{{devices=[{n_devices},1,1,1]0,1,2,3}}") + + torch.manual_seed(42) + q = torch.randn(4, 2, 128, 8, requires_grad=True).to("xla") + k = torch.randn(4, 2, 128, 8, requires_grad=True).to("xla") + v = torch.randn(4, 2, 128, 8, requires_grad=True).to("xla") + q.retain_grad() + k.retain_grad() + v.retain_grad() + + o = self._attention(q, k, v) + loss = o.sum() + loss.backward() + xm.mark_step() + + for i in [(q, q_grad), (k, k_grad), (v, v_grad)]: + self.assertTrue(torch.allclose(i[0].grad.cpu(), i[1].cpu(), atol=1e-05)) + jax.config.update('jax_default_matmul_precision', jax.lax.Precision.DEFAULT) + + +if __name__ == '__main__': + logging.getLogger().setLevel(logging.INFO) + torch.set_default_dtype(torch.float32) + torch.manual_seed(42) + torch_xla._XLAC._xla_set_use_full_mat_mul_precision( + use_full_mat_mul_precision=True) + xr.use_spmd() + test = unittest.main() + sys.exit(0 if test.result.wasSuccessful() else 1) diff --git a/test/tpu/Dockerfile b/test/tpu/Dockerfile index 6a1a9520b58..8acbdf818f4 100644 --- a/test/tpu/Dockerfile +++ b/test/tpu/Dockerfile @@ -3,12 +3,12 @@ FROM us-central1-docker.pkg.dev/tpu-pytorch-releases/docker/development:tpu as b # Replace value with the latest runner release version # source: https://github.com/actions/runner/releases # ex: 2.303.0 -ARG RUNNER_VERSION="2.314.1" +ARG RUNNER_VERSION="2.316.1" ARG RUNNER_ARCH="x64" # Replace value with the latest runner-container-hooks release version # source: https://github.com/actions/runner-container-hooks/releases # ex: 0.3.1 -ARG RUNNER_CONTAINER_HOOKS_VERSION="0.5.1" +ARG RUNNER_CONTAINER_HOOKS_VERSION="0.6.0" ARG USER=runner diff --git a/test/tpu/run_tests.sh b/test/tpu/run_tests.sh index 413951854d6..fc4024a462c 100755 --- a/test/tpu/run_tests.sh +++ b/test/tpu/run_tests.sh @@ -11,15 +11,20 @@ python3 test/spmd/test_xla_distributed_checkpoint.py python3 test/spmd/test_train_spmd_linear_model.py python3 test/spmd/test_xla_spmd_python_api_interaction.py python3 test/spmd/test_xla_auto_sharding.py -XLA_EXPERIMENTAL=nonzero:masked_select python3 test/ds/test_dynamic_shape_models.py -v -XLA_EXPERIMENTAL=nonzero:masked_select python3 test/ds/test_dynamic_shapes.py -v +python3 test/spmd/test_fsdp_v2.py +XLA_EXPERIMENTAL=nonzero:masked_select:nms python3 test/ds/test_dynamic_shape_models.py -v +XLA_EXPERIMENTAL=nonzero:masked_select:nms python3 test/ds/test_dynamic_shapes.py -v python3 test/test_autocast.py +python3 test/test_grad_checkpoint.py python3 test/dynamo/test_dynamo.py python3 test/spmd/test_spmd_debugging.py python3 test/pjrt/test_dtypes.py python3 test/pjrt/test_dynamic_plugin_tpu.py python3 test/test_fori_loop_with_while_loop_simple_add_dispatch_in_torch.py python3 test/test_pallas.py +python3 test/test_pallas_spmd.py +python3 test/test_input_output_aliases.py +python3 test/test_gmm.py python3 test/torch_distributed/test_torch_distributed_all_gather_xla_backend.py python3 test/torch_distributed/test_torch_distributed_all_reduce_xla_backend.py python3 test/torch_distributed/test_torch_distributed_multi_all_reduce_xla_backend.py diff --git a/torch_patches/README.md b/torch_patches/README.md deleted file mode 100644 index f6476f64ca5..00000000000 --- a/torch_patches/README.md +++ /dev/null @@ -1,32 +0,0 @@ -# Guidelines For Patch File Names - -Files with extension '.diff' are consider as git patches by apply script. - -A file for PyTorch PR _N_ needs to be named 'N.diff'. - -Patch files which are not related to PyTorch PRs, should begin with an 'X' character, -followed by a two digit number, followed by a dash ('-'), a name, and '.diff'. -Example: - -``` -X10-optimizer.diff -``` - -Patch file are alphabetically ordered, so PyTorch PR patches are always applied -before the non PyTorch ones. - - -There's a special file `torch_patches/.torch_pin`, which is used to coordinate landing PRs in -`pytorch/pytorch` and `pytorch/xla`. - -To test a `pytorch/xla` PR against a `pytorch/pytorch` PR or branch, -put the PR number or branch name in this file. -Example: - -``` -#32451 -# or -my_awesome_branch # (must live in `pytorch/pytorch`) -``` - -In the case where the pytorch/pytorch PR also depends on the pytorch/xla PR, you will also need to update the https://github.com/pytorch/pytorch/blob/main/.github/ci_commit_pins/xla.txt to match the latest hash of your pytorch/xla PR. To be noted, the hash from a PR produced by a fork won't work in this case. Then you need to find someone from the pytorch/xla team to produe a branch PR for you. diff --git a/torch_xla/__init__.py b/torch_xla/__init__.py index ebc0af6c7ad..eef6e48bac2 100644 --- a/torch_xla/__init__.py +++ b/torch_xla/__init__.py @@ -6,6 +6,7 @@ import torch import _XLAC from ._internal import tpu +from .version import __version__ logging.basicConfig() logger = logging.getLogger(__name__) @@ -27,8 +28,6 @@ def _set_missing_flags(flags, sets): def _setup_xla_flags(): flags = os.environ.get('XLA_FLAGS', '').split(' ') flags = _set_missing_flags(flags, (('xla_cpu_enable_fast_math', 'false'),)) - flags = _set_missing_flags( - flags, (('xla_gpu_simplify_all_fp_conversions', 'false'),)) flags = _set_missing_flags(flags, (('xla_gpu_force_compilation_parallelism', '8'),)) os.environ['XLA_FLAGS'] = ' '.join(flags) @@ -76,6 +75,8 @@ def _setup_default_env(): os.environ.setdefault('ALLOW_MULTIPLE_LIBTPU_LOAD', '1') os.environ.setdefault('TPU_ML_PLATFORM', 'PyTorch/XLA') + # This is used for ML Framework Telemetry. + os.environ.setdefault('TPU_ML_PLATFORM_VERSION', __version__) if tpu.version() == 4: os.environ.setdefault('TPU_MEGACORE', 'megacore_dense') @@ -149,7 +150,6 @@ def _setup_tpu_vm_library_path() -> bool: import atexit from ._patched_functions import _apply_patches -from .version import __version__ _found_libtpu = _setup_tpu_vm_library_path() @@ -186,6 +186,27 @@ def _init_xla_lazy_backend(): # TODO @wonjoo come up with a long term fix in Dynamo. torch._dynamo.config.automatic_dynamic_shapes = False +# Activate view-replay on AOTAutograd. +# See: https://github.com/pytorch/pytorch/pull/124488 +import torch._functorch.config + +torch._functorch.config.view_replay_for_aliased_outputs = True + +import importlib.metadata +import warnings + +try: + # TensorFlow TPU distribution has the same package name as GPU, but not CPU + dist = importlib.metadata.distribution('tensorflow') + warnings.warn( + "`tensorflow` can conflict with `torch-xla`. Prefer `tensorflow-cpu` when" + " using PyTorch/XLA. To silence this warning, `pip uninstall -y " + "tensorflow && pip install tensorflow-cpu`. If you are in a notebook " + "environment such as Colab or Kaggle, restart your notebook runtime " + "afterwards.") +except importlib.metadata.PackageNotFoundError: + pass + from .stablehlo import save_as_stablehlo, save_torch_model_as_stablehlo from .experimental import plugins diff --git a/torch_xla/core/dynamo_bridge.py b/torch_xla/core/dynamo_bridge.py index 624acb9cb6f..f6d7a3b6e00 100644 --- a/torch_xla/core/dynamo_bridge.py +++ b/torch_xla/core/dynamo_bridge.py @@ -100,15 +100,7 @@ def __call__(self, args): def get_fallback_ops(): - fallback_ops = [] - for opname in metrics.counter_names(): - if "aten::" not in opname: - continue - val = int(metrics.counter_value(opname)) - if val > 0: - fallback_ops.append(f"{opname}={val}") - - return fallback_ops + return metrics.executed_fallback_ops() # Checks that all input args that are tensors are on the same device. diff --git a/torch_xla/core/xla_model.py b/torch_xla/core/xla_model.py index 7591e13af29..149aa99b67d 100644 --- a/torch_xla/core/xla_model.py +++ b/torch_xla/core/xla_model.py @@ -7,7 +7,7 @@ import threading import time import warnings -from typing import List, Optional +from typing import List, Optional, TypedDict import torch import torch.distributed._functional_collectives from torch.library import Library @@ -1434,15 +1434,19 @@ def fork_rng(device=None, enabled=True): set_rng_state(xla_rng_state, device=device) -def get_memory_info(device): - """Retrieves the device memory information. +class MemoryInfo(TypedDict): + bytes_used: str + bytes_limit: int + + +def get_memory_info(device: torch.device) -> MemoryInfo: + """Retrieves the device memory usage. Args: - device (string): The device whose memory information are requested. + device: The device whose memory information are requested. Returns: - A dictionary with `kb_free` (free memory in KB) and `kb_total` (total - memory in KB) keys. + MemoryInfo dict with memory usage for the given device. """ return torch_xla._XLAC._xla_memory_info(str(device)) diff --git a/torch_xla/csrc/BUILD b/torch_xla/csrc/BUILD index 2faf483f067..a2aadc0c633 100644 --- a/torch_xla/csrc/BUILD +++ b/torch_xla/csrc/BUILD @@ -42,6 +42,7 @@ ptxla_cc_library( "cross_replica_reduces.cpp", "data_ops.cpp", "debug_util.cpp", + "dl_convertor.cpp", "elementwise.cpp", "helpers.cpp", "ir_dump_util.cpp", @@ -81,6 +82,7 @@ ptxla_cc_library( "cross_replica_reduces.h", "data_ops.h", "debug_util.h", + "dl_convertor.h", "elementwise.h", "generated_file_include.h", "helpers.h", diff --git a/torch_xla/csrc/aten_cpu_fallback.cpp b/torch_xla/csrc/aten_cpu_fallback.cpp index d664c60114f..5e84e61ba1a 100644 --- a/torch_xla/csrc/aten_cpu_fallback.cpp +++ b/torch_xla/csrc/aten_cpu_fallback.cpp @@ -16,6 +16,18 @@ namespace torch_xla { static std::unordered_map _cpu_fallback_counters; +// Get all the executed fallback operations. +// In other words, get all of them whose counters are not zero. +std::vector GetFallbackOperations() { + std::vector fallback; + for (auto const& pair : _cpu_fallback_counters) { + if (pair.second->Value() != 0) { + fallback.push_back(pair.first); + } + } + return fallback; +} + void xla_cpu_fallback(const c10::OperatorHandle& op, torch::jit::Stack* stack) { XLA_FN_TRACK(3); const auto name = c10::toString(op.operator_name()); diff --git a/torch_xla/csrc/aten_cpu_fallback.h b/torch_xla/csrc/aten_cpu_fallback.h index 572d4e1009a..706c7aa40a5 100644 --- a/torch_xla/csrc/aten_cpu_fallback.h +++ b/torch_xla/csrc/aten_cpu_fallback.h @@ -7,6 +7,8 @@ namespace torch_xla { void xla_cpu_fallback(const c10::OperatorHandle& op, torch::jit::Stack* stack); +std::vector GetFallbackOperations(); + } // namespace torch_xla -#endif // XLA_TORCH_XLA_CSRC_ATEN_CPU_FALLBACK_H_ \ No newline at end of file +#endif // XLA_TORCH_XLA_CSRC_ATEN_CPU_FALLBACK_H_ diff --git a/torch_xla/csrc/aten_xla_type.cpp b/torch_xla/csrc/aten_xla_type.cpp index a7ae1c47964..060d52d61d7 100644 --- a/torch_xla/csrc/aten_xla_type.cpp +++ b/torch_xla/csrc/aten_xla_type.cpp @@ -29,6 +29,7 @@ #include "torch_xla/csrc/helpers.h" #include "torch_xla/csrc/ops/as_strided.h" #include "torch_xla/csrc/ops/as_strided_view_update.h" +#include "torch_xla/csrc/ops/device_data.h" #include "torch_xla/csrc/ops/diagonal_view_update.h" #include "torch_xla/csrc/ops/einsum_utilities.h" #include "torch_xla/csrc/ops/index_ops.h" @@ -1290,6 +1291,38 @@ at::Tensor XLANativeFunctions::embedding_dense_backward( num_weights, padding_idx, scale_grad_by_freq)); } +std::tuple +XLANativeFunctions::_embedding_bag_forward_only( + const at::Tensor& weight, const at::Tensor& indices, + const at::Tensor& offsets, bool scale_grad_by_freq, int64_t mode, + bool sparse, const c10::optional& per_sample_weights, + bool include_last_offset, int64_t padding_idx) { + TORCH_LAZY_FN_COUNTER_TIMED_TRACING("xla::"); + if (mode == 1 || scale_grad_by_freq || sparse || padding_idx != -1) { + return at::native::call_fallback_fn< + &xla_cpu_fallback, + ATEN_OP(_embedding_bag_forward_only)>::call(weight, indices, offsets, + scale_grad_by_freq, mode, + sparse, per_sample_weights, + include_last_offset, + padding_idx); + } + auto indices_tensor = bridge::GetXlaTensor(indices); + auto sample_weights = + per_sample_weights.has_value() && per_sample_weights.value().defined() + ? bridge::GetXlaTensor(per_sample_weights.value()) + : tensor_methods::full_like(indices_tensor, 1.0, + *torch_xla::bridge::GetXlaDevice(weight), + at::ScalarType::Float); + auto result = tensor_methods::embedding_bag( + bridge::GetXlaTensor(weight), indices_tensor, + bridge::GetXlaTensor(offsets), mode, sample_weights, include_last_offset); + return std::make_tuple(bridge::AtenFromXlaTensor(std::get<0>(result)), + bridge::AtenFromXlaTensor(std::get<1>(result)), + bridge::AtenFromXlaTensor(std::get<2>(result)), + bridge::AtenFromXlaTensor(std::get<3>(result))); +} + at::Tensor XLANativeFunctions::empty_symint( at::SymIntArrayRef sym_size, c10::optional dtype, c10::optional layout, c10::optional device, @@ -1438,9 +1471,18 @@ at::Tensor XLANativeFunctions::full(at::IntArrayRef size, return at::native::call_fallback_fn<&xla_cpu_fallback, ATEN_OP(full)>::call( size, fill_value, dtype, layout, device, pin_memory); } - return bridge::AtenFromXlaTensor(tensor_methods::full( - absl::Span(size), fill_value, - GetXlaDeviceOrCurrent(device), at::dtype_or_default(dtype))); + at::ScalarType intend_dtype; + if (dtype || fill_value.isFloatingPoint()) { + // Respect the dtype if it is being explictlly passed in. + // All python scalar will be passed in as float64 to the backend, but the + // default behavior for pytorch is to return a float32 tensor in this case. + intend_dtype = at::dtype_or_default(dtype); + } else { + intend_dtype = fill_value.type(); + } + return bridge::AtenFromXlaTensor( + tensor_methods::full(absl::Span(size), fill_value, + GetXlaDeviceOrCurrent(device), intend_dtype)); } at::Tensor XLANativeFunctions::gather(const at::Tensor& self, int64_t dim, @@ -1462,8 +1504,10 @@ at::Tensor XLANativeFunctions::gelu_backward(const at::Tensor& grad, const at::Tensor& self, c10::string_view approximate) { TORCH_LAZY_FN_COUNTER_TIMED_TRACING("xla::"); + at::ScalarType result_type = at::result_type(grad, self); return bridge::AtenFromXlaTensor(tensor_methods::gelu_backward( - bridge::GetXlaTensor(grad), bridge::GetXlaTensor(self), approximate)); + bridge::GetXlaTensor(grad.to(result_type)), + bridge::GetXlaTensor(self.to(result_type)), approximate)); } at::Tensor XLANativeFunctions::hardtanh(const at::Tensor& self, @@ -2497,7 +2541,38 @@ void XLANativeFunctions::_propagate_xla_data(const at::Tensor& input, // 1) Aid XLA's InputOutputAlias. auto input_tensor = bridge::GetXlaTensor(input); auto output_tensor = bridge::GetXlaTensor(output); - output_tensor->data()->alias_id = input_tensor->GetUniqueId(); + if (input_tensor->CurrentDataHandle() != nullptr || + (input_tensor->CurrentIrValue().node != nullptr && + torch_xla::DeviceData::Cast( + input_tensor->CurrentIrValue().node.get()))) { + /* + if input has a XLAData or holds a devicedata node, set alias_id to + tensor_id. Consider the case. + + // x.tensor_id = 1, x.alias_id = 1 + x = torch.randn(5,5).to(xla_device()) + // x.tensor_id = 2, x.alias_id should be 1 + x += 1 + xm.mark_step() + // x.tensor_id =3, x.alias_id should be 2 since input tensor id will be 2 + // for this graph + x *= 1 of 1 + */ + output_tensor->data()->alias_id = input_tensor->GetUniqueId(); + } else { + /* + Consider the case + + // x.tensor_id = 1, x.alias_id = 1 + x = torch.randn(5,5).to(xla_device()) + // x.tensor_id = 2, x.alias_id should be 1 + x += 1 + // x.tensor_id = 3, x.alias_id should still be 1 + x * = 2 + xm.mark_step() + */ + output_tensor->data()->alias_id = input_tensor->data()->alias_id; + } // 2) Aid SPMD. XLATensor::ShardingSpecPtr sharding = input_tensor->sharding_spec(); @@ -3085,8 +3160,12 @@ at::Tensor XLANativeFunctions::squeeze_copy(const at::Tensor& self, at::Tensor XLANativeFunctions::stack(at::TensorList tensors, int64_t dim) { TORCH_LAZY_FN_COUNTER_TIMED_TRACING("xla::"); + at::ScalarType result_type = at::native::result_type(tensors); + std::vector c_tensors(tensors.size()); + std::transform(tensors.begin(), tensors.end(), c_tensors.begin(), + [=](const at::Tensor& t) { return t.to(result_type); }); return bridge::AtenFromXlaTensor( - tensor_methods::stack(bridge::GetXlaTensors(tensors), dim)); + tensor_methods::stack(bridge::GetXlaTensors(c_tensors), dim)); } at::Tensor XLANativeFunctions::std(const at::Tensor& self, bool unbiased) { @@ -3709,6 +3788,7 @@ at::Tensor XLANativeFunctions::embedding_symint(const at::Tensor& weight, scale_grad_by_freq, sparse); } + // TODO: We need to make use of the TPU embedding core here eventually. TORCH_LAZY_FN_COUNTER_TIMED_TRACING("xla::"); return bridge::AtenFromXlaTensor(tensor_methods::embedding( bridge::GetXlaTensor(weight), bridge::GetXlaTensor(indices))); diff --git a/torch_xla/csrc/debug_util.cpp b/torch_xla/csrc/debug_util.cpp index db534dd5292..11843a39a59 100644 --- a/torch_xla/csrc/debug_util.cpp +++ b/torch_xla/csrc/debug_util.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -233,11 +234,25 @@ static bool endsWith(const std::string& str, const std::string& suffix) { 0 == str.compare(str.size() - suffix.size(), suffix.size(), suffix); } +int GetDebugLevel() { + static const bool pt_xla_debug_enabled = + runtime::sys_util::GetEnvBool("PT_XLA_DEBUG", false); + static const int pt_xla_debug_level_env = + runtime::sys_util::GetEnvInt("PT_XLA_DEBUG_LEVEL", -1); + static const int default_debug_level_if_enabled = 100; + // default the pt_xla_debug_level to 100 if PT_XLA_DEBUG is set but + // PT_XLA_DEBUG_LEVEL is not specified. + static const int pt_xla_debug_level = + (pt_xla_debug_level_env == -1) && pt_xla_debug_enabled + ? default_debug_level_if_enabled + : pt_xla_debug_level_env; + return pt_xla_debug_level; +} + void DebugUtil::analyze_graph_execution_python_frame( GraphAnalysisSource source, torch::lazy::hash_t graph_hash, const xla::ProgramShape* program_shape) { - static const bool pt_xla_debug_enabled = - runtime::sys_util::GetEnvBool("PT_XLA_DEBUG", false); + static const int pt_xla_debug_level = GetDebugLevel(); static const bool is_master_process = (runtime::sys_util::GetEnvInt("PJRT_LOCAL_PROCESS_RANK", 0) == 0); static const std::string debug_file_name = @@ -248,7 +263,12 @@ void DebugUtil::analyze_graph_execution_python_frame( static const std::string executation_output_prefix = "Execution Analysis: "; static const std::string compilation_output_prefix = "Compilation Analysis: "; - if (!pt_xla_debug_enabled) { + if (pt_xla_debug_level <= 0) { + return; + } + + if (pt_xla_debug_level <= 1 && source != GraphAnalysisSource::Compilation) { + // for debug level <=1, only output compilation analysis in this function. return; } @@ -355,4 +375,68 @@ void DebugUtil::analyze_graph_execution_python_frame( } } +void DebugUtil::post_compilation_analysis( + runtime::ComputationClient::ComputationPtr computation) { + static const int pt_xla_debug_level = GetDebugLevel(); + static const bool is_master_process = + (runtime::sys_util::GetEnvInt("PJRT_LOCAL_PROCESS_RANK", 0) == 0); + static const std::string debug_file_name = + runtime::sys_util::GetEnvString("PT_XLA_DEBUG_FILE", ""); + if (pt_xla_debug_level <= 0 || !is_master_process) { + return; + } + static const std::string debug_output_prefix = "Post Compilation Analysis: "; + std::stringstream ss; + ss << "\n" + << debug_output_prefix + << "======================================================================" + "==========" + << "\n"; + std::string memory_info = computation->get_memory_info(); + + std::vector keysToExtract = { + "generated_code_size_in_bytes", "argument_size_in_bytes", + "output_size_in_bytes", "alias_size_in_bytes", "temp_size_in_bytes"}; + std::vector sizes_in_gb; + + for (const std::string& key : keysToExtract) { + std::regex pattern(key + "=([0-9]+)"); + std::smatch match; + + if (std::regex_search(memory_info, match, pattern)) { + sizes_in_gb.push_back( + std::to_string(std::stoll(match[1]) * 1.0 / 1024 / 1024 / 1024)); + } else { + sizes_in_gb.push_back("Unknown "); + } + } + + ss << debug_output_prefix << "Graph input size: " << sizes_in_gb[1] + << " GB\n"; + ss << debug_output_prefix << "Graph output size: " << sizes_in_gb[2] + << " GB\n"; + ss << debug_output_prefix << "Aliased Input size: " << sizes_in_gb[3] + << " GB\n"; + ss << debug_output_prefix << "Intermediate tensor size: " << sizes_in_gb[4] + << " GB\n"; + ss << debug_output_prefix << "Compiled program size: " << sizes_in_gb[0] + << " GB\n"; + ss << debug_output_prefix + << "----------------------------------------------------------------------" + "----------" + << "\n"; + ss << debug_output_prefix + << "======================================================================" + "==========" + << "\n"; + if (debug_file_name == "") { + // print to stderr by default + std::cerr << ss.str(); + } else { + std::ofstream outFile; + outFile.open(debug_file_name, std::ios_base::app); + outFile << ss.rdbuf(); + } +} + } // namespace torch_xla diff --git a/torch_xla/csrc/debug_util.h b/torch_xla/csrc/debug_util.h index 7dcc906fb77..516245d8768 100644 --- a/torch_xla/csrc/debug_util.h +++ b/torch_xla/csrc/debug_util.h @@ -6,6 +6,7 @@ #include #include "absl/types/span.h" +#include "torch_xla/csrc/runtime/computation_client.h" #include "torch_xla/csrc/tensor.h" namespace torch_xla { @@ -60,6 +61,9 @@ class DebugUtil { static void analyze_graph_execution_python_frame( GraphAnalysisSource source, torch::lazy::hash_t graph_hash = 0, const xla::ProgramShape* program_shape = nullptr); + + static void post_compilation_analysis( + runtime::ComputationClient::ComputationPtr computation); }; } // namespace torch_xla diff --git a/torch_xla/csrc/dl_convertor.cpp b/torch_xla/csrc/dl_convertor.cpp new file mode 100644 index 00000000000..d29401be8fe --- /dev/null +++ b/torch_xla/csrc/dl_convertor.cpp @@ -0,0 +1,345 @@ +#include "torch_xla/csrc/dl_convertor.h" + +#include + +#include "absl/types/span.h" +#include "torch_xla/csrc/aten_xla_bridge.h" +#include "torch_xla/csrc/ops/device_data.h" +#include "torch_xla/csrc/runtime/computation_client.h" +#include "torch_xla/csrc/runtime/debug_macros.h" +#include "torch_xla/csrc/runtime/pjrt_computation_client.h" +#include "torch_xla/csrc/runtime/runtime.h" +#include "torch_xla/csrc/runtime/tf_logging.h" +#include "torch_xla/csrc/tensor.h" +#include "torch_xla/csrc/tensor_util.h" +#include "torch_xla/csrc/unwrap_data.h" +#include "xla/pjrt/pjrt_client.h" +#include "xla/pjrt/pjrt_future.h" +#include "xla/pjrt/pjrt_layout.h" +#include "xla/status.h" + +namespace torch_xla { + +struct DLPackTensor { + ~DLPackTensor(); + std::unique_ptr external_reference; + std::shared_ptr buffer_reference; + + std::vector shape; + std::vector strides; + DLManagedTensor tensor; +}; + +DLPackTensor::~DLPackTensor() { + if (external_reference) { + external_reference.reset(nullptr); + } +} + +void DLPackTensorDeleter(DLManagedTensor* t) { + if (t) { + delete static_cast(t->manager_ctx); + } +} + +DLDeviceType DLDeviceTypeForDevice(const xla::PjRtDevice& device) { + if (device.client()->platform_id() == xla::CpuId()) { + return DLDeviceType::kDLCPU; + } else if (device.client()->platform_id() == xla::CudaId()) { + return DLDeviceType::kDLCUDA; + } + XLA_ERROR() << "Device " << device.DebugString() + << " cannot be used as a DLPack device."; +} + +// Reference: https://github.com/openxla/xla/blob/main/xla/python/dlpack.cc +DLDevice DLDeviceForDevice(const xla::PjRtDevice& device) { + DLDevice dlDevice; + dlDevice.device_type = DLDeviceTypeForDevice(device); + dlDevice.device_id = device.local_hardware_id(); + return dlDevice; +} + +// Reference: https://github.com/openxla/xla/blob/main/xla/python/dlpack.cc +DLDataType PrimitiveTypeToDLDataType(xla::PrimitiveType type) { + switch (type) { + case xla::PrimitiveType::S8: + return DLDataType{kDLInt, 8, 1}; + case xla::PrimitiveType::S16: + return DLDataType{kDLInt, 16, 1}; + case xla::PrimitiveType::S32: + return DLDataType{kDLInt, 32, 1}; + case xla::PrimitiveType::S64: + return DLDataType{kDLInt, 64, 1}; + case xla::PrimitiveType::U8: + return DLDataType{kDLUInt, 8, 1}; + case xla::PrimitiveType::U16: + return DLDataType{kDLUInt, 16, 1}; + case xla::PrimitiveType::U32: + return DLDataType{kDLUInt, 32, 1}; + case xla::PrimitiveType::U64: + return DLDataType{kDLUInt, 64, 1}; + case xla::PrimitiveType::F16: + return DLDataType{kDLFloat, 16, 1}; + case xla::PrimitiveType::F32: + return DLDataType{kDLFloat, 32, 1}; + case xla::PrimitiveType::F64: + return DLDataType{kDLFloat, 64, 1}; + case xla::PrimitiveType::BF16: + return DLDataType{kDLBfloat, 16, 1}; + case xla::PrimitiveType::PRED: + return DLDataType{kDLBool, 8, 1}; + case xla::PrimitiveType::C64: + return DLDataType{kDLComplex, 64, 1}; + case xla::PrimitiveType::C128: + return DLDataType{kDLComplex, 128, 1}; + default: + XLA_ERROR() << "XLA type " << xla::PrimitiveType_Name(type) + << " has no DLPack equivalent"; + } +} + +std::vector StridesForShape(xla::PrimitiveType element_type, + absl::Span dimensions, + const xla::Layout& layout) { + XLA_CHECK_EQ(dimensions.size(), layout.minor_to_major().size()); + std::vector strides; + strides.resize(dimensions.size()); + int64_t stride = 1; + for (int i : layout.minor_to_major()) { + strides[i] = stride; + stride *= dimensions[i]; + } + return strides; +} + +// Convert an XLA tensor to a dlPack tensor. +DLManagedTensor* toDLPack(const at::Tensor& input) { + std::shared_ptr handle = + get_data_handle(input); + XLA_CHECK(handle != nullptr) + << "Could not extract a valid data handle from the input tensor"; + + std::shared_ptr pjrt_buffer = + runtime::GetComputationClient()->GetPjRtBuffer(handle); + XLA_CHECK(pjrt_buffer != nullptr) << "Could not get a valid pjrt_buffer"; + + XLA_CHECK(!pjrt_buffer->IsTuple()) + << "Unimplemented. BufferToDLPackManagedTensor is not " + "implemented for tuple buffers."; + XLA_CHECK(!pjrt_buffer->has_dynamic_dimensions()) + << "Unimplemented. DynamicShape is not implemented in DLPack."; + + auto pack = std::make_unique(); + DLTensor& dt = pack->tensor.dl_tensor; + { + // AcquireExternalReference may block + auto external_ref = pjrt_buffer->AcquireExternalReference(); + XLA_CHECK_OK(external_ref.status()); + pack->external_reference = std::move(external_ref.value()); + xla::PjRtFuture<> future = pjrt_buffer->GetReadyFuture(); + absl::Status status = future.Await(); + XLA_CHECK_OK(status); + } + pack->buffer_reference = pjrt_buffer; + + dt.data = pack->external_reference->OpaqueDeviceMemoryDataPointer(); + pack->tensor.manager_ctx = pack.get(); + pack->tensor.deleter = DLPackTensorDeleter; + dt.device = DLDeviceForDevice(*pjrt_buffer->device()); + dt.device.device_id = pjrt_buffer->device()->local_hardware_id(); + dt.ndim = pjrt_buffer->dimensions().size(); + dt.dtype = PrimitiveTypeToDLDataType(pjrt_buffer->element_type()); + + pack->shape = std::vector(pjrt_buffer->dimensions().begin(), + pjrt_buffer->dimensions().end()); + xla::Layout xla_layout = xla::GetXlaLayoutUnsafe(pjrt_buffer->layout()); + pack->strides = StridesForShape(pjrt_buffer->element_type(), + pjrt_buffer->dimensions(), xla_layout); + dt.shape = reinterpret_cast(pack->shape.data()); + dt.strides = reinterpret_cast(pack->strides.data()); + dt.byte_offset = 0; + + return &(pack.release()->tensor); +} + +// Reference: https://github.com/openxla/xla/blob/main/xla/python/dlpack.cc +absl::StatusOr DeviceForDLDevice(const DLDevice& context) { + switch (context.device_type) { + case DLDeviceType::kDLCPU: + XLA_CHECK_EQ(runtime::GetComputationClient()->GetPlatformID(), + xla::CpuId()); + return runtime::GetComputationClient()->LookupAddressableDevice( + context.device_id); + case DLDeviceType::kDLCUDA: + XLA_CHECK_EQ(runtime::GetComputationClient()->GetPlatformID(), + xla::CudaId()); + return runtime::GetComputationClient()->LookupAddressableDevice( + context.device_id); + default: + return tsl::errors::InvalidArgument( + "Unknown/unsupported DLPack device type %d", context.device_type); + } +} + +// Reference: https://github.com/openxla/xla/blob/main/xla/python/dlpack.cc +absl::StatusOr DLDataTypeToPrimitiveType(DLDataType type) { + if (type.lanes != 1) { + return tsl::errors::Unimplemented( + "DLPack types with lanes != 1 not implemented, got %d", type.lanes); + } + switch (type.code) { + case kDLBool: + switch (type.bits) { + case 8: + return xla::PrimitiveType::PRED; + default: + return tsl::errors::Unimplemented( + "Only 8-bit DLPack booleans are supported, got %d bits", + type.bits); + } + case kDLInt: + switch (type.bits) { + case 8: + return xla::PrimitiveType::S8; + case 16: + return xla::PrimitiveType::S16; + case 32: + return xla::PrimitiveType::S32; + case 64: + return xla::PrimitiveType::S64; + default: + return tsl::errors::Unimplemented( + "Invalid or unsupported DLPack integer width: %d bits", + type.bits); + } + case kDLUInt: + switch (type.bits) { + case 8: + return xla::PrimitiveType::U8; + case 16: + return xla::PrimitiveType::U16; + case 32: + return xla::PrimitiveType::U32; + case 64: + return xla::PrimitiveType::U64; + default: + return tsl::errors::Unimplemented( + "Invalid or unsupported DLPack unsigned integer width: %d bits", + type.bits); + } + case kDLFloat: + switch (type.bits) { + case 16: + return xla::PrimitiveType::F16; + case 32: + return xla::PrimitiveType::F32; + case 64: + return xla::PrimitiveType::F64; + default: + return tsl::errors::Unimplemented( + "Invalid or unsupported DLPack float width: %d bits", type.bits); + } + case kDLBfloat: + switch (type.bits) { + case 16: + return xla::PrimitiveType::BF16; + default: + return tsl::errors::Unimplemented( + "Invalid or unsupported DLPack Bfloat width: %d bits", type.bits); + } + case kDLComplex: + switch (type.bits) { + case 64: + return xla::PrimitiveType::C64; + case 128: + return xla::PrimitiveType::C128; + default: + return tsl::errors::Unimplemented( + "Invalid or unsupported DLPack complex width: %d bits", + type.bits); + } + default: + return tsl::errors::Unimplemented( + "Unknown or invalid DLPack type code %d", type.code); + } +} + +// Reference: https://github.com/openxla/xla/blob/main/xla/python/dlpack.cc +absl::StatusOr> StridesToLayout( + absl::Span dims, absl::Span strides) { + XLA_CHECK_EQ(dims.size(), strides.size()); + std::vector minor_to_major(dims.size()); + std::iota(minor_to_major.begin(), minor_to_major.end(), 0); + absl::c_sort(minor_to_major, [&](int a, int b) { + if (strides[a] < strides[b]) { + return true; + } + if (strides[a] > strides[b]) { + return false; + } + // If two dimensions have the same stride, prefer the major-to-minor + // interpretation of the ordering, since that's what JAX wants. + return b < a; + }); + int64_t stride = 1; + for (int64_t d : minor_to_major) { + if (dims[d] > 1 && strides[d] != stride) { + return tsl::errors::Unimplemented( + "Only DLPack tensors with trivial (compact) striding are supported; " + "i.e., tensors whose striding represents a transposition of the " + "underlying buffer but not broadcasting. Dimensions were: [%s], " + "strides were [%s].", + absl::StrJoin(dims, ","), absl::StrJoin(strides, ",")); + } + stride *= dims[d]; + } + return minor_to_major; +} + +at::Tensor fromDLPack(DLManagedTensor* dlmt) { + XLA_CHECK(dlmt->dl_tensor.ndim >= 0) + << "Number of dimensions in DLManagedTensor must be nonnegative, got " + << dlmt->dl_tensor.ndim; + xla::PjRtDevice* device = DeviceForDLDevice(dlmt->dl_tensor.device).value(); + absl::Span dimensions( + const_cast(dlmt->dl_tensor.shape), dlmt->dl_tensor.ndim); + xla::PrimitiveType element_type = + DLDataTypeToPrimitiveType(dlmt->dl_tensor.dtype).value(); + + std::vector minor_to_major; + if (dlmt->dl_tensor.strides && + absl::c_find(dimensions, 0) == dimensions.end()) { + absl::Span strides( + const_cast(dlmt->dl_tensor.strides), dlmt->dl_tensor.ndim); + minor_to_major = StridesToLayout(dimensions, strides).value(); + } else { + minor_to_major.resize(dlmt->dl_tensor.ndim); + std::iota(minor_to_major.rbegin(), minor_to_major.rend(), 0); + } + xla::Shape shape = xla::ShapeUtil::MakeShapeWithDenseLayout( + element_type, dimensions, minor_to_major); + + std::function on_delete_callback; + if (dlmt->deleter) { + on_delete_callback = [dlmt]() { dlmt->deleter(dlmt); }; + } + xla::StatusOr> pjrt_buffer = + device->client()->CreateViewOfDeviceBuffer( + static_cast(dlmt->dl_tensor.data) + + dlmt->dl_tensor.byte_offset, + shape, device, on_delete_callback); + XLA_CHECK_OK(pjrt_buffer.status()) << "Failed to create a pjrt buffer."; + XLA_CHECK(pjrt_buffer.value() != nullptr) << "pjrt buffer is null."; + + runtime::ComputationClient::DataPtr data = + runtime::PjRtComputationClient::CreateData( + runtime::GetComputationClient()->PjRtDeviceToString(device), shape, + std::move(pjrt_buffer.value())); + + at::ScalarType tensor_type = at::toScalarType(dlmt->dl_tensor.dtype); + XLATensorPtr xla_tensor = XLATensor::Create(data, tensor_type); + return bridge::AtenFromXlaTensor(xla_tensor); +} + +} // namespace torch_xla diff --git a/torch_xla/csrc/dl_convertor.h b/torch_xla/csrc/dl_convertor.h new file mode 100644 index 00000000000..f5a54823e2e --- /dev/null +++ b/torch_xla/csrc/dl_convertor.h @@ -0,0 +1,14 @@ +#ifndef XLA_TORCH_XLA_CSRC_DL_CONVERTOR_H_ +#define XLA_TORCH_XLA_CSRC_DL_CONVERTOR_H_ + +#include +#include + +namespace torch_xla { + +DLManagedTensor* toDLPack(const at::Tensor& src); +at::Tensor fromDLPack(DLManagedTensor* src); + +} // namespace torch_xla + +#endif // XLA_TORCH_XLA_CSRC_DL_CONVERTOR_H_ diff --git a/torch_xla/csrc/dtype.cpp b/torch_xla/csrc/dtype.cpp index e26e4e27fe9..c5310a9e2ea 100644 --- a/torch_xla/csrc/dtype.cpp +++ b/torch_xla/csrc/dtype.cpp @@ -10,6 +10,9 @@ namespace { bool ShouldUseBF16() { bool use_bf16 = runtime::sys_util::GetEnvBool("XLA_USE_BF16", false); if (use_bf16) { + std::cout + << "XLA_USE_BF16 will be deprecated after the 2.4 release, please " + "convert your model to bf16 directly\n"; TF_LOG(INFO) << "Using BF16 data type for floating point values"; } return use_bf16; @@ -18,6 +21,9 @@ bool ShouldUseBF16() { bool ShouldUseF16() { bool use_fp16 = runtime::sys_util::GetEnvBool("XLA_USE_FP16", false); if (use_fp16) { + std::cout + << "XLA_USE_FP16 will be deprecated after the 2.4 release, please " + "convert your model to fp16 directly\n"; TF_LOG(INFO) << "Using F16 data type for floating point values"; } return use_fp16; @@ -27,6 +33,9 @@ bool ShouldDowncastToBF16() { bool downcast_bf16 = runtime::sys_util::GetEnvBool("XLA_DOWNCAST_BF16", false); if (downcast_bf16) { + std::cout + << "XLA_DOWNCAST_BF16 will be deprecated after the 2.4 release, please " + "downcast your model directly\n"; TF_LOG(INFO) << "Downcasting floating point values, F64->F32, F32->BF16"; } return downcast_bf16; @@ -36,6 +45,9 @@ bool ShouldDowncastToF16() { bool downcast_fp16 = runtime::sys_util::GetEnvBool("XLA_DOWNCAST_FP16", false); if (downcast_fp16) { + std::cout + << "XLA_DOWNCAST_FP16 will be deprecated after the 2.4 release, please " + "downcast your model directly\n"; TF_LOG(INFO) << "Downcasting floating point values, F64->F32, F32->FP16"; } return downcast_fp16; @@ -45,6 +57,8 @@ bool ShouldUse32BitLong() { bool use_32bit_long = runtime::sys_util::GetEnvBool("XLA_USE_32BIT_LONG", false); if (use_32bit_long) { + std::cout + << "XLA_USE_32BIT_LONG will be deprecated after the 2.4 release\n"; TF_LOG(INFO) << "Using 32bit integers for kLong values"; } return use_32bit_long; diff --git a/torch_xla/csrc/init_python_bindings.cpp b/torch_xla/csrc/init_python_bindings.cpp index e20e28fbb8f..362df87e08d 100644 --- a/torch_xla/csrc/init_python_bindings.cpp +++ b/torch_xla/csrc/init_python_bindings.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -32,8 +33,10 @@ #include "pybind11/stl_bind.h" #include "torch_xla/csrc/XLANativeFunctions.h" #include "torch_xla/csrc/aten_autograd_ops.h" +#include "torch_xla/csrc/aten_cpu_fallback.h" #include "torch_xla/csrc/aten_xla_bridge.h" #include "torch_xla/csrc/device.h" +#include "torch_xla/csrc/dl_convertor.h" #include "torch_xla/csrc/dtype.h" #include "torch_xla/csrc/helpers.h" #include "torch_xla/csrc/ir.h" @@ -725,8 +728,8 @@ py::dict GetMemoryInfo(const std::string& device_str) { runtime::GetComputationClient()->GetMemoryInfo(device.toString()); } auto py_dict = py::dict(); - py_dict["kb_free"] = mem_info.kb_free; - py_dict["kb_total"] = mem_info.kb_total; + py_dict["bytes_used"] = mem_info.bytes_used; + py_dict["bytes_limit"] = mem_info.bytes_limit; return py_dict; } @@ -1115,6 +1118,36 @@ void BuildLoweringContextSubmodule(py::module* m) { .def("get_name_string", &PyLoweringContext::GetNameString); } +// Used in the to_dlpack. +void dlPack_Capsule_Destructor(PyObject* data) { + if (!PyCapsule_IsValid(data, "dltensor")) { + return; + } + DLManagedTensor* dlMTensor = + static_cast(PyCapsule_GetPointer(data, "dltensor")); + if (dlMTensor) { + dlMTensor->deleter(dlMTensor); + } else { + // The tensor has been deleted. Clear any error from + // PyCapsule_GetPointer. + PyErr_Clear(); + } +} + +at::Tensor tensor_fromDLPack(PyObject* data) { + DLManagedTensor* dlMTensor = + (DLManagedTensor*)PyCapsule_GetPointer(data, "dltensor"); + XLA_CHECK(dlMTensor != nullptr) + << "from_dlpack received an invalid capsule. Note that a DLTensor " + "capsule can be consumed only once. You may have already constructed " + "a tensor from it once."; + + at::Tensor tensor = torch_xla::fromDLPack(dlMTensor); + PyCapsule_SetName(data, "used_dltensor"); + PyCapsule_SetDestructor(data, nullptr); + return tensor; +} + void InitXlaModuleBindings(py::module m) { m.def("_prepare_to_exit", []() { PrepareToExit(); }); m.def("_xla_runtime_is_initialized", []() { @@ -1280,6 +1313,9 @@ void InitXlaModuleBindings(py::module m) { return runtime::GetComputationClient()->GetLocalDevices(); } }); + m.def("_get_stream_for_cuda_device", [](const int device_id) { + return runtime::GetComputationClient()->GetCudaStreamForDevice(device_id); + }); m.def("_xla_num_devices", []() -> int64_t { if (UseVirtualDevice()) { return 1; @@ -1766,6 +1802,7 @@ void InitXlaModuleBindings(py::module m) { } }, py::arg("devices")); + m.def("_get_executed_fallback_ops", []() { return GetFallbackOperations(); }); m.def("_xla_counter_names", []() { auto counter_names = torch::lazy::GetCounterNames(); auto xla_counter_names = runtime::metrics::GetCounterNames(); @@ -1842,9 +1879,8 @@ void InitXlaModuleBindings(py::module m) { return GetLiveTensorsReport(nodes_threshold, device); }, py::arg("nodes_threshold") = 100, py::arg("device") = ""); - m.def("_xla_memory_info", [](const std::string& device) -> py::object { - return GetMemoryInfo(device); - }); + m.def("_xla_memory_info", + [](const std::string& device) { return GetMemoryInfo(device); }); m.def( "_xla_set_use_full_mat_mul_precision", [](bool use_full_mat_mul_precision) { @@ -2042,6 +2078,16 @@ void InitXlaModuleBindings(py::module m) { XLATensorPtr xtensor = bridge::GetXlaTensor(input); return GetXLAShardingSpec(xtensor); }); + m.def("_get_xla_op_sharding", + [](const at::Tensor& input) -> std::optional { + XLATensorPtr xtensor = bridge::GetXlaTensor(input); + XLATensor::ShardingSpecPtr sharding_spec = + xtensor ? xtensor->sharding_spec() : nullptr; + if (sharding_spec != nullptr) { + return sharding_spec->sharding; + } + return std::nullopt; + }); m.def("_get_xla_sharding_specs", [](const std::vector& tensors) -> std::vector { tsl::profiler::TraceMe activity("_get_xla_sharding_specs", @@ -2339,6 +2385,24 @@ void InitXlaModuleBindings(py::module m) { [](at::Tensor& self, const at::Tensor& source) -> at::Tensor& { return XLANativeFunctions::set_(self, source); }); + m.def("_xla_custom_call", + [](const std::vector& inputs, const std::string& target, + const std::vector>& output_shapes, + const std::vector& output_dtypes, bool has_side_effect, + const std::string& backend_config, + const int api_version) -> std::vector { + std::vector dtypes; + dtypes.reserve(output_dtypes.size()); + for (auto& dtype : output_dtypes) { + dtypes.push_back( + reinterpret_cast(dtype.ptr())->scalar_type); + } + + auto xtensors = tensor_methods::custom_call( + bridge::GetXlaTensors(inputs), target, output_shapes, dtypes, + has_side_effect, backend_config, api_version); + return bridge::AtenFromXlaTensors(std::move(xtensors)); + }); m.def("_xla_tpu_custom_call", [](const std::vector& inputs, const std::string& payload, const std::vector>& output_shapes, @@ -2482,6 +2546,54 @@ void InitXlaModuleBindings(py::module m) { return false; }); + m.def("_unsafe_buffer_pointer", + [](const at::Tensor& input) -> std::uintptr_t { + XLATensorPtr xtensor = bridge::GetXlaTensor(input); + XLA_CHECK(xtensor) << "The input is not an XLA tensor."; + if (xtensor->CurrentDataHandle() != nullptr) { + std::shared_ptr data = + std::dynamic_pointer_cast( + xtensor->CurrentDataHandle()); + return runtime::GetComputationClient()->UnsafeBufferPointer(data); + } else if (xtensor->CurrentIrValue().node != nullptr) { + DeviceData* device_data = + DeviceData::Cast(xtensor->CurrentIrValue().node.get()); + if (device_data != nullptr) { + torch::lazy::BackendDataPtr data = device_data->data(); + return runtime::GetComputationClient()->UnsafeBufferPointer( + UnwrapXlaData(data)); + } else { + XLA_ERROR() << "Could not get the buffer pointer for XLATensor " + "with IR that's not DeviceData"; + } + } + XLA_ERROR() << "Could not get the buffer pointer for XLATensor " + "without a data handle or an IR."; + }); + + // from an XLA tensor to a dlpack tensor. + // If ext_data is the result of an CUDA computation, we should synchronize + // (waits for all kernels in all streams on a CUDA device to complete) if the + // current stream is different from the ext_data's stream. Otherwise, we may + // risk of getting incorrect results. + m.def("_to_dlpack", [](const at::Tensor& input) -> py::handle { + DLManagedTensor* dlMTensor; + { + NoGilSection nogil; + dlMTensor = torch_xla::toDLPack(input); + } + return PyCapsule_New(dlMTensor, "dltensor", dlPack_Capsule_Destructor); + }); + + // from a dlpack tensor to an XLA tensor + // If ext_data is the result of an CUDA computation, we should synchronize + // (waits for all kernels in all streams on a CUDA device to complete) if the + // current stream is different from the ext_data's stream. Otherwise, we may + // risk of getting incorrect results. + m.def("_from_dlpack", [](py::handle ext_data) -> at::Tensor { + return tensor_fromDLPack(ext_data.ptr()); + }); + // -------------Dynamo Integration API Start------------------------- /* * Return tensor ids and at::tensors for all DeviceData nodes that is needed diff --git a/torch_xla/csrc/ops/custom_call.cpp b/torch_xla/csrc/ops/custom_call.cpp new file mode 100644 index 00000000000..00347e0c975 --- /dev/null +++ b/torch_xla/csrc/ops/custom_call.cpp @@ -0,0 +1,70 @@ +#include "torch_xla/csrc/ops/custom_call.h" + +#include + +#include "torch_xla/csrc/lowering_context.h" +#include "torch_xla/csrc/ops/xla_ops.h" +#include "torch_xla/csrc/shape_helper.h" + +namespace torch_xla { + +CustomCall::CustomCall(torch::lazy::OpList inputs, + const std::string& call_target, xla::Shape output_shape, + bool has_side_effect, const std::string& backend_config, + const int api_version) + : XlaNode(xla_custom_call, inputs, std::move(output_shape), + /*num_outputs=*/output_shape.tuple_shapes_size(), + torch::lazy::MHash(call_target)), + call_target_(call_target), + has_side_effect_(has_side_effect), + backend_config_(backend_config), + api_version_(api_version) {} + +torch::lazy::NodePtr CustomCall::Clone(torch::lazy::OpList operands) const { + return torch::lazy::MakeNode(operands, call_target_, + this->xla_shape(), has_side_effect_, + backend_config_, api_version_); +} + +XlaOpVector CustomCall::Lower(LoweringContext* loctx) const { + std::vector inputs; + inputs.reserve(this->operands().size()); + for (auto& operand : operands()) { + inputs.push_back(loctx->GetOutputOp(operand)); + } + xla::Shape output_shape = this->xla_shape(); + const int n_outputs = output_shape.tuple_shapes_size(); + if (n_outputs == 1) { + output_shape = output_shape.tuple_shapes(0); + } + XLA_CHECK(api_version_ >= 0 && api_version_ < 5); + xla::XlaOp output = xla::CustomCall( + inputs[0].builder(), call_target_, inputs, output_shape, + /*opaque=*/backend_config_, + /*has_side_effect=*/has_side_effect_, + /*output_operand_aliasing=*/{}, + /*literal=*/nullptr, + /*schedule=*/xla::CustomCallSchedule::SCHEDULE_NONE, + /*api_version=*/static_cast(api_version_)); + std::vector result; + if (n_outputs == 1) { + result = {output}; + } else { + result.reserve(n_outputs); + for (int i = 0; i < n_outputs; ++i) { + result.push_back(xla::GetTupleElement(output, i)); + } + } + return ReturnOps(result, loctx); +} + +std::string CustomCall::ToString() const { + std::stringstream ss; + ss << XlaNode::ToString() << ", call_target=" << call_target_ + << ", has_side_effect=" << has_side_effect_ + << ", backend_config=" << backend_config_ + << ", api_version=" << api_version_; + return ss.str(); +} + +} // namespace torch_xla diff --git a/torch_xla/csrc/ops/custom_call.h b/torch_xla/csrc/ops/custom_call.h new file mode 100644 index 00000000000..69bb613d4b6 --- /dev/null +++ b/torch_xla/csrc/ops/custom_call.h @@ -0,0 +1,29 @@ +#ifndef XLA_TORCH_XLA_CSRC_OPS_CUSTOM_CALL_H_ +#define XLA_TORCH_XLA_CSRC_OPS_CUSTOM_CALL_H_ + +#include "torch_xla/csrc/ir.h" + +namespace torch_xla { + +class CustomCall : public XlaNode { + public: + CustomCall(torch::lazy::OpList inputs, const std::string& call_target, + xla::Shape output_shape, bool has_side_effect, + const std::string& backend_config, const int api_version); + + std::string ToString() const override; + + torch::lazy::NodePtr Clone(torch::lazy::OpList operands) const override; + + XlaOpVector Lower(LoweringContext* loctx) const override; + + private: + std::string call_target_; + bool has_side_effect_; + std::string backend_config_; + int api_version_; +}; + +} // namespace torch_xla + +#endif // XLA_TORCH_XLA_CSRC_OPS_CUSTOM_CALL_H_ diff --git a/torch_xla/csrc/ops/embedding_bag.cpp b/torch_xla/csrc/ops/embedding_bag.cpp new file mode 100644 index 00000000000..d2bb034a005 --- /dev/null +++ b/torch_xla/csrc/ops/embedding_bag.cpp @@ -0,0 +1,192 @@ +#include "torch_xla/csrc/ops/embedding_bag.h" + +#include "torch_xla/csrc/helpers.h" +#include "torch_xla/csrc/lowering_context.h" +#include "torch_xla/csrc/ops/infer_output_shape.h" +#include "torch_xla/csrc/ops/xla_ops.h" +#include "torch_xla/csrc/shape_helper.h" +#include "torch_xla/csrc/xla_lower_util.h" +#include "tsl/platform/stacktrace.h" +#include "xla/client/lib/constants.h" +#include "xla/client/lib/loops.h" +#include "xla/client/lib/slicing.h" +#include "xla/shape_util.h" + +namespace torch_xla { +namespace { +const int MODE_SUM = 0; +const int MODE_MEAN = 1; +const int MODE_MAX = 2; +std::vector BuildEmbeddingBag(xla::XlaOp weight, xla::XlaOp indices, + xla::XlaOp offsets, + xla::XlaOp per_sample_weights, + bool include_last_offset, int mode) { + xla::Shape offset_shape = ShapeHelper::ShapeOfXlaOp(offsets); + int64_t n = offset_shape.dimensions(0); + xla::Shape weight_shape = ShapeHelper::ShapeOfXlaOp(weight); + int64_t weight_dim = weight_shape.dimensions(1); + xla::Shape indices_shape = ShapeHelper::ShapeOfXlaOp(indices); + int64_t num_embeddings = indices_shape.dimensions(0); + XLA_CHECK(indices_shape.rank() == 1 || indices_shape.rank() == 2) + << "input has to be a 1D or 2D Tensor, but got Tensor of dimension " + << indices_shape.rank(); + if (indices_shape.rank() == 1) { + XLA_CHECK(offset_shape.rank() == 1) + << "offsets has to be a 1D Tensor, but got Tensor of dimension " + << offset_shape.rank(); + } + XLA_CHECK(weight_shape.rank() == 2) + << "weight has to be a 2D Tensor, but got Tensor of dimension " + << weight_shape.rank(); + + xla::XlaOp output2 = xla::ZerosLike(indices); + xla::XlaOp output3 = xla::ZerosLike(offsets); + std::vector sizes = {n, weight_dim}; + xla::XlaOp output4 = + xla::Zeros(offsets.builder(), + xla::ShapeUtil::MakeShape(offset_shape.element_type(), sizes)); + + xla::XlaOp embeddings = xla::TorchIndexSelect(weight, indices, 0); + xla::XlaOp embeddings_weighted = xla::Mul( + embeddings, xla::ConvertElementType( + xla::BroadcastInDim(per_sample_weights, + {num_embeddings, weight_dim}, {0}), + weight_shape.element_type())); + + std::vector shape_elements = { + xla::ShapeUtil::MakeShape(offset_shape.element_type(), {}), + xla::ShapeUtil::MakeShape(offset_shape.element_type(), {}), + xla::ShapeUtil::MakeShape(weight_shape.element_type(), + {num_embeddings, weight_dim}), + xla::ShapeUtil::MakeShape(weight_shape.element_type(), {1, weight_dim})}; + xla::Shape result_shape = xla::ShapeUtil::MakeTupleShape(shape_elements); + + xla::XlaComputation condition; + { + xla::XlaBuilder builder("condition"); + auto prev = xla::Parameter(&builder, 0, result_shape, "prev"); + auto index = xla::GetTupleElement(prev, 0); + auto final_value = xla::GetTupleElement(prev, 1); + xla::Lt(index, final_value); + condition = builder.Build().value(); + } + + xla::XlaComputation body; + { + xla::XlaBuilder builder("body"); + auto prev = xla::Parameter(&builder, 0, result_shape, "prev"); + auto index = xla::GetTupleElement(prev, 0); + auto emb = xla::GetTupleElement(prev, 2); + auto w = xla::GetTupleElement(prev, 3); + + xla::XlaOp slice = xla::DynamicSlice( + emb, + {index, xla::ConvertElementType(xla::ConstantR0(&builder, 0), + offset_shape.element_type())}, + {1, weight_dim}); + xla::XlaOp result = + mode == MODE_SUM ? xla::Add(w, slice) : xla::Max(w, slice); + + xla::Tuple(&builder, + { + xla::Add(index, xla::ConvertElementType( + xla::ConstantR0(&builder, 1), + offset_shape.element_type())), + xla::GetTupleElement(prev, 1), + xla::GetTupleElement(prev, 2), + result, + }); + body = builder.Build().value(); + } + + xla::Array initial_vector({1, weight_dim}, 0.f); + std::vector results; + for (int64_t i = 0; i < n; i++) { + xla::XlaOp start = xla::DynamicSlice( + offsets, {xla::ConstantR0(offsets.builder(), i)}, {1}); + if (i == n - 1 && include_last_offset) continue; + xla::XlaOp end = + i == n - 1 && !include_last_offset + ? xla::ConvertElementType(xla::ConstantR1( + offsets.builder(), 1, num_embeddings), + offset_shape.element_type()) + : xla::DynamicSlice( + offsets, {xla::ConstantR0(offsets.builder(), i + 1)}, + {1}); + // Create a While node with computations for the condition and the body. + auto init_tuple = xla::Tuple( + offsets.builder(), + {xla::Reshape(start, {0}, {}), xla::Reshape(end, {0}, {}), + embeddings_weighted, + xla::ConvertElementType( + xla::ConstantFromArray(offsets.builder(), initial_vector), + weight_shape.element_type())}); + auto result = xla::While(condition, body, init_tuple); + results.push_back(xla::GetTupleElement(result, 3)); + }; + xla::XlaOp output1 = xla::ConcatInDim(offsets.builder(), results, 0); + return {output1, output2, output3, output4}; +} + +xla::Shape NodeOutputShapes(const torch::lazy::Value& weight, + const torch::lazy::Value& indices, + const torch::lazy::Value& offsets, + const torch::lazy::Value& per_sample_weights, + bool include_last_offset, bool mode) { + auto lower_for_shapes_fn = + [&](absl::Span operands) -> xla::XlaOp { + return xla::Tuple( + operands[0].builder(), + BuildEmbeddingBag(operands[0], operands[1], operands[2], operands[3], + include_last_offset, mode)); + }; + + std::vector input_shapes = { + GetXlaShape(weight), GetXlaShape(indices), GetXlaShape(offsets), + GetXlaShape(per_sample_weights)}; + + return InferOutputShape(absl::MakeSpan(input_shapes), lower_for_shapes_fn); +} +} // namespace + +std::string EmbeddingBag::ToString() const { + std::stringstream ss; + ss << XlaNode::ToString(); + return ss.str(); +} + +EmbeddingBag::EmbeddingBag(const torch::lazy::Value& weight, + const torch::lazy::Value& indices, + const torch::lazy::Value& offsets, int64_t mode, + const torch::lazy::Value& per_sample_weights, + bool include_last_offset) + : XlaNode( + torch::lazy::OpKind(at::aten::embedding_bag), + {weight, indices, offsets, per_sample_weights}, + [&]() { + return NodeOutputShapes(weight, indices, offsets, + per_sample_weights, include_last_offset, + mode); + }, + /*num_outputs=*/4, torch::lazy::MHash(mode, include_last_offset)), + mode_(mode), + include_last_offset_(include_last_offset) {} + +torch::lazy::NodePtr EmbeddingBag::Clone(torch::lazy::OpList operands) const { + return torch::lazy::MakeNode(operands.at(0), operands.at(1), + operands.at(2), mode_, + operands.at(3), false); +} + +XlaOpVector EmbeddingBag::Lower(LoweringContext* loctx) const { + xla::XlaOp weight = loctx->GetOutputOp(operand(0)); + xla::XlaOp indices = loctx->GetOutputOp(operand(1)); + xla::XlaOp offsets = loctx->GetOutputOp(operand(2)); + xla::XlaOp per_sample_weights = loctx->GetOutputOp(operand(3)); + std::vector ops = + BuildEmbeddingBag(weight, indices, offsets, per_sample_weights, + include_last_offset_, mode_); + return ReturnOps(absl::MakeSpan(ops), loctx); +} + +} // namespace torch_xla \ No newline at end of file diff --git a/torch_xla/csrc/ops/embedding_bag.h b/torch_xla/csrc/ops/embedding_bag.h new file mode 100644 index 00000000000..4d9b0a6eecb --- /dev/null +++ b/torch_xla/csrc/ops/embedding_bag.h @@ -0,0 +1,31 @@ +#ifndef XLA_TORCH_XLA_CSRC_OPS_EMBEDDING_BAG_H_ +#define XLA_TORCH_XLA_CSRC_OPS_EMBEDDING_BAG_H_ + +#include + +#include "torch_xla/csrc/ir.h" + +namespace torch_xla { + +class EmbeddingBag : public XlaNode { + public: + EmbeddingBag(const torch::lazy::Value& weight, + const torch::lazy::Value& indices, + const torch::lazy::Value& offsets, int64_t mode, + const torch::lazy::Value& per_sample_weights, + bool include_last_offset); + + std::string ToString() const override; + + torch::lazy::NodePtr Clone(torch::lazy::OpList operands) const override; + + XlaOpVector Lower(LoweringContext* loctx) const override; + + private: + int64_t mode_; + bool include_last_offset_; +}; + +} // namespace torch_xla + +#endif // XLA_TORCH_XLA_CSRC_OPS_EMBEDDING_BAG_H_ \ No newline at end of file diff --git a/torch_xla/csrc/ops/index_ops.cpp b/torch_xla/csrc/ops/index_ops.cpp index ddbf0c677aa..ccc3d090a56 100644 --- a/torch_xla/csrc/ops/index_ops.cpp +++ b/torch_xla/csrc/ops/index_ops.cpp @@ -277,12 +277,59 @@ torch::lazy::Value EnsureRank1(const torch::lazy::Value& index) { : index; } +bool HasZeroElementIndex(absl::Span indices) { + return std::any_of(indices.begin(), indices.end(), + [](const XLATensorPtr& index) { + return xla::ShapeUtil::ElementsIn(*index->shape()) == 0; + }); +} + +XLATensorPtr GetZeroElementTensor(const XLATensorPtr& base, + absl::Span indices, + int64_t start_dim) { + // Returns a 0-element tensor described by the indexing. + // + // At this point, we know that we are indexing 'base' with 0-element + // tensors, i.e. one of its dimensions has size 0. Therefore, we + // need to return a 0-element tensor of the appropriate size. + // + // This function computes the output size and calls 'full' to create the + // desired 0-element tensor. + std::vector dimensions; + + // In the beginning, we add all dimensions that come before the ones that + // correspond to the indices. + absl::Span base_dimensions = base->shape().get().dimensions(); + dimensions.insert(dimensions.end(), base_dimensions.begin(), + base_dimensions.begin() + start_dim); + + // Then, we add the dimensions of the first index. Notice that, at this + // point, all indices are already broadcasted, i.e. have the same size. + // So, we grab the first one for convenience. + for (auto dim : indices.front()->shape().get().dimensions()) { + dimensions.push_back(dim); + } + + // Finally, add the remaining dimensions that weren't indexed. + dimensions.insert(dimensions.end(), + base_dimensions.begin() + start_dim + indices.size(), + base_dimensions.end()); + + return tensor_methods::full(dimensions, 0, base->GetDevice(), base->dtype()); +} + XLATensorPtr IndexByTensors(const XLATensorPtr& base, absl::Span indices, int64_t start_dim) { if (indices.empty()) { return base; } + // Check whether we are trying to index with a 0-element tensor. + // If so, there's no need to compute anything. We simply return + // a 0-element tensor. + if (HasZeroElementIndex(indices)) { + return GetZeroElementTensor(base, indices, start_dim); + } auto canonical_indices = WrapIndicesOnce(base, indices, start_dim); int64_t indices_rank = canonical_indices.front()->shape().get().rank(); // Stack the indices to allow the whole multi-indexing to be dispatched with a diff --git a/torch_xla/csrc/ops/xla_ops.cpp b/torch_xla/csrc/ops/xla_ops.cpp index 97ae036b774..e1aa70d56d6 100644 --- a/torch_xla/csrc/ops/xla_ops.cpp +++ b/torch_xla/csrc/ops/xla_ops.cpp @@ -9,6 +9,7 @@ const OpKindWrapper xla_as_strided_view_update("xla::as_strided_view_update"); const OpKindWrapper xla_cast("xla::cast"); const OpKindWrapper xla_collective_permute("xla::collective_permute"); const OpKindWrapper xla_cross_replica_sum("xla::cross_replica_sum"); +const OpKindWrapper xla_custom_call("xla::custom_call"); const OpKindWrapper xla_device_data("xla::device_data"); const OpKindWrapper xla_dequantize_tensor("xla::dequantize_tensor"); const OpKindWrapper xla_diagonal_view_update("xla::diagonal_view_update"); diff --git a/torch_xla/csrc/ops/xla_ops.h b/torch_xla/csrc/ops/xla_ops.h index 7a56d99743b..fff50fe6bc3 100644 --- a/torch_xla/csrc/ops/xla_ops.h +++ b/torch_xla/csrc/ops/xla_ops.h @@ -35,6 +35,7 @@ extern const OpKindWrapper xla_as_strided_view_update; extern const OpKindWrapper xla_cast; extern const OpKindWrapper xla_collective_permute; extern const OpKindWrapper xla_cross_replica_sum; +extern const OpKindWrapper xla_custom_call; extern const OpKindWrapper xla_device_data; extern const OpKindWrapper xla_dequantize_tensor; extern const OpKindWrapper xla_diagonal_view_update; diff --git a/torch_xla/csrc/reduction.cpp b/torch_xla/csrc/reduction.cpp index f7b29d1cf3b..56702e79279 100644 --- a/torch_xla/csrc/reduction.cpp +++ b/torch_xla/csrc/reduction.cpp @@ -459,9 +459,9 @@ xla::XlaOp BuildArgMin(xla::XlaOp input, int64_t dim, bool keepdim) { shape = &ShapeHelper::ShapeOfXlaOp(operand); } } - xla::XlaOp result = xla::ArgMin( + xla::XlaOp result = xla::ArgMinMax( operand, GetXlaPrimitiveTypeForCurrentDevice(xla::PrimitiveType::S64), - dim); + dim, /* is_min */ true); if (keepdim) { auto dimensions = torch::lazy::ToVector(shape->dimensions()); if (dim_is_none) { diff --git a/torch_xla/csrc/runtime/BUILD b/torch_xla/csrc/runtime/BUILD index 6f746972355..582b69d8a50 100644 --- a/torch_xla/csrc/runtime/BUILD +++ b/torch_xla/csrc/runtime/BUILD @@ -237,7 +237,7 @@ cc_library( deps = [ ":debug_macros", ":sys_util", - "@tsl//tsl/distributed_runtime/preemption:preemption_sync_manager", + "@xla//xla/tsl/distributed_runtime/preemption:preemption_sync_manager", "@xla//xla/pjrt/distributed", ], ) diff --git a/torch_xla/csrc/runtime/cache.h b/torch_xla/csrc/runtime/cache.h index bef5b099ec6..9557b2353b7 100644 --- a/torch_xla/csrc/runtime/cache.h +++ b/torch_xla/csrc/runtime/cache.h @@ -173,6 +173,7 @@ class PersistentCache : public AbstractCache { TORCH_LAZY_COUNTER("PersistentCacheMiss", 1); return nullptr; } + TORCH_LAZY_TIMED("PersistentCacheLoad"); std::stringstream ss; std::ifstream in(path, std::ios::binary); ss << in.rdbuf(); diff --git a/torch_xla/csrc/runtime/computation_client.h b/torch_xla/csrc/runtime/computation_client.h index 33b48255baf..a66ae2a7fa4 100644 --- a/torch_xla/csrc/runtime/computation_client.h +++ b/torch_xla/csrc/runtime/computation_client.h @@ -27,6 +27,8 @@ #include "xla/client/xla_computation.h" #include "xla/hlo/ir/hlo_module.h" #include "xla/literal_util.h" +#include "xla/pjrt/pjrt_client.h" +#include "xla/pjrt/pjrt_common.h" #include "xla/types.h" namespace torch_xla { @@ -191,6 +193,10 @@ class ComputationClient { return module->ToString(); } + virtual const std::string get_memory_info() const { + XLA_ERROR() << "Unimplemented"; + } + private: xla::XlaComputation computation_; xla::ProgramShape program_shape_; @@ -246,8 +252,8 @@ class ComputationClient { struct ExecuteReplicatedOptions : public ClientExecuteOptions {}; struct MemoryInfo { - int64_t kb_free = 0; - int64_t kb_total = 0; + int64_t bytes_used = 0; + int64_t bytes_limit = 0; }; virtual ~ComputationClient() {} @@ -275,6 +281,9 @@ class ComputationClient { // structure will be empty if there is no sharding, like with PjRtData. virtual std::optional GetDataSharding(DataPtr handle) = 0; + virtual std::string PjRtDeviceToString( + xla::PjRtDevice* const device) const = 0; + // Transfers local tensor values to the TPU devices and fetches the handles. virtual std::vector TransferToDevice( absl::Span> tensors) = 0; @@ -302,6 +311,11 @@ class ComputationClient { virtual std::vector TransferFromDevice( absl::Span handles) = 0; + virtual std::uintptr_t UnsafeBufferPointer(const DataPtr handle) = 0; + + virtual std::shared_ptr GetPjRtBuffer( + const DataPtr handle) = 0; + // Compiles a set of computations. virtual std::vector Compile( std::vector instances) = 0; @@ -342,6 +356,13 @@ class ComputationClient { virtual torch_xla::DeviceType GetDeviceType() const = 0; + virtual xla::PjRtPlatformId GetPlatformID() const = 0; + + virtual absl::StatusOr LookupAddressableDevice( + int local_device_id) const = 0; + + virtual std::intptr_t GetCudaStreamForDevice(int local_device_id) const = 0; + virtual size_t GetNumDevices() const = 0; virtual std::vector GetLocalDevices() const = 0; diff --git a/torch_xla/csrc/runtime/ifrt_computation_client.cc b/torch_xla/csrc/runtime/ifrt_computation_client.cc index 029f9268342..e15cd238c0d 100644 --- a/torch_xla/csrc/runtime/ifrt_computation_client.cc +++ b/torch_xla/csrc/runtime/ifrt_computation_client.cc @@ -58,18 +58,6 @@ torch::lazy::hash_t hash_comp_env( xla::ifrt::Client* client, std::vector& ordered_devices) { torch::lazy::hash_t hash = hash::HashXlaEnvVars(); - auto topology_desc = client->GetTopologyForDevices(ordered_devices); - if (topology_desc.ok()) { - // Some backends support a topology description which provides a better - // view of the specific compilation environment. - auto serialized = topology_desc.value()->Serialize(); - if (serialized.ok()) { - return torch::lazy::HashCombine( - hash, - torch::lazy::DataHash(serialized->data(), serialized->length())); - } - // If serialization fails, fallthrough to the manual approach. - } std::string platform_name(client->platform_name()); std::string platform_version(client->platform_version()); hash = torch::lazy::HashCombine( @@ -78,10 +66,26 @@ torch::lazy::hash_t hash_comp_env( hash = torch::lazy::HashCombine( hash, torch::lazy::StringHash(platform_version.c_str())); // Include global devices in the hash, ensuring order is consistent. + xla::ifrt::DeviceList::Devices ifrt_devices; for (auto& device : ordered_devices) { std::string device_str(device->ToString()); hash = torch::lazy::HashCombine( hash, torch::lazy::StringHash(device_str.c_str())); + ifrt_devices.push_back(device); + } + + xla::ifrt::DeviceList device_list(std::move(ifrt_devices)); + auto topology_desc = client->GetTopologyForDevices(device_list); + if (topology_desc.ok()) { + // Some backends support a topology description which provides a better + // view of the specific compilation environment. + auto serialized = topology_desc.value()->Serialize(); + if (serialized.ok()) { + return torch::lazy::HashCombine( + hash, + torch::lazy::DataHash(serialized->data(), serialized->length())); + } + // If serialization fails, fallthrough to the manual approach. } return hash; } @@ -92,7 +96,7 @@ std::string IfrtComputationClient::IfrtDeviceToString( xla::ifrt::Device* const device) const { std::string platform = absl::AsciiStrToUpper(device->client()->platform_name()); - int ordinal = global_ordinals_.at(device->id()); + int ordinal = global_ordinals_.at(device->Id().value()); std::string str = absl::StrFormat("%s:%d", platform, ordinal); return str; } @@ -120,11 +124,12 @@ IfrtComputationClient::IfrtComputationClient() { // a device's global ordinal separately from its device ID. Order the // devices by increasing ID to assign global ordinals. std::vector ordered_devices(client_->device_count()); - std::partial_sort_copy(client_->devices().begin(), client_->devices().end(), - ordered_devices.begin(), ordered_devices.end(), - [](auto& a, auto& b) { return a->id() < b->id(); }); + std::partial_sort_copy( + client_->devices().begin(), client_->devices().end(), + ordered_devices.begin(), ordered_devices.end(), + [](auto& a, auto& b) { return a->Id().value() < b->Id().value(); }); for (auto* device : ordered_devices) { - global_ordinals_[device->id()] = global_ordinals_.size(); + global_ordinals_[device->Id().value()] = global_ordinals_.size(); std::string device_str = IfrtDeviceToString(device); string_to_device_.emplace(device_str, device); } @@ -392,6 +397,16 @@ tsl::RCReference IfrtComputationClient::ReplicateShardedData( return *replicated_output; } +std::uintptr_t IfrtComputationClient::UnsafeBufferPointer( + const DataPtr handle) { + XLA_ERROR() << __FUNCTION__ << " not implemented"; +} + +std::shared_ptr IfrtComputationClient::GetPjRtBuffer( + const DataPtr handle) { + XLA_ERROR() << __FUNCTION__ << " not implemented"; +} + std::vector IfrtComputationClient::TransferFromDevice( absl::Span handles) { metrics::TimedSection timed(TransferFromDeviceMetric()); @@ -470,7 +485,7 @@ std::vector IfrtComputationClient::Compile( &mlir_module); std::unique_ptr executable = ConsumeValue(client_->GetDefaultCompiler()->Compile( - std::make_unique(std::move(mlir_module)), + std::make_unique(std::move(mlir_module)), std::make_unique(compile_options))); StableHloCompileCounter()->AddValue(1); @@ -611,7 +626,7 @@ std::vector IfrtComputationClient::GetAllDevices() const { int IfrtComputationClient::GetNumProcesses() const { int max_process_index = client_->process_index(); for (auto* device : client_->devices()) { - max_process_index = std::max(max_process_index, device->process_index()); + max_process_index = std::max(max_process_index, device->ProcessIndex()); } return max_process_index + 1; diff --git a/torch_xla/csrc/runtime/ifrt_computation_client.h b/torch_xla/csrc/runtime/ifrt_computation_client.h index d6d914ad8da..59664d045e8 100644 --- a/torch_xla/csrc/runtime/ifrt_computation_client.h +++ b/torch_xla/csrc/runtime/ifrt_computation_client.h @@ -16,6 +16,7 @@ #include "xla/literal.h" #include "xla/pjrt/pjrt_client.h" #include "xla/pjrt/pjrt_executable.h" +#include "xla/python/ifrt/hlo/hlo_program.h" #include "xla/python/pjrt_ifrt/pjrt_array.h" #include "xla/python/pjrt_ifrt/pjrt_client.h" #include "xla/python/pjrt_ifrt/xla_compiler.h" @@ -54,6 +55,10 @@ class IfrtComputationClient : public ComputationClient { std::vector TransferFromDevice( absl::Span handles) override; + std::uintptr_t UnsafeBufferPointer(const DataPtr handle) override; + + std::shared_ptr GetPjRtBuffer(const DataPtr handle) override; + DataPtr TransferShardsToDevice( absl::Span> tensor_shards, std::string device, xla::Shape shape, xla::OpSharding sharding) override; @@ -82,6 +87,19 @@ class IfrtComputationClient : public ComputationClient { absl::AsciiStrToUpper(client_->platform_name())); }; + xla::PjRtPlatformId GetPlatformID() const override { + return client_->platform_id(); + } + + absl::StatusOr LookupAddressableDevice( + int local_device_id) const override { + XLA_ERROR() << __FUNCTION__ << " not implemented"; + } + + std::intptr_t GetCudaStreamForDevice(int local_device_id) const override { + XLA_ERROR() << __FUNCTION__ << " not implemented"; + } + std::vector GetLocalDevices() const override; std::vector GetAllDevices() const override; @@ -119,6 +137,10 @@ class IfrtComputationClient : public ComputationClient { XLA_ERROR() << __FUNCTION__ << " not implemented"; }; + std::string PjRtDeviceToString(xla::PjRtDevice* const device) const override { + XLA_ERROR() << __FUNCTION__ << " not implemented"; + } + std::string SerializeComputation(const ComputationPtr computation) override { XLA_ERROR() << __FUNCTION__ << " not implemented"; } @@ -134,7 +156,7 @@ class IfrtComputationClient : public ComputationClient { // global_ordinals_ tracks a map from PjRtDeviceId to the device's // dense global ordinal. std::unordered_map global_ordinals_; - std::unordered_map string_to_device_; + std::unordered_map string_to_device_; std::shared_ptr> replication_devices_; OperationManager operation_manager_; tsl::thread::ThreadPool pool_ = tsl::thread::ThreadPool( diff --git a/torch_xla/csrc/runtime/pjrt_computation_client.cc b/torch_xla/csrc/runtime/pjrt_computation_client.cc index 188e26f8ac2..55089014152 100644 --- a/torch_xla/csrc/runtime/pjrt_computation_client.cc +++ b/torch_xla/csrc/runtime/pjrt_computation_client.cc @@ -8,7 +8,6 @@ #include "absl/strings/ascii.h" #include "absl/synchronization/blocking_counter.h" #include "absl/types/span.h" -#include "pjrt_computation_client.h" #include "torch_xla/csrc/runtime/computation_client.h" #include "torch_xla/csrc/runtime/debug_macros.h" #include "torch_xla/csrc/runtime/env_hash.h" @@ -185,6 +184,13 @@ ComputationClient::DataPtr PjRtComputationClient::CreateDataPlaceholder( return std::make_shared(std::move(device), std::move(shape)); } +ComputationClient::DataPtr PjRtComputationClient::CreateData( + std::string device, xla::Shape shape, + std::shared_ptr pjrt_buffer) { + return std::make_shared(std::move(device), std::move(shape), + pjrt_buffer); +} + std::vector PjRtComputationClient::GetDataShards( ComputationClient::DataPtr data) { tsl::profiler::TraceMe activity("PjRtComputationClient::GetDataShards", @@ -458,12 +464,42 @@ std::vector PjRtComputationClient::ReshardData( return resharded_results; } +std::uintptr_t PjRtComputationClient::UnsafeBufferPointer( + const DataPtr handle) { + std::shared_ptr pjrt_data = + std::dynamic_pointer_cast(handle); + XLA_CHECK(pjrt_data) << "handle must be PjRtData, got " << handle->ToString(); + XLA_CHECK(pjrt_data->buffer != nullptr) + << "PjRt buffer is null in " << __FUNCTION__; + xla::StatusOr ptr = + client_->UnsafeBufferPointer(pjrt_data->buffer.get()); + XLA_CHECK(ptr.ok()); + return ptr.value(); +} + +std::shared_ptr PjRtComputationClient::GetPjRtBuffer( + const DataPtr handle) { + std::shared_ptr pjrt_data = + std::dynamic_pointer_cast(handle); + + XLA_CHECK(pjrt_data) << "handle must be PjRtData, got " << handle->ToString(); + std::shared_ptr pjrt_buffer = pjrt_data->buffer; + if (pjrt_buffer != nullptr) { + return pjrt_buffer; + } else { + TF_VLOG(3) << "The pjrt buffer is null so we need to wait for device ops " + "to finish."; + WaitDeviceOps({}); + return std::dynamic_pointer_cast(handle)->buffer; + } +} + std::vector PjRtComputationClient::TransferFromDevice( absl::Span handles) { metrics::TimedSection timed(TransferFromDeviceMetric()); tsl::profiler::TraceMe activity("PjRtComputationClient::TransferFromDevice", tsl::profiler::TraceMeLevel::kInfo); - std::vector> futures; + std::vector> futures; futures.reserve(handles.size()); std::vector literals; literals.reserve(handles.size()); @@ -472,7 +508,9 @@ std::vector PjRtComputationClient::TransferFromDevice( // Use XLA replication to reassemble the sharded data. If input handle // is not sharded, then it is a no-op. std::shared_ptr pjrt_data = ReplicateShardedData(handle); - XLA_CHECK(pjrt_data); + XLA_CHECK(pjrt_data) << "PjRt_data is null in " << __FUNCTION__; + XLA_CHECK(pjrt_data->buffer != nullptr) + << "PjRt buffer is null in " << __FUNCTION__; xla::Literal& literal = literals.emplace_back(host_output_shape(pjrt_data->buffer.get())); @@ -482,7 +520,8 @@ std::vector PjRtComputationClient::TransferFromDevice( } for (auto& future : futures) { absl::Status status = future.Await(); - XLA_CHECK_OK(status); + XLA_CHECK_OK(status) << "Failed to await future from buffer to literal in" + << __FUNCTION__; } InboundDataMetric()->AddSample(total_size); @@ -580,6 +619,14 @@ std::vector PjRtComputationClient::Compile( client_->Compile(instance.computation, compile_options).value(); } + auto memory_stats_status_or = executable->GetCompiledMemoryStats(); + if (memory_stats_status_or.ok()) { + xla::CompiledMemoryStats memory_stats = memory_stats_status_or.value(); + TF_VLOG(3) << "memory usage detail = " << memory_stats.DebugString(); + } else { + TF_VLOG(3) << "memory usage is not availiable"; + } + const auto& hlo_modules = ConsumeValue(executable->GetHloModules()); xla::HloComputation* hlo_computation = hlo_modules[0]->entry_computation(); std::shared_ptr pjrt_computation = @@ -679,7 +726,7 @@ PjRtComputationClient::ExecuteComputation( TF_VLOG(5) << "ExecuteComputation acquiring PJRT device lock for " << device << " Done"; - std::optional> returned_future; + std::optional> returned_future; std::vector> results = pjrt_computation.executable ->ExecuteSharded(buffers, pjrt_device, execute_options, @@ -779,8 +826,8 @@ PjRtComputationClient::ExecuteReplicated( TF_VLOG(5) << "ExecuteReplicated acquiring PJRT device lock for " << spmd_device_str << " Done"; - std::optional>> returned_futures = - std::vector>(); + std::optional>> returned_futures = + std::vector>(); std::vector>> results; { tsl::profiler::TraceMe activity( @@ -915,5 +962,19 @@ std::map PjRtComputationClient::GetMetrics() const { return {}; } +ComputationClient::MemoryInfo PjRtComputationClient::GetMemoryInfo( + const std::string& device) { + XLA_CHECK_NE(device, spmd_device_str) + << "MemoryInfo not supported for SPMD virtual device."; + xla::PjRtDevice* pjrt_device = + PjRtComputationClient::StringToPjRtDevice(device); + tsl::AllocatorStats stats = pjrt_device->GetAllocatorStats().value(); + + return { + stats.bytes_in_use, + *stats.bytes_limit, + }; +} + } // namespace runtime } // namespace torch_xla diff --git a/torch_xla/csrc/runtime/pjrt_computation_client.h b/torch_xla/csrc/runtime/pjrt_computation_client.h index 9a911c0139b..1d31107e6b9 100644 --- a/torch_xla/csrc/runtime/pjrt_computation_client.h +++ b/torch_xla/csrc/runtime/pjrt_computation_client.h @@ -32,6 +32,9 @@ class PjRtComputationClient : public ComputationClient { std::string device, xla::Shape shape, std::optional sharding = std::nullopt) override; + static DataPtr CreateData(std::string device, xla::Shape shape, + std::shared_ptr pjrt_buffer); + std::vector GetDataShards(DataPtr data) override; DataPtr GetDataShard(DataPtr data, size_t index) override; @@ -55,6 +58,10 @@ class PjRtComputationClient : public ComputationClient { std::vector TransferFromDevice( absl::Span handles) override; + std::uintptr_t UnsafeBufferPointer(const DataPtr handle) override; + + std::shared_ptr GetPjRtBuffer(const DataPtr handle) override; + DataPtr TransferShardsToDevice( absl::Span> tensor_shards, std::string device, xla::Shape shape, xla::OpSharding sharding) override; @@ -87,6 +94,27 @@ class PjRtComputationClient : public ComputationClient { absl::AsciiStrToUpper(client_->platform_name())); }; + xla::PjRtPlatformId GetPlatformID() const override { + return client_->platform_id(); + } + + absl::StatusOr LookupAddressableDevice( + int local_device_id) const override { + return client_->LookupAddressableDevice( + xla::PjRtLocalDeviceId(local_device_id)); + } + + std::intptr_t GetCudaStreamForDevice(int local_device_id) const override { + absl::StatusOr pjrt_device = + client_->LookupAddressableDevice( + xla::PjRtLocalDeviceId(local_device_id)); + XLA_CHECK(pjrt_device.ok()) << "Failed to get a PjRt device."; + absl::StatusOr stream = + pjrt_device.value()->GetStreamForExternalReadyEvents(); + XLA_CHECK(stream.ok()) << "Failed to get a stream."; + return stream.value(); + } + std::vector GetLocalDevices() const override; std::vector GetAllDevices() const override; @@ -118,11 +146,11 @@ class PjRtComputationClient : public ComputationClient { bool CoordinatorInitialized() const override; - // NOT IMPLEMENTED + MemoryInfo GetMemoryInfo(const std::string& device) override; - MemoryInfo GetMemoryInfo(const std::string& device) override { - XLA_ERROR() << __FUNCTION__ << " not implemented"; - }; + std::string PjRtDeviceToString(xla::PjRtDevice* const device) const override; + std::vector PjRtDevicesToString( + absl::Span devices) const; private: std::unique_ptr client_; @@ -139,10 +167,6 @@ class PjRtComputationClient : public ComputationClient { xla::PjRtDevice* StringToPjRtDevice(const std::string& device); - std::string PjRtDeviceToString(xla::PjRtDevice* const device) const; - std::vector PjRtDevicesToString( - absl::Span devices) const; - struct PjRtData : public Data { PjRtData(std::string device, xla::Shape device_shape) : Data(std::move(device), std::move(device_shape)) {} @@ -261,6 +285,15 @@ class PjRtComputationClient : public ComputationClient { output_shardings_ = this->executable->GetOutputShardings(); } + const std::string get_memory_info() const override { + auto memory_stats_status_or = executable->GetCompiledMemoryStats(); + if (memory_stats_status_or.ok()) { + return memory_stats_status_or.value().DebugString(); + } else { + return "memory usage is not availiable"; + } + } + std::unique_ptr executable; std::optional> output_shardings_; }; diff --git a/torch_xla/csrc/runtime/pjrt_registry.cc b/torch_xla/csrc/runtime/pjrt_registry.cc index 648076757be..52b06d89cb4 100644 --- a/torch_xla/csrc/runtime/pjrt_registry.cc +++ b/torch_xla/csrc/runtime/pjrt_registry.cc @@ -21,8 +21,24 @@ namespace runtime { namespace { +// Placeholder plugin for testing only. Does not implement multiprocessing or +// configuration. Very likely will not work from Python code. +class LibraryPlugin : public PjRtPlugin { + public: + std::string library_path() const override { + return sys_util::GetEnvString("PJRT_LIBRARY_PATH", ""); + } + + const std::unordered_map + client_create_options() const override { + return {}; + } + + bool requires_xla_coordinator() const override { return false; } +}; + std::unordered_map> - pjrt_plugins_; + pjrt_plugins_ = {{"LIBRARY", std::make_shared()}}; xla::GpuAllocatorConfig GetGpuAllocatorConfig() { auto allocator_config = xla::GpuAllocatorConfig{}; @@ -60,7 +76,8 @@ InitializePjRt(const std::string& device_type) { std::unique_ptr client; std::unique_ptr coordinator; - if (sys_util::GetEnvBool(env::kEnvPjrtDynamicPlugins, false)) { + if (sys_util::GetEnvBool(env::kEnvPjrtDynamicPlugins, false) && + device_type != "CPU") { std::shared_ptr plugin = GetPjRtPlugin(device_type); if (plugin) { TF_VLOG(1) << "Initializing client for PjRt plugin " << device_type; diff --git a/torch_xla/csrc/runtime/stablehlo_composite_helper.cc b/torch_xla/csrc/runtime/stablehlo_composite_helper.cc index 3bc9e9cc309..5035fb221a0 100644 --- a/torch_xla/csrc/runtime/stablehlo_composite_helper.cc +++ b/torch_xla/csrc/runtime/stablehlo_composite_helper.cc @@ -7,9 +7,9 @@ #include "absl/log/log.h" #include "absl/strings/str_cat.h" +#include "mlir/Analysis/TopologicalSortUtils.h" #include "mlir/IR/IRMapping.h" #include "mlir/Support/LogicalResult.h" -#include "mlir/Transforms/TopologicalSortUtils.h" #include "single_include/nlohmann/json.hpp" #include "stablehlo/dialect/StablehloOps.h" diff --git a/torch_xla/csrc/runtime/xla_coordinator.h b/torch_xla/csrc/runtime/xla_coordinator.h index ae85c79a941..fb2cfaf99f5 100644 --- a/torch_xla/csrc/runtime/xla_coordinator.h +++ b/torch_xla/csrc/runtime/xla_coordinator.h @@ -3,8 +3,8 @@ #include -#include "tsl/distributed_runtime/preemption/preemption_sync_manager.h" #include "xla/pjrt/distributed/distributed.h" +#include "xla/tsl/distributed_runtime/preemption/preemption_sync_manager.h" namespace torch_xla { namespace runtime { diff --git a/torch_xla/csrc/tensor_methods.cpp b/torch_xla/csrc/tensor_methods.cpp index f27dc786fb5..7baa951c9a6 100644 --- a/torch_xla/csrc/tensor_methods.cpp +++ b/torch_xla/csrc/tensor_methods.cpp @@ -1,5 +1,6 @@ #include "torch_xla/csrc/tensor_methods.h" +#include #include #include #include @@ -40,6 +41,7 @@ #include "torch_xla/csrc/ops/count_nonzero.h" #include "torch_xla/csrc/ops/cumprod.h" #include "torch_xla/csrc/ops/cumsum.h" +#include "torch_xla/csrc/ops/custom_call.h" #include "torch_xla/csrc/ops/dequant_tensor.h" #include "torch_xla/csrc/ops/device_data.h" #include "torch_xla/csrc/ops/diagonal.h" @@ -48,6 +50,7 @@ #include "torch_xla/csrc/ops/dynamic_view.h" #include "torch_xla/csrc/ops/einsum.h" #include "torch_xla/csrc/ops/einsum_backward.h" +#include "torch_xla/csrc/ops/embedding_bag.h" #include "torch_xla/csrc/ops/expand.h" #include "torch_xla/csrc/ops/expand_symint.h" #include "torch_xla/csrc/ops/exponential.h" @@ -519,6 +522,41 @@ std::pair collective_permute( torch::lazy::Value(node, 1)}; } +std::vector custom_call( + const std::vector& inputs, const std::string& target, + const std::vector>& output_shapes, + const std::vector& output_dtypes, bool has_side_effect, + const std::string& backend_config, const int api_version) { + XLA_CHECK(inputs.size() > 0) << "inputs are empty"; + + std::vector values; + values.reserve(inputs.size()); + for (const auto& input : inputs) { + values.push_back(input->GetIrValue()); + } + + XLA_CHECK_EQ(output_shapes.size(), output_dtypes.size()); + std::vector output_xla_shapes; + output_xla_shapes.reserve(output_shapes.size()); + for (size_t i = 0; i < output_shapes.size(); ++i) { + output_xla_shapes.push_back(xla::ShapeUtil::MakeShape( + MakeXlaPrimitiveType(output_dtypes[i], &(inputs[0]->GetDevice())), + output_shapes[i])); + } + + auto node = torch::lazy::MakeNode( + values, target, xla::ShapeUtil::MakeTupleShape(output_xla_shapes), + has_side_effect, backend_config, api_version); + + std::vector outputs; + outputs.reserve(output_shapes.size()); + for (size_t i = 0; i < output_shapes.size(); ++i) { + outputs.push_back( + inputs[0]->CreateFrom(torch::lazy::Value(node, i), output_dtypes[i])); + } + return outputs; +} + void custom_sharding_( const XLATensorPtr& input, const std::shared_ptr& sharding_spec, @@ -1223,10 +1261,14 @@ XLATensorPtr div(const XLATensorPtr& input, const at::Scalar& other) { if (input_is_float) { scalar_type = MaybeUpcastToHostTorchType(input_type); } - torch::lazy::Value input_value = GetFloatingIrValue(input, scalar_type); + at::ScalarType op_math_type = at::toOpMathType(scalar_type); + torch::lazy::Value input_value = + torch::lazy::MakeNode(input->GetIrValue(), op_math_type); torch::lazy::Value other_value = XLAGraphExecutor::Get()->GetIrValueForScalar( - other, GetXlaShape(input_value).element_type(), input->GetDevice()); - return input->CreateFrom(Div(input_value, other_value), scalar_type); + other, XlaTypeFromTorchType(op_math_type), input->GetDevice()); + return input->CreateFrom( + torch::lazy::MakeNode(Div(input_value, other_value), scalar_type), + scalar_type); } XLATensorPtr einsum(const std::string& equation, @@ -1292,6 +1334,20 @@ XLATensorPtr embedding(const XLATensorPtr& weight, return tensor_ops::Embedding(weight, indices); } +std::tuple +embedding_bag(const XLATensorPtr& weight, const XLATensorPtr& indices, + const XLATensorPtr& offsets, int64_t mode, + const XLATensorPtr& per_sample_weights, + bool include_last_offset) { + torch::lazy::NodePtr node = torch::lazy::MakeNode( + weight->GetIrValue(), indices->GetIrValue(), offsets->GetIrValue(), mode, + per_sample_weights->GetIrValue(), include_last_offset); + return std::make_tuple(weight->CreateFrom(torch::lazy::Value(node, 0)), + weight->CreateFrom(torch::lazy::Value(node, 1)), + weight->CreateFrom(torch::lazy::Value(node, 2)), + weight->CreateFrom(torch::lazy::Value(node, 3))); +} + XLATensorPtr exp(const XLATensorPtr& input) { return input->CreateFrom(Exp(input->GetIrValue())); } diff --git a/torch_xla/csrc/tensor_methods.h b/torch_xla/csrc/tensor_methods.h index f27465fd67d..1d565dd351a 100644 --- a/torch_xla/csrc/tensor_methods.h +++ b/torch_xla/csrc/tensor_methods.h @@ -80,6 +80,12 @@ std::pair collective_permute( const XLATensorPtr& input, const torch::lazy::Value& token, std::vector> source_target_pairs); +std::vector custom_call( + const std::vector& inputs, const std::string& target, + const std::vector>& output_shapes, + const std::vector& output_dtypes, bool has_side_effect, + const std::string& backend_config, const int api_version); + void custom_sharding_( const XLATensorPtr& input, const std::shared_ptr& spec, @@ -381,6 +387,11 @@ XLATensorPtr embedding_dense_backward(const XLATensorPtr& grad_output, int64_t num_weights, int64_t padding_idx, bool scale_grad_by_freq); +std::tuple +embedding_bag(const XLATensorPtr& weight, const XLATensorPtr& indices, + const XLATensorPtr& offsets, int64_t mode, + const XLATensorPtr& per_sample_weights, bool include_last_offset); + XLATensorPtr embedding(const XLATensorPtr& weight, const XLATensorPtr& indices); XLATensorPtr eq(const XLATensorPtr& input, const at::Scalar& other); diff --git a/torch_xla/csrc/tensor_util.cpp b/torch_xla/csrc/tensor_util.cpp index dd13bd63d1b..8822b6de7c4 100644 --- a/torch_xla/csrc/tensor_util.cpp +++ b/torch_xla/csrc/tensor_util.cpp @@ -17,6 +17,7 @@ #include "torch_xla/csrc/dtype.h" #include "torch_xla/csrc/helpers.h" #include "torch_xla/csrc/layout_manager.h" +#include "torch_xla/csrc/ops/device_data.h" #include "torch_xla/csrc/runtime/computation_client.h" #include "torch_xla/csrc/runtime/debug_macros.h" #include "torch_xla/csrc/runtime/runtime.h" @@ -931,4 +932,24 @@ xla::PrimitiveType GetShapeDimensionType( return xla::PrimitiveType::S32; } +std::shared_ptr get_data_handle( + const at::Tensor& input) { + XLATensorPtr xtensor = bridge::GetXlaTensor(input); + if (xtensor->CurrentDataHandle() != nullptr) { + TF_VLOG(4) << "The xla tensor has a current data handle."; + return std::dynamic_pointer_cast( + xtensor->CurrentDataHandle()); + } else if (xtensor->CurrentIrValue().node != nullptr) { + DeviceData* device_data = + DeviceData::Cast(xtensor->CurrentIrValue().node.get()); + if (device_data != nullptr) { + return UnwrapXlaData(device_data->data()); + } + TF_VLOG(4) << "The xla tensor has IR value but does not have device data."; + } + TF_VLOG(4) + << "The xla tensor either has no current data handle or has no IR value."; + return nullptr; +} + } // namespace torch_xla diff --git a/torch_xla/csrc/tensor_util.h b/torch_xla/csrc/tensor_util.h index 7d726c00b50..0804d3e9f78 100644 --- a/torch_xla/csrc/tensor_util.h +++ b/torch_xla/csrc/tensor_util.h @@ -212,6 +212,9 @@ inline std::vector xla_expand_outplace(at::TensorList to_expand) { } } +std::shared_ptr get_data_handle( + const at::Tensor& input); + } // namespace torch_xla #endif // XLA_TORCH_XLA_CSRC_TENSOR_UTIL_H_ diff --git a/torch_xla/csrc/unwrap_data.h b/torch_xla/csrc/unwrap_data.h index 7d5080e84bf..6bf1cc60e0a 100644 --- a/torch_xla/csrc/unwrap_data.h +++ b/torch_xla/csrc/unwrap_data.h @@ -11,6 +11,9 @@ namespace torch_xla { +runtime::ComputationClient::DataPtr UnwrapXlaData( + const torch::lazy::BackendDataPtr& data); + std::vector UnwrapXlaData( absl::Span datas); diff --git a/torch_xla/csrc/xla_graph_executor.cpp b/torch_xla/csrc/xla_graph_executor.cpp index fe12e392ea4..660a4a0fb18 100644 --- a/torch_xla/csrc/xla_graph_executor.cpp +++ b/torch_xla/csrc/xla_graph_executor.cpp @@ -45,6 +45,7 @@ #include "torch_xla/csrc/runtime/computation_client.h" #include "torch_xla/csrc/runtime/debug_macros.h" #include "torch_xla/csrc/runtime/env_vars.h" +#include "torch_xla/csrc/runtime/pjrt_computation_client.h" #include "torch_xla/csrc/runtime/runtime.h" #include "torch_xla/csrc/runtime/stablehlo_helper.h" #include "torch_xla/csrc/runtime/sys_util.h" @@ -1396,6 +1397,7 @@ XLAGraphExecutor::CompilationResult XLAGraphExecutor::Compile( std::vector> computations = runtime::GetComputationClient()->Compile(std::move(instances)); + DebugUtil::post_compilation_analysis(computations[0]); TF_VLOG(3) << "Compiling IR graph hash " << torch::lazy::HashToString(coll.hash) << " on device " << coll.device << " done!"; diff --git a/torch_xla/csrc/xla_manual_registration.cpp b/torch_xla/csrc/xla_manual_registration.cpp index dc7df436ec7..6020ef6bc04 100644 --- a/torch_xla/csrc/xla_manual_registration.cpp +++ b/torch_xla/csrc/xla_manual_registration.cpp @@ -1,7 +1,9 @@ #include #include +#include "torch_xla/csrc/aten_cpu_fallback.h" #include "torch_xla/csrc/aten_xla_bridge.h" +#include "torch_xla/csrc/debug_util.h" #include "torch_xla/csrc/ops/nms.h" #include "torch_xla/csrc/ops/ops.h" #include "torch_xla/csrc/tensor_methods.h" @@ -11,10 +13,22 @@ namespace torch_xla { namespace manual { namespace { +struct NmsOp { + using schema = at::Tensor(const at::Tensor&, const at::Tensor&, double); + using ptr_schema = schema*; + STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "torchvision::nms") + STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "") +}; + at::Tensor nms_kernel(const at::Tensor& boxes, const at::Tensor& scores, double iou_threshold) { TORCH_LAZY_FN_COUNTER_TIMED_TRACING("xla::"); + if (!DebugUtil::ExperimentEnabled("nms")) { + return at::native::call_fallback_fn<&xla_cpu_fallback, NmsOp>::call( + boxes, scores, iou_threshold); + } + XLA_CHECK_EQ(boxes.dim(), 2) << "nms(): boxes should be a 2D tensor."; XLA_CHECK_EQ(boxes.size(1), 4) << "nms(): boxes should be a 2D tensor of shape [N, 4]."; diff --git a/torch_xla/debug/metrics.py b/torch_xla/debug/metrics.py index 363c52a80da..11718e8376b 100644 --- a/torch_xla/debug/metrics.py +++ b/torch_xla/debug/metrics.py @@ -79,3 +79,8 @@ def short_metrics_report(counter_names: list = None, metric_names: list = None): 'TransferToDeviceTime', 'TransferFromDeviceTime' ] return torch_xla._XLAC._short_xla_metrics_report(counter_names, metric_names) + + +def executed_fallback_ops(): + """Retrieves a list of operations that were run in fallback mode.""" + return torch_xla._XLAC._get_executed_fallback_ops() diff --git a/torch_xla/distributed/spmd/__init__.py b/torch_xla/distributed/spmd/__init__.py index abfe1c62ba0..099f25e9fb5 100644 --- a/torch_xla/distributed/spmd/__init__.py +++ b/torch_xla/distributed/spmd/__init__.py @@ -27,4 +27,6 @@ "_mark_manual_sharding", "enable_manual_sharding", "disable_manual_sharding", + "enable_manual_sharding", + "disable_manual_sharding", ] diff --git a/torch_xla/experimental/custom_kernel.py b/torch_xla/experimental/custom_kernel.py index ff4b335058b..1a8a8cd3852 100644 --- a/torch_xla/experimental/custom_kernel.py +++ b/torch_xla/experimental/custom_kernel.py @@ -2,11 +2,13 @@ import os import warnings +import numpy as np import torch import torch_xla import torch_xla.core.xla_model as xm +import torch_xla.distributed.spmd as xs -from typing import List, Callable +from typing import Any, List, Callable from torch.library import impl from torch_xla.core.xla_model import XLA_LIB @@ -17,7 +19,7 @@ def _extract_backend_config( module: "jaxlib.mlir._mlir_libs._mlir.ir.Module") -> str | None: """ This algorithm intends to extract the backend config from the compiler IR like the following, - and it is designed to traverse any generic MLIR module. + and it is not designed to traverse any generic MLIR module. module @jit_add_vectors attributes {mhlo.num_partitions = 1 : i32, mhlo.num_replicas = 1 : i32} { func.func public @main(%arg0: tensor<8xi32> {mhlo.layout_mode = "default", mhlo.sharding = "{replicated}"}, %arg1: tensor<8xi32> {mhlo.layout_mode = "default", mhlo.sharding = "{replicated}"}) -> (tensor<8xi32> {jax.result_info = "", mhlo.layout_mode = "default"}) { @@ -54,6 +56,48 @@ def jax_import_guard(): torch_xla._XLAC._init_computation_client() +def convert_torch_dtype_to_jax(dtype: torch.dtype) -> "jnp.dtype": + # Import JAX within the function such that we don't need to call the jax_import_guard() + # in the global scope which could cause problems for xmp.spawn. + jax_import_guard() + import jax.numpy as jnp + + if dtype == torch.float32: + if _XLA_USE_BF16: + return jnp.bfloat16 + return jnp.float32 + elif dtype == torch.float64: + if _XLA_USE_BF16: + return jnp.bfloat16 + return jnp.float64 + elif dtype == torch.float16: + return jnp.float16 + elif dtype == torch.bfloat16: + return jnp.bfloat16 + elif dtype == torch.int32: + return jnp.int32 + elif dtype == torch.int64: + return jnp.int64 + elif dtype == torch.int16: + return jnp.int16 + elif dtype == torch.int8: + return jnp.int8 + elif dtype == torch.uint8: + return jnp.uint8 + else: + raise ValueError(f"Unsupported dtype: {dtype}") + + +def to_jax_shape_dtype_struct(tensor: torch.Tensor) -> "jax.ShapeDtypeStruct": + # Import JAX within the function such that we don't need to call the jax_import_guard() + # in the global scope which could cause problems for xmp.spawn. + jax_import_guard() + import jax + + return jax.ShapeDtypeStruct(tensor.shape, + convert_torch_dtype_to_jax(tensor.dtype)) + + def trace_pallas(kernel: Callable, *args, static_argnums=None, @@ -63,43 +107,15 @@ def trace_pallas(kernel: Callable, # in the global scope which could cause problems for xmp.spawn. jax_import_guard() import jax - import jax.numpy as jnp import jax._src.pallas.mosaic.pallas_call_registration - def convert_torch_dtype_to_jax(dtype: torch.dtype) -> jnp.dtype: - if dtype == torch.float32: - if _XLA_USE_BF16: - return jnp.bfloat16 - return jnp.float32 - elif dtype == torch.float64: - if _XLA_USE_BF16: - return jnp.bfloat16 - return jnp.float64 - elif dtype == torch.float16: - return jnp.float16 - elif dtype == torch.bfloat16: - return jnp.bfloat16 - elif dtype == torch.int32: - return jnp.int32 - elif dtype == torch.int64: - return jnp.int64 - elif dtype == torch.int16: - return jnp.int16 - elif dtype == torch.int8: - return jnp.int8 - elif dtype == torch.uint8: - return jnp.uint8 - else: - raise ValueError(f"Unsupported dtype: {dtype}") - jax_args = [] # for tracing tensor_args = [] # for execution for i, arg in enumerate(args): # TODO: Could the args be a tuple of tensors or a list of tensors? Flattern them? if torch.is_tensor(arg): # ShapeDtypeStruct doesn't have any storage and thus is very suitable for generating the payload. - jax_meta_tensor = jax.ShapeDtypeStruct( - arg.shape, convert_torch_dtype_to_jax(arg.dtype)) + jax_meta_tensor = to_jax_shape_dtype_struct(arg) jax_args.append(jax_meta_tensor) tensor_args.append(arg) else: @@ -166,61 +182,129 @@ class FlashAttention(torch.autograd.Function): "block_k_dq": 256, "block_k_major_dq": 512, } + NUM_LANES = 128 + NUM_SUBLANES = 8 + + @staticmethod + def prepare_segment_ids(q_segment_ids, kv_segment_ids): + from jax.experimental.pallas.ops.tpu.flash_attention import SegmentIds + if q_segment_ids is None or kv_segment_ids is None: + return None, None, None + + assert q_segment_ids is not None and kv_segment_ids is not None, "Both q_segment_ids and kv_segment_ids should be provided." + segment_ids = SegmentIds( + to_jax_shape_dtype_struct(q_segment_ids), + to_jax_shape_dtype_struct(kv_segment_ids)) + q_segment_ids = q_segment_ids.unsqueeze(-1).expand( + [-1 for _ in q_segment_ids.shape] + [FlashAttention.NUM_LANES]) + kv_segment_ids = kv_segment_ids.unsqueeze(1).expand([ + kv_segment_ids.shape[0], FlashAttention.NUM_SUBLANES, + kv_segment_ids.shape[1] + ]) + return segment_ids, q_segment_ids, kv_segment_ids @staticmethod - def forward(ctx, q, k, v, causal=False): + def forward(ctx, q, k, v, causal, q_segment_ids, kv_segment_ids, sm_scale, + partition_spec, mesh): # Import JAX within the function such that we don't need to call the jax_import_guard() # in the global scope which could cause problems for xmp.spawn. jax_import_guard() + import jax from jax.experimental.pallas.ops.tpu.flash_attention import _flash_attention_impl ctx.causal = causal + ctx.sm_scale = sm_scale + ctx.partition_spec = partition_spec + ctx.mesh = mesh + ctx.full_shape = None save_residuals = q.requires_grad or k.requires_grad or v.requires_grad - # It returns the shape and type of o, l, m. - def shape_dtype(q, *arg): - if not save_residuals: - return [(q.shape, q.dtype)] + # SPMD integration. + # mark_sharding is in-placed, and therefore save the full q, k, v for the backward. + full_q = q + full_k = k + full_v = v + if partition_spec is not None: + ctx.full_shape = q.shape + q = xs.enable_manual_sharding(q, partition_spec, mesh=mesh).global_tensor + k = xs.enable_manual_sharding(k, partition_spec, mesh=mesh).global_tensor + v = xs.enable_manual_sharding(v, partition_spec, mesh=mesh).global_tensor + + # It computes the shape and type of o, l, m. + shapes = [q.shape] + dtypes = [q.dtype] + if save_residuals: res_shape = list(q.shape) res_shape[-1] = FlashAttention.MIN_BLOCK_SIZE - return [(q.shape, q.dtype), (res_shape, torch.float32), - (res_shape, torch.float32)] - - # We can't directly use flash_attention as we need to override the save_residuals flag which returns - # l and m that is needed for the backward. Then we lose all the shape checks. - # TODO: replicate the shape checks on flash_attention. - _flash_attention_impl = make_kernel_from_pallas(_flash_attention_impl, - shape_dtype) + for _ in range(2): + shapes.append(res_shape) + dtypes.append(torch.float32) + with torch.no_grad(): - o = _flash_attention_impl( + segment_ids, q_segment_ids, kv_segment_ids = FlashAttention.prepare_segment_ids( + q_segment_ids, kv_segment_ids) + ctx.segment_ids = segment_ids + + # We can't directly use flash_attention as we need to override the save_residuals flag which returns + # l and m that is needed for the backward. Then we lose all the shape checks. + # TODO: replicate the shape checks on flash_attention. + # Here we seperate the tracing and execution part just to support SegmentIds. + payload, _ = trace_pallas( + _flash_attention_impl, q, k, v, None, - None, + segment_ids, save_residuals, causal, - 1.0, + sm_scale, min(FlashAttention.DEFAULT_BLOCK_SIZES["block_b"], q.shape[0]), min(FlashAttention.DEFAULT_BLOCK_SIZES["block_q"], q.shape[2]), min(FlashAttention.DEFAULT_BLOCK_SIZES["block_k_major"], k.shape[2]), min(FlashAttention.DEFAULT_BLOCK_SIZES["block_k"], k.shape[2]), False, static_argnums=range(5, 13)) + + args = [q, k, v] + if segment_ids is not None: + args += [q_segment_ids, kv_segment_ids] + o = torch_xla._XLAC._xla_tpu_custom_call(args, payload, shapes, dtypes) + if not save_residuals: + o = o[0] + # SPMD integration + if partition_spec is not None: + o = xs.disable_manual_sharding( + o, partition_spec, ctx.full_shape, mesh=mesh).global_tensor return o o, *aux = o l, m = (v[..., 0] for v in aux[-2:]) - ctx.save_for_backward(q, k, v, o, l, m) + # SPMD integration + if partition_spec is not None: + o = xs.disable_manual_sharding( + o, partition_spec, ctx.full_shape, mesh=mesh).global_tensor + l = xs.disable_manual_sharding( + l, partition_spec[0:3], ctx.full_shape[0:3], mesh=mesh).global_tensor + m = xs.disable_manual_sharding( + m, partition_spec[0:3], ctx.full_shape[0:3], mesh=mesh).global_tensor + + ctx.save_for_backward(full_q, full_k, full_v, o, l, m, q_segment_ids, + kv_segment_ids) return o @staticmethod def backward(ctx, grad_output): from jax.experimental.pallas.ops.tpu.flash_attention import _flash_attention_bwd_dq, _flash_attention_bwd_dkv - q, k, v, o, l, m = ctx.saved_tensors + q, k, v, o, l, m, q_segment_ids, kv_segment_ids = ctx.saved_tensors causal = ctx.causal + sm_scale = ctx.sm_scale + partition_spec = ctx.partition_spec + mesh = ctx.mesh + full_shape = ctx.full_shape + segment_ids = ctx.segment_ids grad_q = grad_k = grad_v = None grad_i = torch.sum( @@ -234,6 +318,20 @@ def backward(ctx, grad_output): expanded_grad_i = grad_i.unsqueeze(-1).expand( [-1 for _ in grad_i.shape] + [FlashAttention.MIN_BLOCK_SIZE]) + # SPMD integration + if partition_spec is not None: + q = xs.enable_manual_sharding(q, partition_spec, mesh=mesh).global_tensor + k = xs.enable_manual_sharding(k, partition_spec, mesh=mesh).global_tensor + v = xs.enable_manual_sharding(v, partition_spec, mesh=mesh).global_tensor + expanded_l = xs.enable_manual_sharding( + expanded_l, partition_spec, mesh=mesh).global_tensor + expanded_m = xs.enable_manual_sharding( + expanded_m, partition_spec, mesh=mesh).global_tensor + grad_output = xs.enable_manual_sharding( + grad_output, partition_spec, mesh=mesh).global_tensor + expanded_grad_i = xs.enable_manual_sharding( + expanded_grad_i, partition_spec, mesh=mesh).global_tensor + if ctx.needs_input_grad[0]: payload, _ = trace_pallas( _flash_attention_bwd_dq, @@ -241,7 +339,7 @@ def backward(ctx, grad_output): k, v, None, - None, + segment_ids, l, m, grad_output, @@ -253,7 +351,7 @@ def backward(ctx, grad_output): k.shape[2]), block_k=min(FlashAttention.DEFAULT_BLOCK_SIZES["block_k_dq"], k.shape[2]), - sm_scale=1.0, + sm_scale=sm_scale, causal=causal, mask_value=FlashAttention.DEFAULT_MASK_VALUE, debug=False, @@ -261,9 +359,13 @@ def backward(ctx, grad_output): "block_q_major", "block_k_major", "block_k", "sm_scale", "causal", "mask_value", "debug" ]) - grad_q = torch_xla._XLAC._xla_tpu_custom_call( - [q, k, v, expanded_l, expanded_m, grad_output, expanded_grad_i], - payload, [q.shape], [q.dtype])[0] + + args = [q, k, v] + if segment_ids is not None: + args += [q_segment_ids, kv_segment_ids] + args += [expanded_l, expanded_m, grad_output, expanded_grad_i] + grad_q = torch_xla._XLAC._xla_tpu_custom_call(args, payload, [q.shape], + [q.dtype])[0] if ctx.needs_input_grad[1] or ctx.needs_input_grad[2]: payload, _ = trace_pallas( @@ -272,7 +374,7 @@ def backward(ctx, grad_output): k, v, None, - None, + segment_ids, l, m, grad_output, @@ -287,7 +389,7 @@ def backward(ctx, grad_output): k.shape[2]), block_q=min(FlashAttention.DEFAULT_BLOCK_SIZES["block_q_dkv"], q.shape[2]), - sm_scale=1.0, + sm_scale=sm_scale, causal=causal, mask_value=FlashAttention.DEFAULT_MASK_VALUE, debug=False, @@ -295,15 +397,29 @@ def backward(ctx, grad_output): "block_q_major", "block_k_major", "block_k", "block_q", "sm_scale", "causal", "mask_value", "debug" ]) - grads = torch_xla._XLAC._xla_tpu_custom_call( - [q, k, v, expanded_l, expanded_m, grad_output, expanded_grad_i], - payload, [k.shape, v.shape], [k.dtype, v.dtype]) + + args = [q, k, v] + if segment_ids is not None: + args += [q_segment_ids, kv_segment_ids] + args += [expanded_l, expanded_m, grad_output, expanded_grad_i] + grads = torch_xla._XLAC._xla_tpu_custom_call(args, payload, + [k.shape, v.shape], + [k.dtype, v.dtype]) if ctx.needs_input_grad[1]: grad_k = grads[0] if ctx.needs_input_grad[2]: grad_v = grads[1] - return grad_q, grad_k, grad_v, None + # SPMD integration + if partition_spec is not None: + grad_q = xs.disable_manual_sharding( + grad_q, partition_spec, full_shape, mesh=mesh).global_tensor + grad_k = xs.disable_manual_sharding( + grad_k, partition_spec, full_shape, mesh=mesh).global_tensor + grad_v = xs.disable_manual_sharding( + grad_v, partition_spec, full_shape, mesh=mesh).global_tensor + + return grad_q, grad_k, grad_v, None, None, None, None, None, None def flash_attention( @@ -311,8 +427,430 @@ def flash_attention( k, # [batch_size, num_heads, kv_seq_len, d_model] v, # [batch_size, num_heads, kv_seq_len, d_model] causal=False, -): - return FlashAttention.apply(q, k, v, causal) + q_segment_ids=None, # [batch_size, q_seq_len] + kv_segment_ids=None, # [batch_size, kv_seq_len] + sm_scale=1.0, + *, + partition_spec=None, + mesh=None): + # TODO: support SPMD and Dynamo with segment_ids. + return FlashAttention.apply(q, k, v, causal, q_segment_ids, kv_segment_ids, + sm_scale, partition_spec, mesh) + + +def paged_attention(q, + k_pages, + v_pages, + lengths, + page_indices, + pages_per_compute_block, + megacore_mode: str = None): + # Import JAX within the function such that we don't need to call the jax_import_guard() + # in the global scope which could cause problems for xmp.spawn. + jax_import_guard() + from jax.experimental.pallas.ops.tpu.paged_attention.paged_attention_kernel import paged_attention + + assert megacore_mode in [ + "kv_head", "batch", None + ], "megacore_mode must be one of ['kv_head', 'batch', None]." + + payload, tensor_args = trace_pallas( + paged_attention, + q, + k_pages, + v_pages, + lengths, + page_indices, + pages_per_compute_block=pages_per_compute_block, + megacore_mode=megacore_mode, + static_argnames=["pages_per_compute_block", "megacore_mode"], + ) + + batch_size, num_heads, head_dim = q.shape + num_kv_heads, _, page_size, head_dim_k = k_pages.shape + batch_size_paged_indices, pages_per_sequence = page_indices.shape + q_dtype_for_kernel_launch = q.dtype + if (num_heads // num_kv_heads) % 8 != 0: + q = q.reshape(batch_size, num_heads, 1, head_dim) + q_dtype_for_kernel_launch = torch.float32 + + page_indices_reshaped = page_indices.reshape(-1) + buffer_index = torch.zeros((1,), dtype=torch.int32).to("xla") + step = torch.zeros((1,), dtype=torch.int32).to("xla") + output_shape = torch.Size(list(q.shape[:-1]) + [1]) + + output, _, _ = torch_xla._XLAC._xla_tpu_custom_call( + [ + lengths, + page_indices_reshaped, + buffer_index, + step, + q.to(q_dtype_for_kernel_launch), + k_pages, + v_pages, + ], payload, [q.shape, output_shape, output_shape], + [q_dtype_for_kernel_launch, torch.float32, torch.float32]) + + return output.reshape(batch_size, num_heads, head_dim).to(q.dtype) + + +def _calculate_num_tiles(x: int, tx: int) -> int: + tiles, rem = divmod(x, tx) + if rem: + raise ValueError(f"{x} must be divisible by x-dimension tile size ({tx}).") + return tiles + + +def _histogram(input: torch.Tensor, min: int, max: int) -> torch.Tensor: + """ + Compute the histogram of a int32 tensor. The bin edges are defined by the min and max values, with step = 1. + """ + assert input.dtype == torch.int32, "input must be of torch.int32 dtype." + assert min <= max, "min must be less than or equal to max." + + def searchsorted(sorted_sequence: torch.Tensor, + values_to_search: torch.Tensor) -> torch.Tensor: + return (sorted_sequence.unsqueeze(1) == values_to_search).sum(dim=1) + + bin_edges = torch.linspace( + min, max, max - min + 1, dtype=input.dtype).to(input.device) + return searchsorted(bin_edges, input) + + +# Refence: https://github.com/google/jax/blob/main/jax/experimental/pallas/ops/tpu/megablox/gmm.py#L78 +def _make_group_metadata( + *, + group_sizes: torch.Tensor, + m: int, + tm: int, + visit_empty_groups: bool, +) -> Any: + """Create the metadata needed for grouped matmul computation. + + Args: + group_sizes: A 1d, torch.Tensor with shape [num_groups] and torch.int32 dtype. + m: The number of rows in lhs. + tm: The m-dimension tile size being used. + visit_empty_groups: If True, do not squeeze tiles for empty groups out of + the metadata. This is necessary for tgmm, where we at least need to zero + the output for each group. + + Returns: + tuple of: + group_offsets: A 1d, torch.Tensor with shape [num_groups + 1] and torch.int32 + dtype. group_offsets[i] indicates the row at which group [i] starts in + the lhs matrix and group_offsets[i-1] = m. + group_ids: A 1d, torch.Tensor with shape [m_tiles + num_groups - 1] and + torch.int32 dtype. group_ids[i] indicates which group grid index 'i' will + work on. + m_tile_ids: A 1d, torch.Tensor with shape [m_tiles + num_groups - 1] and + torch.int32. m_tile_ids[i] indicates which m-dimension tile grid index 'i' + will work on. + num_tiles: The number of m-dimension tiles to execute including overlapping + executions. And don't confuse this with m_tiles which is m // tm. + """ + assert group_sizes.dtype == torch.int32, "group_sizes must be of torch.int32 dtype." + + device = group_sizes.device + num_groups = group_sizes.shape[0] + + # Calculate the offset of each group, starting at zero. This metadata is + # similar to row offsets in a CSR matrix. The following properties hold: + # + # group_offsets.shape = [num_groups + 1] + # group_offsets[0] = 0 + # group_offsets[num_groups] = m + # + # The row at which group 'i' starts is group_offsets[i]. + group_ends = torch.cumsum(group_sizes, dim=0, dtype=torch.int32) + group_offsets = torch.cat( + [torch.zeros(1, dtype=torch.int32).to(device), group_ends]) + + # Assign a group id to each grid index. + # + # If a group starts somewhere other than the start of a tile or ends somewhere + # other than the end of a tile we need to compute that full tile. Calculate + # the number of tiles for each group by rounding their end up to the nearest + # 'tm' and their start down to the nearest 'tm'. + + # (1) Round the group_ends up to the nearest multiple of 'tm'. + # + # NOTE: This does not change group_offsets[num_groups], which is m + # (because we enforce m is divisible by tm). + rounded_group_ends = ((group_ends + tm - 1) // tm * tm).to(torch.int32) + + # (2) Round the group_starts down to the nearest multiple of 'tm'. + group_starts = torch.cat( + [torch.zeros(1, dtype=torch.int32).to(device), group_ends[:-1]]) + rounded_group_starts = group_starts // tm * tm + + # (3) Calculate the number of rows in each group. + # + # NOTE: Handle zero-sized groups as a special case. If the start for a + # zero-sized group is not divisible by 'tm' its start will be rounded down and + # its end will be rounded up such that its size will become 1 tile here. + rounded_group_sizes = rounded_group_ends - rounded_group_starts + rounded_group_sizes = torch.where(group_sizes == 0, 0, rounded_group_sizes) + + # (4) Convert the group sizes from units of rows to unit of 'tm' sized tiles. + # + # An m-dimension tile is 'owned' by group 'i' if the first row of the tile + # belongs to group 'i'. In addition to owned tiles, each group can have 0 or 1 + # initial partial tiles if it's first row does not occur in the first row of a + # tile. The '0-th' group never has a partial tile because it always starts at + # the 0-th row. + # + # If no group has a partial tile, the total number of tiles is equal to + # 'm // tm'. If every group has a partial except the 0-th group, the total + # number of tiles is equal to 'm // tm + num_groups - 1'. Thus we know that + # + # tiles_m <= group_tiles.sum() <= tiles_m + num_groups - 1 + # + # Where tiles_m = m // tm. + # + # NOTE: All group sizes are divisible by 'tm' because of the rounding in steps + # (1) and (2) so this division is exact. + group_tiles = rounded_group_sizes // tm + + if visit_empty_groups: + # Insert one tile for empty groups. + group_tiles = torch.where(group_sizes == 0, 1, group_tiles) + + # Create the group ids for each grid index based on the tile counts for each + # group. + # + # NOTE: This repeat(...) will pad group_ids with the final group id if + # group_tiles.sum() < tiles_m + num_groups - 1. The kernel grid will be sized + # such that we only execute the necessary number of tiles. + tiles_m = _calculate_num_tiles(m, tm) + group_ids = repeat_with_fixed_output_size( + torch.arange(num_groups, dtype=torch.int32).to(device), group_tiles, + tiles_m + num_groups - 1) + + # Assign an m-dimension tile id to each grid index. + # + # NOTE: Output tiles can only be re-visited consecutively. The following + # procedure guarantees that m-dimension tile indices respect this. + + # (1) Calculate how many times each m-dimension tile will be visited. + # + # Each tile is guaranteed to be visited once by the group that owns the tile. + # The remaining possible visits occur when a group starts inside of a tile at + # a position other than the first row. We can calculate which m-dimension tile + # each group starts in by floor-dividing its offset with `tm` and then count + # tile visits with a histogram. + # + # To avoid double counting tile visits from the group that owns the tile, + # filter these out by assigning their tile id to `tile_m` (one beyond the max) + # such that they're ignored by the subsequent histogram. Also filter out any + # group which is empty. + # + # TODO(tgale): Invert the 'partial_tile_mask' predicates to be more clear. + partial_tile_mask = torch.logical_or((group_offsets[:-1] % tm) == 0, + group_sizes == 0) + + # Explicitly enable tiles for zero sized groups, if specified. This covers + # zero sized groups that start on a tile-aligned row and those that do not. + if visit_empty_groups: + partial_tile_mask = torch.where(group_sizes == 0, False, partial_tile_mask) + + partial_tile_ids = torch.where(partial_tile_mask, tiles_m, + group_offsets[:-1] // tm) + + tile_visits = (_histogram(partial_tile_ids, min=0, max=tiles_m - 1) + 1) + + # Create the m-dimension tile ids for each grid index based on the visit + # counts for each tile. + m_tile_ids = repeat_with_fixed_output_size( + torch.arange(tiles_m, dtype=torch.int32).to(device), tile_visits, + tiles_m + num_groups - 1) + + num_tiles = group_tiles.sum(dtype=torch.int32) + return group_offsets, group_ids, m_tile_ids, num_tiles + + +# Repeat the `input` tensor `repeats` number of times. We expect `input` and +# `repeats` both be 1d tensor with same shape. output shape will be [total_repeat_length]. +# If `total_repeat_length` is larger than the repeated tensor length we will use the last value +# in the `input` to fill it up. If `total_repeat_length` is smaller than repeated tensor length +# we will truncate the repeated tensor. +def repeat_with_fixed_output_size(input: torch.Tensor, repeats: torch.Tensor, + total_repeat_length: int): + # currently only support 1d input and 1d repeats + assert len(input.size()) == 1 + assert len(repeats.size()) == 1 + device = input.device + + # to better understand this code, let's assume + # input.size() = [10] + # repeats = [0, 1, 2, 0, 4, 0, 6, 7, 8, 9] + # total_repeat_length = 20 + + # shift the repeats by one + # tensor([0, 0, 1, 2, 0, 4, 0, 6, 7, 8]) + exclusive_repeats = torch.roll(repeats, shifts=1) + exclusive_repeats[0] = 0 + + # tensor([ 0, 0, 1, 3, 3, 7, 7, 13, 20, 28]) + scatter_indices = torch.cumsum(exclusive_repeats, dim=0) + # set the out of bound indices to 0 and calculate how many of them. + # tensor([ 0, 0, 1, 3, 3, 7, 7, 13, 0, 0]) + valid_indices = torch.where(scatter_indices >= total_repeat_length, + torch.zeros_like(scatter_indices), + scatter_indices) + out_of_bound_count = torch.where(scatter_indices >= total_repeat_length, 1, + 0).sum() + + # tensor([2, 1, 0, 2, 0, 0, 0, 2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]) + block_split_indicators = torch.zeros( + total_repeat_length, dtype=torch.int32, device=device) + block_split_indicators.scatter_add_(0, valid_indices.to(torch.int64), + torch.ones_like(block_split_indicators)) + # out_of_bound indices also scatter to index 0, need to offset them + block_split_indicators[0] -= out_of_bound_count + + # value in gather_indices represents the index in the input. + # tensor([1, 2, 2, 4, 4, 4, 4, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7]) + gather_indices = torch.cumsum(block_split_indicators, dim=0) - 1 + res = torch.gather(input, 0, gather_indices) + return res + + +def gmm( + lhs: torch.Tensor, + rhs: torch.Tensor, + group_sizes: torch.Tensor, + tiling: tuple[int, int, int] = (512, 512, 512) +) -> torch.Tensor: + """Compute lhs[sizes[i-1]:sizes[i], :] @ rhs for each group 'i'. + + Args: + lhs: A 2d, torch.Tensor with shape [m, k]. + rhs: A 3d, torch.Tensor with shape [num_groups, k, n]. + group_sizes: A 1d, torch.Tensor with shape [num_groups] and torch.int32 dtype. + tiling: 3-tuple of ints. The m, k and n-dimension tile sizes. + + Returns: + A 2d, torch.Tensor with shape [m, n]. + """ + # Import JAX within the function such that we don't need to call the jax_import_guard() + # in the global scope which could cause problems for xmp.spawn. + jax_import_guard() + from jax.experimental.pallas.ops.tpu.megablox.gmm import gmm + + m, k, n = lhs.shape[0], lhs.shape[1], rhs.shape[2] + tm, tk, tn = min(tiling[0], m), min(tiling[1], k), min(tiling[2], n) + preferred_element_type = lhs.dtype + + payload, _ = trace_pallas( + gmm, + lhs, + rhs, + group_sizes, + static_argnames=["tiling", "preferred_element_type"], + preferred_element_type=convert_torch_dtype_to_jax(preferred_element_type), + tiling=(tm, tk, tn)) + + # Create the metadata we need for computation, and that's why need to separate + # the tracing and execution part. + group_offsets, group_ids, m_tile_ids, num_tiles = _make_group_metadata( + group_sizes=group_sizes, + m=m, + tm=tm, + visit_empty_groups=False, + ) + group_offset_torch = torch.tensor([0], dtype=torch.int32).to(lhs.device) + + return torch_xla._XLAC._xla_tpu_custom_call([ + num_tiles, group_offsets, group_ids, m_tile_ids, group_offset_torch, lhs, + rhs + ], payload, [torch.Size([m, n])], [preferred_element_type])[0] + + +def tgmm( + lhs: torch.Tensor, + rhs: torch.Tensor, + group_sizes: torch.Tensor, + tiling: tuple[int, int, int] = (512, 512, 512) +) -> torch.Tensor: + """Compute lhs[:, sizes[i-1]:sizes[i]] @ rhs[sizes[i-1]:sizes[i], :]. + + Args: + lhs: A 2d, torch.Tensor with shape [k, m]. + rhs: A 2d, torch.Tensor with shape [m, n]. + group_sizes: A 1d, torch.Tensor with shape [num_groups] and torch.int32 dtype. + tiling: 3-tuple of ints. The m, k and n-dimension tile sizes. + + Returns: + A 3d, torch.Tensor with shape [num_groups, k, n]. + """ + # Import JAX within the function such that we don't need to call the jax_import_guard() + # in the global scope which could cause problems for xmp.spawn. + jax_import_guard() + from jax.experimental.pallas.ops.tpu.megablox.gmm import tgmm + + k, m, n, num_groups = lhs.shape[0], lhs.shape[1], rhs.shape[ + 1], group_sizes.shape[0] + tm, tk, tn = min(tiling[0], m), min(tiling[1], k), min(tiling[2], n) + preferred_element_type = lhs.dtype + + payload, _ = trace_pallas( + tgmm, + lhs, + rhs, + group_sizes, + static_argnames=["tiling", "preferred_element_type"], + preferred_element_type=convert_torch_dtype_to_jax(preferred_element_type), + tiling=(tm, tk, tn)) + + # Create the metadata we need for computation, and that's why need to separate + # the tracing and execution part. + group_offsets, group_ids, m_tile_ids, num_tiles = _make_group_metadata( + group_sizes=group_sizes, + m=m, + tm=tm, + visit_empty_groups=True, + ) + group_offset_torch = torch.tensor([0], dtype=torch.int32).to(lhs.device) + + return torch_xla._XLAC._xla_tpu_custom_call([ + num_tiles, group_offsets, group_ids, m_tile_ids, group_offset_torch, + lhs.t(), rhs + ], payload, [torch.Size([num_groups, k, n])], [preferred_element_type])[0] + + +def gmm_backward(grad, lhs, rhs, group_sizes, tiling=(512, 512, 512)): + grad_lhs = gmm(grad, rhs.transpose(-1, -2), group_sizes, tiling) + grad_rhs = tgmm(lhs.t(), grad, group_sizes, tiling) + return grad_lhs, grad_rhs + + +class GMM(torch.autograd.Function): + + @staticmethod + def forward(ctx, lhs, rhs, group_sizes, tiling=(512, 512, 512)): + ctx.save_for_backward(lhs, rhs, group_sizes) + ctx.tiling = tiling + return gmm(lhs, rhs, group_sizes, tiling) + + @staticmethod + def backward(ctx, grad_output): + lhs, rhs, group_sizes = ctx.saved_tensors + grad_lhs, grad_rhs = gmm_backward(grad_output, lhs, rhs, group_sizes, + ctx.tiling) + return grad_lhs, grad_rhs, None, None + + +def non_xla_attetion(q, k, v, attention_type): + # This will be called when dynamo use fake tensor to construct the fake output. + # We need to make sure output tensor's shape is correct. + if k.device != torch.device("meta"): + warnings.warn( + f'XLA {attention_type} attention should only be applied to tensors on XLA device' + ) + + # Return orignal shape of q. + return torch.empty_like(q) XLA_LIB.define( @@ -333,14 +871,32 @@ def flash_attention_non_xla(q: torch.Tensor, k: torch.Tensor, v: torch.Tensor, causal: bool = False): - # This will be called when dynamo use fake tensor to construct the fake output. - # We need to make sure output tensor's shape is correct. - if k.device != torch.device("meta"): - warnings.warn( - 'XLA flash attention should only be applied to tensors on XLA device') + return non_xla_attetion(q, k, v, "flash") + + +XLA_LIB.define( + "paged_attention(Tensor q, Tensor k_pages, Tensor v_pages, Tensor lengths, Tensor page_indices, int pages_per_compute_block, str megacore_mode=None) -> Tensor", +) + - # perform a regular attention if input tensors are not on XLA device. - attn_weight = q @ k.transpose(-2, -1) - attn_weight = torch.nn.functional.softmax(attn_weight, dim=-1) - attn_output = attn_weight @ v - return attn_output +@impl(XLA_LIB, "paged_attention", "XLA") +def paged_attention_xla(q: torch.Tensor, + k_pages: torch.Tensor, + v_pages: torch.Tensor, + lengths: torch.Tensor, + page_indices: torch.Tensor, + pages_per_compute_block: int, + megacore_mode: str = None): + return paged_attention(q, k_pages, v_pages, lengths, page_indices, + pages_per_compute_block, megacore_mode) + + +@impl(XLA_LIB, "paged_attention", "CompositeExplicitAutograd") +def paged_attention_non_xla(q: torch.Tensor, + k_pages: torch.Tensor, + v_pages: torch.Tensor, + lengths: torch.Tensor, + page_indices: torch.Tensor, + pages_per_compute_block: int, + megacore_mode: str = None): + return non_xla_attetion(q, k_pages, v_pages, "paged") diff --git a/torch_xla/experimental/distributed_checkpoint/__init__.py b/torch_xla/experimental/distributed_checkpoint/__init__.py index cad57c3a405..a29b943f217 100644 --- a/torch_xla/experimental/distributed_checkpoint/__init__.py +++ b/torch_xla/experimental/distributed_checkpoint/__init__.py @@ -1,8 +1,10 @@ from .manager import CheckpointManager from .planners import SPMDSavePlanner, SPMDLoadPlanner +from .util import prime_optimizer __all__ = [ "CheckpointManager", "SPMDSavePlanner", "SPMDLoadPlanner", + "prime_optimizer", ] diff --git a/torch_xla/experimental/distributed_checkpoint/manager.py b/torch_xla/experimental/distributed_checkpoint/manager.py index 4ce57b5fb38..5d4ce7814e2 100644 --- a/torch_xla/experimental/distributed_checkpoint/manager.py +++ b/torch_xla/experimental/distributed_checkpoint/manager.py @@ -66,7 +66,10 @@ class CheckpointManager: >>> if tracked_steps: >>> # Choose the highest step >>> best_step = max(tracked_steps) - >>> state_dict = {'model': model.state_dict()} + >>> # Before restoring the checkpoint, the optimizer state must be primed + >>> # to allow state to be loaded into it. + >>> prime_optimizer(optim) + >>> state_dict = {'model': model.state_dict(), 'optim': optim.state_dict()} >>> chkpt_mgr.restore(best_step, state_dict) >>> model.load_state_dict(state_dict['model']) diff --git a/torch_xla/experimental/distributed_checkpoint/util.py b/torch_xla/experimental/distributed_checkpoint/util.py new file mode 100644 index 00000000000..198cb350323 --- /dev/null +++ b/torch_xla/experimental/distributed_checkpoint/util.py @@ -0,0 +1,44 @@ +import torch +from torch.utils._pytree import tree_map +import torch_xla +import torch_xla.core.xla_model as xm + + +def prime_optimizer(optimizer: torch.optim.Optimizer) -> torch.optim.Optimizer: + """ + Prime the optimizer state by running a dummy weight update. + + Optimizer state isn't created until after the first training step. Since the + distributed checkpointing library loads the state_dict in-place, the + optimizer state must already exist before loading the checkpoint. + + This utility method runs a dummy weight update with zero gradient to ensure + the optimizer state exists and can be loaded into. + + **Warning** This method calls `optimizer.step`, which can impact the + optimizer's state and model parameters. Therefore, it should only be used + prior to restoring a checkpoint, when the state and parameters will be + immediately overwritten. + + Args: + optimizer: The optimizer whose state should be primed for checkpoint + loading. + """ + + # Initial mark_step to ensure all param_groups are backed by device data. + xm.mark_step() + xm.wait_device_ops() + + def zero_grad(x): + if isinstance(x, torch.Tensor) and x.requires_grad: + x.grad = torch.zeros_like(x, requires_grad=False) + param_sharding = torch_xla._XLAC._get_xla_op_sharding(x) + if param_sharding: + # Match the gradient sharding to the parameter's. + torch_xla._XLAC._xla_mark_sharding(x.grad, param_sharding) + + tree_map(zero_grad, optimizer.param_groups) + optimizer.step() + xm.mark_step() + xm.wait_device_ops() + return optimizer diff --git a/torch_xla/experimental/plugins.py b/torch_xla/experimental/plugins.py index 77c2a572de3..620dff7e45c 100644 --- a/torch_xla/experimental/plugins.py +++ b/torch_xla/experimental/plugins.py @@ -76,7 +76,9 @@ def use_dynamic_plugins(): def using_dynamic_plugins(): - return xu.getenv_as(xenv.PJRT_DYNAMIC_PLUGINS, bool, False) + # TODO: dummy plugin for CPU + return xu.getenv_as(xenv.PJRT_DYNAMIC_PLUGINS, bool, + False) and xr.device_type() != "CPU" def default() -> DevicePlugin: diff --git a/torch_xla/experimental/spmd_fully_sharded_data_parallel.py b/torch_xla/experimental/spmd_fully_sharded_data_parallel.py index 461d66b8565..142f9bc7561 100644 --- a/torch_xla/experimental/spmd_fully_sharded_data_parallel.py +++ b/torch_xla/experimental/spmd_fully_sharded_data_parallel.py @@ -13,17 +13,24 @@ from torch_xla.distributed.fsdp.wrap import recursive_wrap -def _prepare_spmd_partition_spec(param): - partition_spec = [None] * len(param.shape) +def _prepare_spmd_partition_spec(param, + extra_data_axis=None, + shard_maximal=False): + shape = param.shape + partition_spec = [None] * len(shape) # Skip scalar tensors and it replicated. if len(partition_spec) == 0: return partition_spec - # Only shard the 0th dimension of the parameter according to the - # fsdp axis of the mesh. - # TODO: should we shard on the maximal dim for param? Then we need - # another helper for the output. - partition_spec[0] = "fsdp" + # Shard the 0th dimension of the parameter according to the + # fsdp axis of the mesh, if shard_maximal is not specified. + index = 0 + if shard_maximal: + index = shape.index(max(shape)) + + partition_spec[index] = "fsdp" + if extra_data_axis: + partition_spec[index] = (extra_data_axis, "fsdp") return tuple(partition_spec) @@ -44,10 +51,12 @@ class SpmdFullyShardedDataParallel(nn.Module): def __init__( self, module: nn.Module, + *, mesh: Optional[spmd.Mesh] = None, shard_output: Optional[Callable] = None, auto_wrap_policy: Optional[Callable] = None, auto_wrapper_callable: Optional[Callable] = None, + extra_data_axis: Optional[str] = None, ): if isinstance(module, SpmdFullyShardedDataParallel): raise RuntimeError( @@ -74,6 +83,9 @@ def __init__( ) if "fsdp" not in mesh.axis_names: raise ValueError("The mesh must have an axis named 'fsdp'.") + if extra_data_axis and extra_data_axis not in mesh.axis_names: + raise ValueError( + f"The provided {extra_data_axis} axis is not in the mesh.") super().__init__() @@ -106,7 +118,8 @@ def __init__( for param in module.parameters(): if torch_xla._XLAC._get_xla_sharding_spec(param) != "": continue - spmd.mark_sharding(param, mesh, _prepare_spmd_partition_spec(param)) + spmd.mark_sharding( + param, mesh, _prepare_spmd_partition_spec(param, shard_maximal=True)) # Register a backward hook to place optimization barrier to prevent # gigantic fusions on syncing the gradients. @@ -130,8 +143,9 @@ def shard_output_impl(output, mesh): f"The output type is not supported: {type(output)}. Please provide your own shard_output callable." ) - spmd.mark_sharding(real_output, mesh, - _prepare_spmd_partition_spec(real_output)) + spmd.mark_sharding( + real_output, mesh, + _prepare_spmd_partition_spec(real_output, extra_data_axis)) shard_output = shard_output_impl diff --git a/torch_xla/experimental/stablehlo_custom_call.py b/torch_xla/experimental/stablehlo_custom_call.py new file mode 100644 index 00000000000..e729d0b7791 --- /dev/null +++ b/torch_xla/experimental/stablehlo_custom_call.py @@ -0,0 +1,31 @@ +import torch +import torch_xla + + +# TODO(lsy323): Register as a torch op, cannot do that because parameter +# `ScalarType[] output_dtypes` in the op schema has some problem. +def stablehlo_custom_call(args, + call_target, + output_shapes, + output_dtypes, + has_side_effect=False, + backend_config="", + api_version=0): + res = torch_xla._XLAC._xla_custom_call(args, call_target, output_shapes, + output_dtypes, has_side_effect, + backend_config, api_version) + if len(output_shapes) == 1: + return res[0] + return res + + +def extract_custom_call_outputs_shape_dtype(n: torch.fx.Node): + assert 'val' in n.meta + if isinstance(n.meta['val'], torch.Tensor): + return [n.meta['val'].shape], [n.meta['val'].dtype] + output_shape_dtype = [(t.shape, + t.dtype) if isinstance(t, torch.Tensor) else None + for t in n.meta['val']] + assert None not in output_shape_dtype + output_shape, output_dtype = zip(*output_shape_dtype) + return output_shape, output_dtype diff --git a/torch_xla/experimental/xla_mlir_debuginfo.py b/torch_xla/experimental/xla_mlir_debuginfo.py index 4d12e20b2b2..e74617123be 100644 --- a/torch_xla/experimental/xla_mlir_debuginfo.py +++ b/torch_xla/experimental/xla_mlir_debuginfo.py @@ -8,7 +8,6 @@ # Enable debug info automatically when importing this file. This is necessary # to propagate any debug info to downstream MLIR locations. os.environ["XLA_HLO_DEBUG"] = "1" -xla_device = xm.xla_device() XLA_LIB.define("write_mlir_debuginfo(Tensor x, str data) -> Tensor") @@ -31,7 +30,7 @@ def write_mlir_debuginfo(x, data: str): @torch.library.impl(XLA_LIB, "write_mlir_debuginfo", "CompositeExplicitAutograd") -def write_mlir_debuginfo(x, data: str): +def write_mlir_debuginfo_tensor(x, data: str): return x diff --git a/torch_xla/stablehlo.py b/torch_xla/stablehlo.py index 3642354ab91..adf642f37a6 100644 --- a/torch_xla/stablehlo.py +++ b/torch_xla/stablehlo.py @@ -1,24 +1,27 @@ import copy -from dataclasses import dataclass +import dataclasses import enum import json import os -from typing import List, Tuple, Optional, Mapping, Any, Dict -import dataclasses +from dataclasses import dataclass, field +from typing import Any, Callable, Dict, List, Mapping, Optional, Set, Tuple import numpy as np import torch -from torch.fx import _pytree as fx_pytree import torch_xla -from torch_xla.core import xla_model as xm -from torch_xla.core import dynamo_bridge -from torch_xla.debug import metrics import torch_xla.experimental.quantized -from torch_xla.experimental.unbounded_dynamism_export import exported_program_has_symbolic_input_shape, process_exported_program_with_symbolic_input -from torch.utils import _pytree as pytree from torch._decomp import get_decompositions - -from typing import Tuple +from torch._export.serde.serialize import GraphModuleSerializer +from torch.fx import _pytree as fx_pytree +from torch.utils import _pytree as pytree +from torch_xla.core import dynamo_bridge +from torch_xla.core import xla_model as xm +from torch_xla.debug import metrics +from torch_xla.experimental.stablehlo_custom_call import ( + extract_custom_call_outputs_shape_dtype, stablehlo_custom_call) +from torch_xla.experimental.unbounded_dynamism_export import ( + exported_program_has_symbolic_input_shape, + process_exported_program_with_symbolic_input) def _get_numpy_dtype(dtype): @@ -59,6 +62,11 @@ class StableHLOExportOptions: # Whether to export the weights export_weights: bool = True + # Ops that will be mapped to stablehlo.custom_call in the + # exported StableHLO graph. + custom_ops_allowed_in_graph: Set[str] = field(default_factory=set) + # Export node metadata to NamedLoc in StableHLO. + export_node_metadata: bool = False class StableHLOGraphModule: @@ -214,10 +222,13 @@ class StableHLOModelBundle: class XLAExportInterpreter(torch.fx.Interpreter): - def __init__(self, module, device): + def __init__(self, module, device, custom_ops_allowed_in_graph, + gm_serializer): self._device = device super().__init__(module) self.tensor_id_to_dynamic_dims = {} + self.custom_ops_allowed_in_graph = custom_ops_allowed_in_graph + self.gm_serializer = gm_serializer def _mark_dynamic(self, tensor, dynamic_dims): tid = torch_xla._XLAC._xla_get_tensor_id(tensor) @@ -261,8 +272,24 @@ def run_node(self, n) -> Any: i for i, x in enumerate(fake_t.shape) if not isinstance(x, int) ] self._mark_dynamic(res, dynamic_dims) - return res - return super().run_node(n) + elif n.op == 'call_function': + if hasattr(n.target, 'namespace' + ) and n.target.namespace in self.custom_ops_allowed_in_graph: + output_shapes, output_dtypes = extract_custom_call_outputs_shape_dtype( + n) + call_name = str(n.target) + n.target = stablehlo_custom_call + n.args = (n.args, call_name, output_shapes, output_dtypes) + res = super().run_node(n) + else: + res = super().run_node(n) + if self.gm_serializer is not None: + from torch_xla.experimental.xla_mlir_debuginfo import write_mlir_debuginfo + node_metadata = json.dumps(self.gm_serializer.serialize_metadata(n)) + pytree.tree_map_only(torch.Tensor, + lambda x: write_mlir_debuginfo(x, node_metadata), + res) + return res def _extract_input_args(exported_model, options): @@ -320,7 +347,17 @@ def _exported_program_to_stablehlo_bundle(exported_model, if options.inline_all_constant: # Inline all constants. torch_xla._XLAC._set_xla_all_numbers_special_scalars(True) - xla_interpreter = XLAExportInterpreter(exported_model.graph_module, device) + xla_hlo_debug_env = os.environ.get("XLA_HLO_DEBUG", "0") + if options.export_node_metadata: + gm_serializer = GraphModuleSerializer(exported_model.graph_signature, + exported_model.module_call_graph) + os.environ["XLA_HLO_DEBUG"] = "1" + else: + gm_serializer = None + + xla_interpreter = XLAExportInterpreter(exported_model.graph_module, device, + options.custom_ops_allowed_in_graph, + gm_serializer) with torch.no_grad(): res = xla_interpreter.run(*_flat_input_args, enable_io_processing=False) res = res[num_mutations:] @@ -442,6 +479,8 @@ def _exported_program_to_stablehlo_bundle(exported_model, # Recover the global flag to not inline all scalars. torch_xla._XLAC._set_xla_all_numbers_special_scalars(False) + # Recover the global XLA_HLO_DEBUG flag + os.environ["XLA_HLO_DEBUG"] = xla_hlo_debug_env return bundle diff --git a/torch_xla/torch_xla.py b/torch_xla/torch_xla.py index 141d7e3e5a7..f5f56ba9cbc 100644 --- a/torch_xla/torch_xla.py +++ b/torch_xla/torch_xla.py @@ -1,4 +1,6 @@ +import contextlib from typing import List + import torch import torch_xla import torch_xla.core.xla_model as xm @@ -50,3 +52,20 @@ def device_count() -> int: def sync(): """Launches all pending graph operations.""" xm.mark_step() + + +@contextlib.contextmanager +def step(): + """Wraps code that should be dispatched to the runtime. + + Experimental: `xla.step` is still a work in progress. Some code that currently + works with `xla.step` but does not follow best practices will become errors in + future releases. See https://github.com/pytorch/xla/issues/6751 for context. + """ + # Clear pending operations + xm.mark_step() + + try: + yield + finally: + xm.mark_step() diff --git a/torch_xla/utils/dlpack.py b/torch_xla/utils/dlpack.py new file mode 100644 index 00000000000..c49083e4403 --- /dev/null +++ b/torch_xla/utils/dlpack.py @@ -0,0 +1,36 @@ +from typing import Any +import enum +import torch_xla + + +def to_dlpack(xla_tensor: Any): + return torch_xla._XLAC._to_dlpack(xla_tensor) + + +class DLDeviceType(enum.IntEnum): + # Enums as in DLPack specification (aten/src/ATen/dlpack.h) + kDLCPU = 1, + kDLGPU = 2, + kDLCPUPinned = 3, + kDLOpenCL = 4, + kDLVulkan = 7, + kDLMetal = 8, + kDLVPI = 9, + kDLROCM = 10, + kDLExtDev = 12, + kDLOneAPI = 14, + + +def from_dlpack(ext_tensor: Any): + if hasattr(ext_tensor, '__dlpack_device__') and hasattr( + ext_tensor, '__dlpack__'): + device_type, device_id = ext_tensor.__dlpack_device__() + if device_type == DLDeviceType.kDLGPU: + stream = torch_xla._XLAC._get_stream_for_cuda_device(device_id) + dlpack = ext_tensor.__dlpack__(stream=stream) + else: + dlpack = ext_tensor.__dlpack__() + else: + dlpack = ext_tensor + + return torch_xla._XLAC._from_dlpack(dlpack)