File size: 69,237 Bytes
8f1929a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 |
Joint inference and input optimization in equilibrium networks Swaminathan Gurumurthy Carnegie Mellon UniversityShaojie Bai Carnegie Mellon UniversityZachary Manchester Carnegie Mellon University J. Zico Kolter Carnegie Mellon University Bosch Center for AI Abstract Many tasks in deep learning involve optimizing over the inputs to a network to minimize or maximize some objective; examples include optimization over latent spaces in a generative model to match a target image, or adversarially perturbing an input to worsen classifier performance. Performing such optimization, however, is traditionally quite costly, as it involves a complete forward and backward pass through the network for each gradient step. In a separate line of work, a recent thread of research has developed the deep equilibrium (DEQ) model, a class of models that foregoes traditional network depth and instead computes the output of a network by finding the fixed point of a single nonlinear layer. In this paper, we show that there is a natural synergy between these two settings. Although, naively using DEQs for these optimization problems is expensive (owing to the time needed to compute a fixed point for each gradient step), we can leverage the fact that gradient- based optimization can itself be cast as a fixed point iteration to substantially improve the overall speed. That is, we simultaneously both solve for the DEQ fixed point andoptimize over network inputs, all within a single “augmented” DEQ model that jointly encodes both the original network and the optimization process. Indeed, the procedure is fast enough that it allows us to efficiently train DEQ models for tasks traditionally relying on an “inner” optimization loop. We demonstrate this strategy on various tasks such as training generative models while optimizing over latent codes, training models for inverse problems like denoising and inpainting, adversarial training and gradient based meta-learning. 1 Introduction Many settings in deep learning involve optimization over the inputs to a network to minimize some desired loss. For example, for a “generator” network G:Z!X that maps from latent space Zto an observed space X, it may be desirable to find a latent vector z2Z that most closely produces some target output x2X by solving the optimization problem (e.g. [10, 13]) minimize z2Zkx G(z)k2 2: (1) As another example, constructing adversarial examples for classifiers [ 28,53] typically involves optimizating over a perturbation to a given input; i.e., given a classifier network g:X!Y , task loss Correspondence to: Swaminathan Gurumurthy <[email protected]> Code available at https://github.com/locuslab/JIIO-DEQ Preprint. Under review.arXiv:2111.13236v1 [cs.LG] 25 Nov 2021`:Y!R+, and a sample x2X, we want to solve maximize kk`(g(x+)): (2) More generally, a wide range of inverse problems [ 10] and other auxiliary tasks [ 22,3] in deep learning can also be formulated in such a manner. Orthogonal to this line of work, a recent trend has focused on the use of an implicit layer within deep networks to avoid traditional depth. For instance, Bai et al. [5]introduced deep equilibrium models (DEQs) which instead treat the network as repeated applications of a single layer and compute the output of the network as a solution to an equilibrium-finding problem instead of simply specifying a sequence of non-linear layer operations. Bai et al. [5]and subsequent work [ 6] have shown that DEQs can achieve results competitive with traditional deep networks for many realistic tasks. In this work, we highlight the benefit of using these implicit models in the context of input optimization routines. Specifically, because optimization over inputs itself is typically done via an iterative method (e.g., gradient descent), we can combine this optimization fixed-point iteration with the forward DEQ fixed point iteration all within a single “augmented” DEQ model that simultaneously performs forward model inference as well as optimization over the inputs. This enables the models to more quickly perform both the inference and optimization procedures, and the resulting speedups further allow us to train networks that use such “bi-level” fixed point passes. In addition, we also show a close connection between our proposed approach and the primal-dual methods for constrained optimization. We illustrate our methods on 4 tasks that span across different domains and problems: 1) training DEQ-based generative models while optimizing over latent codes; 2) training models for inverse problems such as denoising and inpainting; 3) adversarial training of implicit models; and 4) gradient- based meta-learning. We show that in all cases, performing this simultaneous optimization and forward inference accelerates the process over a more naive inner/outer optimization approach. For instance, using the combined approach leads to a 3.5-9x speedup for generative DEQ networks, a 3x speedup in adverarial training of DEQ networks and a 2.5-3x speedup for gradient based meta-learning. In total, we believe this work points to a variety of new potential applications for optimization with implicit models. 2 Related Work Implicit layers. Layers with implicitly defined depth have gained tremendous popularity in recent years[ 46,19,29]. Rather than a static computation graph, these layers define a condition on the output that the model must satisfy, which can represent “infinite” depth, be directly differentiated through via the implicit function theorem [ 47], and are memory-efficient to train. Some recent examples of implicit layers include optimization layers [ 16,1], deep equilibrium models[ 5,6,68,40,52], neural ordinary differential equations (ODEs) [ 14,18,61], logical structure learning [ 67], and continuous generative models [30]. In particular, deep equilibrium models (DEQs) [ 5] define the output of the model as the fixed point of repeated applications of a layer. They compute this using black-box root-finding methods[ 5] or accelerated fixed-point iterations [ 36] (e.g., Broyden’s method [ 11]). In this work, we propose an efficient approach to perform input optimization with the DEQ by simultaneously optimizing over the inputs and solving the forward fixed point of an equilibrium model as a joint, augmented system. As related work, Jeon et al. [36] introduce fixed point iteration networks that generalize DEQs to repeated applications of gradient descent over variables. However, they don’t address the specific formulation presented in this paper, which has a number of practical use cases (e.g., adversarial training). Lu et al. [52] proposes an implicit version of normalizing flows by formulating a joint root-finding problem that defines an invertible function between the input xand outputz?. Perhaps the most relevant approach to our work is Gilton et al. [26], which specifically formulates inverse imaging problems as a DEQ model. In contrast, our approach focuses on solving input optimization problems where the network of interest is already a DEQ, and thus the combined optimization and forward inference task leads to a substantially different set of update equations and tradeoffs. 2Input optimization in deep learning. Many problems in deep learning can be framed as optimizing over the inputs to minimize some objective . Some canonical examples of this include finding adversarial examples [ 53,45], solving inverse problems [ 10,13,56], learning generative models [ 9, 72], meta-learning [ 58,22,74,32] etc. For most of these examples, input optimization is typically done using gradient descent on the input, i.e., we feed the input through the network and compute some loss, which we minimize by optimizing over the input with gradient descent. While some of these problems might not require differentiating through the entire optimization process, many do (introduced below), and can further slow down training and impose massive memory requirements. Input optimization has recently been applied to train generative models. Zadeh et al. [72], Bojanowski et al. [9]proposed to train generator networks by jointly optimizing the parameters and the latent variables corresponding to each example. Similarly, optimizing a latent variable to make the corresponding output match a target image is common in decoder-only models like GANs to get correspondences [ 10,39], and has been found useful to stabilize GAN training [ 71]. However, in all of these cases, the input is optimized for just a few (mostly 1) iterations. In this work, we present a generative model, where we optimize and find the optimal latent code for each image at each training step. Additionally, Bora et al. [10], Chang et al. [13] showed that we can take a pretrained generative model and use it as a prior to solve for the likely solutions to inverse problems by optimizing on the input space of the generative model (i.e., unsupervised inverse problem solving). Furthermore, Diamond et al. [15], Gilton et al. [25], Gregor and LeCun [31] have shown that networks can also be trained to solve specific inverse problems by effectively unrolling the optimization procedure and iteratively updating the input. We demonstrate our approach in the unsupervised setting as in Bora et al. [10], Chang et al. [13], but also show flexible extension of our framework to train implicit models for supervised inverse problem solving. Another crucial application of input optimization is to find adversarial examples [ 64,28]. This manifests as optimizing an objective that incentivices an incorrect prediction by the classifier, while constraining the input to be within a bounded region of the original input. Many attempts have been made on the defense side [ 57,37,65,69]. The most successful strategy thus far has been adversarial training with a projected gradient descent (PGD) adversary [ 53] which involves training the network on the adversarial examples computed using PGD online during training . We show that our joint optimization approach can be easily applied to this setting, allowing us to train implicit models to perform competitively with PGD in guaranteeing adversarial robustness, but at much faster speeds. While the examples above were illustrated with non-convex networks, attempts have also been made to design networks whose output is a convex function of the input [ 2]. This allows one to use more sophisticated optimization algorithms, but usually at a heavy cost of model capacity. They have been demonstrated to work in a variety of problems including multi-label prediction, image completion [2], learning stable dynamical systems [44] and optimal transport mappings [54], MPC [12], etc. 3 Joint inference and input optimization in DEQs Here we present our main methodological contribution, which sets up an augmented DEQ that jointly performs inference and input optimization over an existing DEQ model. We first define the base DEQ model, and then illustrate a joint approach that simultaneously finds it’s forward fixed point and optimizes over its inputs. We discuss several methodological details and extensions. 3.1 Preliminaries: DEQ-based models To begin with, we recall the deep equilibrium model setting from Bai et al. [5], but with the notation slightly adapted to better align with its usage in this paper. Specifically, we consider an input-injected layerf:ZX!Z whereZdenotes the hidden state of the network, Xdenotes the input space, anddenotes the parameters of the layer. Given an input x2X, computing the forward pass in a DEQ model involves finding a fixed point z?(x)2Z, such that z? (x) =f(z? (x);x); (3) which (under proper stability conditions) corresponds to the “infinite depth” limit of repeatedly applying the ffunction. We emphasize that under this setting, we can effectively think of z? itself 3as the implicitly defined network (which thus is also parameterized by ), and one can differentiate through this “network” via the implicit function theorem [8, 47]. The fixed point of a DEQ could be computed via the simple forward iteration z+:=f(z;x) (4) starting at some artibrary initial value of z(typically 0). However, in practice DEQ models will typically compute this fixed point not simply by iterating the function f, but by using a more accelerated root-finding or fixed-point approach such as Broyden’s method [ 11] or Anderson acceleration [ 4,66]. Further, although little can be said about e.g., the existence or uniqueness of these fixed points in general (though there do exist restrictive settings where this is possible [ 68,59,23]), in practice a wide suite of techniques have been used to ensure that such fixed points exist, can be found using relatively few function evaluations, and are able to competitively model large-scale tasks [ 5,6]. 3.2 Joint inference and input optimization Now we consider the setting of performing input optimization for such a DEQ model. Specifically, consider the task of attempting to optimize the input x2X to minimize some loss `:ZY! R+. minimize x2X`(z? (x);y) (5) wherey2Y represents the data point. To solve this, we typically perform such an optimization via e.g., gradient descent, which repeats the update x+:=x @`(z? (x);y) @x> (6) until convergence, where we use term z?alone to denote the fixed output of the network z? (i.e., just as a fixed output rather than a function). Using the chain rule and the implicit function theorem, we can further expand update (6) using the following analytical expression of the gradient: @`(z? (x);y) @x=@`(z?;y) @z?@z? (x) @x=@`(z?;y) @z? I @f(z?;x) z? >@f(z?;x) @x(7) Thinking about z? as an implicit function of xpermits us to combine the fixed-point equation in Eq. 4 (onz) with this input optimization update (on x), thus performing a joint forward update: z+ x+ :=f(z;x) x @f(z;x) @x> |