32
32
33
33
34
34
if TYPE_CHECKING :
35
+ from pytensor .compile .mode import Mode
35
36
from pytensor .link .vm import VM
36
37
37
38
@@ -1391,16 +1392,24 @@ def check_unused_inputs(inputs, outputs, on_unused_input):
1391
1392
1392
1393
@staticmethod
1393
1394
def prepare_fgraph (
1394
- inputs , outputs , additional_outputs , fgraph , rewriter , linker , profile
1395
+ inputs ,
1396
+ outputs ,
1397
+ additional_outputs ,
1398
+ fgraph : FunctionGraph ,
1399
+ mode : "Mode" ,
1400
+ profile ,
1395
1401
):
1396
1402
1403
+ rewriter = mode .optimizer
1404
+
1397
1405
try :
1398
1406
start_rewriter = time .perf_counter ()
1399
1407
1400
1408
rewriter_profile = None
1401
1409
rewrite_time = None
1402
1410
1403
1411
with config .change_flags (
1412
+ mode = mode ,
1404
1413
compute_test_value = config .compute_test_value_opt ,
1405
1414
traceback__limit = config .traceback__compile_limit ,
1406
1415
):
@@ -1440,7 +1449,7 @@ def prepare_fgraph(
1440
1449
stacklevel = 3 ,
1441
1450
)
1442
1451
1443
- if not hasattr (linker , "accept" ):
1452
+ if not hasattr (mode . linker , "accept" ):
1444
1453
raise ValueError (
1445
1454
"'linker' parameter of FunctionMaker should be "
1446
1455
f"a Linker with an accept method or one of { list (pytensor .compile .mode .predefined_linkers .keys ())} "
@@ -1511,12 +1520,8 @@ def __init__(
1511
1520
1512
1521
self .fgraph = fgraph
1513
1522
1514
- rewriter , linker = mode .optimizer , copy .copy (mode .linker )
1515
-
1516
1523
if not no_fgraph_prep :
1517
- self .prepare_fgraph (
1518
- inputs , outputs , found_updates , fgraph , rewriter , linker , profile
1519
- )
1524
+ self .prepare_fgraph (inputs , outputs , found_updates , fgraph , mode , profile )
1520
1525
1521
1526
assert len (fgraph .outputs ) == len (outputs + found_updates )
1522
1527
@@ -1528,6 +1533,8 @@ def __init__(
1528
1533
if not spec .borrow
1529
1534
]
1530
1535
1536
+ linker = copy .copy (mode .linker )
1537
+
1531
1538
if no_borrow :
1532
1539
self .linker = linker .accept (
1533
1540
fgraph ,
0 commit comments