Commit 9150f56
Save the current EMA varaibles to the checkpoint, instead of t-1.
Currently, Lingvo saves EMA(t-1) to the t-th checkpoint, as the train_op looks like,
def ConstructFPropBPropGraph(self):
self.ApplyExponentialMovingAverage() <-- update var_t-1 to ema var (ema_t-1)
self._task.FPropDefaultTheta()
self._task.BProp() <-- update var_t-1 to var_t
ema.apply() after BProp more makes sense, as is updates var_t and then updates
ema_t at global_step t.
But Lingvo runs ema.apply() first. It's because this method is used for both
graph construction and train step.
In graph construction, self._task.FPropDefaultTheta() may need EMA variables.
e.g. EMBR, EMA teacher, so on.
So, ConstructFPropBPropGraph() routine calls ema.apply() first to ensure EMA var.
It causes following confusion;
* After train_op, var_t and ema_t-1 are saved into the checkpoint at t.
* Evaler/Decoder step_ops are very confusing.
This issue can be solved by separating EMA variable creation and update,
althogh both use same TF API; ema.apply(). Especially it doesn't make sense
that graph construction method constructs EMA variables. EMA variables are
variables. It more makes sense that variable creation method (i.e.
mdl.Instantiate()) creates EMA variables. This CL makes the changes. After
that, ConstructFPropBPropGraph() doesn't need to call ema.apply() first,
because there is already EMA varaibles. The weird order of train_op is fixed.
It's more dramatic for evaler and decoder step_ops. Currently, Evaler's
ConstructFPropGraph() and Decoder's ConstructDecodeGraph() have to call
ema.apply(), only because of EMA variables creation. Evaler/Decoder must not
update EMA variables, which is Trainer's job. Those use EMA variable from the
checkpoint or trainer. Now we can remove the weird ema.apply() in
evaler/decoder_step_ops (i.e. tech debt).
PiperOrigin-RevId: 4885073491 parent 3bdda3f commit 9150f56
File tree
4 files changed
+84
-79
lines changed- lingvo/core
4 files changed
+84
-79
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1113 | 1113 | | |
1114 | 1114 | | |
1115 | 1115 | | |
1116 | | - | |
| 1116 | + | |
1117 | 1117 | | |
1118 | 1118 | | |
1119 | 1119 | | |
1120 | | - | |
| 1120 | + | |
| 1121 | + | |
1121 | 1122 | | |
1122 | 1123 | | |
1123 | 1124 | | |
1124 | 1125 | | |
1125 | 1126 | | |
1126 | 1127 | | |
1127 | 1128 | | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
1128 | 1141 | | |
1129 | 1142 | | |
1130 | 1143 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
748 | 749 | | |
749 | 750 | | |
750 | 751 | | |
751 | | - | |
| 752 | + | |
| 753 | + | |
752 | 754 | | |
753 | 755 | | |
754 | 756 | | |
755 | | - | |
| 757 | + | |
756 | 758 | | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
757 | 767 | | |
758 | 768 | | |
759 | 769 | | |
| |||
813 | 823 | | |
814 | 824 | | |
815 | 825 | | |
816 | | - | |
817 | | - | |
| 826 | + | |
| 827 | + | |
818 | 828 | | |
819 | 829 | | |
820 | 830 | | |
821 | 831 | | |
822 | | - | |
823 | | - | |
824 | | - | |
825 | | - | |
826 | | - | |
827 | | - | |
828 | | - | |
829 | | - | |
830 | | - | |
831 | | - | |
832 | | - | |
833 | | - | |
834 | | - | |
835 | | - | |
836 | | - | |
837 | | - | |
838 | | - | |
839 | | - | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
840 | 848 | | |
841 | 849 | | |
842 | 850 | | |
| |||
849 | 857 | | |
850 | 858 | | |
851 | 859 | | |
852 | | - | |
853 | | - | |
854 | | - | |
855 | | - | |
856 | 860 | | |
857 | | - | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
858 | 868 | | |
859 | 869 | | |
860 | 870 | | |
| |||
1199 | 1209 | | |
1200 | 1210 | | |
1201 | 1211 | | |
1202 | | - | |
| 1212 | + | |
1203 | 1213 | | |
1204 | 1214 | | |
1205 | | - | |
| 1215 | + | |
1206 | 1216 | | |
1207 | 1217 | | |
1208 | 1218 | | |
1209 | 1219 | | |
1210 | 1220 | | |
1211 | | - | |
1212 | | - | |
1213 | | - | |
1214 | 1221 | | |
1215 | 1222 | | |
1216 | 1223 | | |
| |||
1276 | 1283 | | |
1277 | 1284 | | |
1278 | 1285 | | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
1279 | 1296 | | |
1280 | 1297 | | |
1281 | 1298 | | |
| |||
1287 | 1304 | | |
1288 | 1305 | | |
1289 | 1306 | | |
1290 | | - | |
1291 | | - | |
1292 | | - | |
1293 | | - | |
1294 | | - | |
1295 | | - | |
1296 | | - | |
1297 | 1307 | | |
1298 | | - | |
1299 | 1308 | | |
1300 | 1309 | | |
1301 | 1310 | | |
1302 | | - | |
1303 | | - | |
1304 | | - | |
| 1311 | + | |
1305 | 1312 | | |
1306 | 1313 | | |
1307 | 1314 | | |
1308 | 1315 | | |
1309 | | - | |
1310 | 1316 | | |
1311 | | - | |
1312 | | - | |
1313 | 1317 | | |
1314 | 1318 | | |
1315 | 1319 | | |
| |||
1511 | 1515 | | |
1512 | 1516 | | |
1513 | 1517 | | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
1514 | 1531 | | |
1515 | 1532 | | |
1516 | 1533 | | |
| |||
1545 | 1562 | | |
1546 | 1563 | | |
1547 | 1564 | | |
1548 | | - | |
1549 | | - | |
1550 | | - | |
1551 | | - | |
1552 | | - | |
1553 | | - | |
1554 | | - | |
1555 | | - | |
1556 | 1565 | | |
1557 | 1566 | | |
1558 | 1567 | | |
1559 | | - | |
1560 | 1568 | | |
1561 | 1569 | | |
1562 | 1570 | | |
1563 | 1571 | | |
1564 | | - | |
1565 | | - | |
| 1572 | + | |
1566 | 1573 | | |
1567 | 1574 | | |
1568 | 1575 | | |
1569 | 1576 | | |
1570 | 1577 | | |
1571 | 1578 | | |
1572 | 1579 | | |
1573 | | - | |
1574 | | - | |
| 1580 | + | |
1575 | 1581 | | |
1576 | 1582 | | |
1577 | 1583 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | | - | |
61 | 59 | | |
62 | 60 | | |
63 | 61 | | |
| |||
77 | 75 | | |
78 | 76 | | |
79 | 77 | | |
80 | | - | |
| 78 | + | |
81 | 79 | | |
82 | 80 | | |
83 | 81 | | |
| |||
101 | 99 | | |
102 | 100 | | |
103 | 101 | | |
104 | | - | |
105 | | - | |
106 | 102 | | |
107 | 103 | | |
108 | 104 | | |
| |||
155 | 151 | | |
156 | 152 | | |
157 | 153 | | |
158 | | - | |
159 | | - | |
160 | 154 | | |
161 | 155 | | |
162 | 156 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
798 | 798 | | |
799 | 799 | | |
800 | 800 | | |
801 | | - | |
802 | | - | |
| 801 | + | |
803 | 802 | | |
804 | 803 | | |
805 | 804 | | |
| |||
1044 | 1043 | | |
1045 | 1044 | | |
1046 | 1045 | | |
1047 | | - | |
1048 | 1046 | | |
1049 | 1047 | | |
1050 | 1048 | | |
| |||
1152 | 1150 | | |
1153 | 1151 | | |
1154 | 1152 | | |
1155 | | - | |
1156 | 1153 | | |
1157 | | - | |
1158 | 1154 | | |
1159 | | - | |
1160 | 1155 | | |
1161 | 1156 | | |
1162 | 1157 | | |
| |||
1636 | 1631 | | |
1637 | 1632 | | |
1638 | 1633 | | |
1639 | | - | |
1640 | | - | |
| 1634 | + | |
1641 | 1635 | | |
1642 | 1636 | | |
1643 | 1637 | | |
| |||
1911 | 1905 | | |
1912 | 1906 | | |
1913 | 1907 | | |
1914 | | - | |
1915 | | - | |
1916 | | - | |
| 1908 | + | |
1917 | 1909 | | |
1918 | 1910 | | |
1919 | 1911 | | |
| |||
0 commit comments