returnn 1.20250603.232135__py3-none-any.whl → 1.20250618.161226__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of returnn might be problematic. Click here for more details.

returnn/PKG-INFO CHANGED
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: returnn
3
- Version: 1.20250603.232135
3
+ Version: 1.20250618.161226
4
4
  Summary: The RWTH extensible training framework for universal recurrent neural networks
5
5
  Home-page: https://github.com/rwth-i6/returnn/
6
6
  Author: Albert Zeyer
@@ -1,2 +1,2 @@
1
- version = '1.20250603.232135'
2
- long_version = '1.20250603.232135+git.5b262ae'
1
+ version = '1.20250618.161226'
2
+ long_version = '1.20250618.161226+git.a2170b5'
@@ -58,6 +58,7 @@ import threading
58
58
  import keyword
59
59
  import inspect
60
60
  import contextlib
61
+ import types
61
62
  from weakref import WeakKeyDictionary
62
63
 
63
64
  try:
@@ -96,6 +97,13 @@ except NameError: # Python3
96
97
  PY3 = sys.version_info[0] >= 3
97
98
 
98
99
 
100
+ cfg_print_builtins = False
101
+ cfg_print_not_found = False
102
+ cfg_print_bound_methods = False
103
+ cfg_print_modules = False
104
+ cfg_print_module_functions = False
105
+
106
+
99
107
  def parse_py_statement(line):
100
108
  """
101
109
  Parse Python statement into tokens.
@@ -111,6 +119,10 @@ def parse_py_statement(line):
111
119
  """
112
120
  state = 0
113
121
  cur_token = ""
122
+ str_prefix = None
123
+ str_is_f_string = False # whether we are in an f-string
124
+ str_quote = None
125
+ f_str_expr_opening_brackets = 0
114
126
  spaces = " \t\n"
115
127
  ops = ".,;:+-*/%&!=|(){}[]^<>"
116
128
  i = 0
@@ -133,29 +145,36 @@ def parse_py_statement(line):
133
145
  yield "op", c
134
146
  elif c == "#":
135
147
  state = 6
136
- elif c == '"':
148
+ elif c in "\"'":
137
149
  state = 1
138
- elif c == "'":
139
- state = 2
140
- else:
141
- cur_token = c
142
- state = 3
143
- elif state == 1: # string via "
144
- if c == "\\":
145
- state = 4
146
- elif c == '"':
147
- yield "str", cur_token
150
+ str_prefix = None
151
+ str_is_f_string = False
152
+ str_quote = c
148
153
  cur_token = ""
149
- state = 0
150
154
  else:
151
- cur_token += c
152
- elif state == 2: # string via '
155
+ cur_token = c
156
+ state = 3 # identifier
157
+ elif state == 1: # string
153
158
  if c == "\\":
154
- state = 5
155
- elif c == "'":
156
- yield "str", cur_token
159
+ cur_token += _escape_char(line[i : i + 1])
160
+ i += 1
161
+ elif c == str_quote:
162
+ yield "str" if not str_prefix else "%s-str" % str_prefix, cur_token
157
163
  cur_token = ""
158
164
  state = 0
165
+ elif str_is_f_string and c == "{": # f-string
166
+ if line[i - 1 : i + 1] == "{{":
167
+ cur_token += "{"
168
+ i += 1
169
+ else:
170
+ yield "str" if not str_prefix else "%s-str" % str_prefix, cur_token
171
+ yield "f-str-expr-open", "{"
172
+ cur_token = ""
173
+ f_str_expr_opening_brackets = 0
174
+ state = 4
175
+ elif str_is_f_string and c == "}" and line[i - 1 : i + 1] == "}}":
176
+ cur_token += "}"
177
+ i += 1
159
178
  else:
160
179
  cur_token += c
161
180
  elif state == 3: # identifier
@@ -164,20 +183,40 @@ def parse_py_statement(line):
164
183
  cur_token = ""
165
184
  state = 0
166
185
  i -= 1
167
- elif c == '"': # identifier is string prefix
168
- cur_token = ""
186
+ elif c in "\"'": # identifier is string prefix
169
187
  state = 1
170
- elif c == "'": # identifier is string prefix
188
+ str_prefix = cur_token
189
+ str_is_f_string = "f" in str_prefix or "F" in str_prefix
190
+ str_quote = c
171
191
  cur_token = ""
172
- state = 2
173
192
  else:
174
193
  cur_token += c
175
- elif state == 4: # escape in "
176
- cur_token += _escape_char(c)
177
- state = 1
178
- elif state == 5: # escape in '
179
- cur_token += _escape_char(c)
180
- state = 2
194
+ elif state == 4: # f-string expression (like state 0 but simplified)
195
+ if c in spaces:
196
+ pass
197
+ elif c in ops:
198
+ if f_str_expr_opening_brackets == 0 and c == "}":
199
+ yield "f-str-expr-close", "}"
200
+ state = 1 # back into the f-string
201
+ cur_token = ""
202
+ else:
203
+ yield "op", c
204
+ if c in "([{":
205
+ f_str_expr_opening_brackets += 1
206
+ elif c in ")]}":
207
+ if f_str_expr_opening_brackets > 0:
208
+ f_str_expr_opening_brackets -= 1
209
+ else:
210
+ cur_token = c
211
+ state = 5 # identifier in f-string expression
212
+ elif state == 5: # identifier in f-string expression (like state 3 but simplified)
213
+ if c in spaces + ops:
214
+ yield "id", cur_token
215
+ cur_token = ""
216
+ state = 4
217
+ i -= 1
218
+ else:
219
+ cur_token += c
181
220
  elif state == 6: # comment
182
221
  cur_token += c
183
222
  if state == 3:
@@ -234,6 +273,7 @@ def set_linecache(filename, source):
234
273
  """
235
274
  import linecache
236
275
 
276
+ # noinspection PyTypeChecker
237
277
  linecache.cache[filename] = None, None, [line + "\n" for line in source.splitlines()], filename
238
278
 
239
279
 
@@ -245,7 +285,7 @@ def simple_debug_shell(globals, locals):
245
285
  :return: nothing
246
286
  """
247
287
  try:
248
- import readline
288
+ import readline # noqa: F401
249
289
  except ImportError:
250
290
  pass # ignore
251
291
  compile_string_fn = "<simple_debug_shell input>"
@@ -253,7 +293,7 @@ def simple_debug_shell(globals, locals):
253
293
  try:
254
294
  s = raw_input("> ")
255
295
  except (KeyboardInterrupt, EOFError):
256
- print("breaked debug shell: " + sys.exc_info()[0].__name__)
296
+ print("broke debug shell: " + sys.exc_info()[0].__name__)
257
297
  break
258
298
  if s.strip() == "":
259
299
  continue
@@ -307,9 +347,6 @@ def debug_shell(user_ns, user_global_ns, traceback=None, execWrapper=None):
307
347
  if not ipshell and traceback and have_ipython:
308
348
  # noinspection PyBroadException
309
349
  try:
310
- # noinspection PyPackageRequirements,PyUnresolvedReferences
311
- from IPython.core.debugger import Pdb
312
-
313
350
  # noinspection PyPackageRequirements,PyUnresolvedReferences
314
351
  from IPython.terminal.debugger import TerminalPdb
315
352
 
@@ -1123,6 +1160,8 @@ def format_tb(
1123
1160
  output("(Exclude vars because we are on a GC stack.)")
1124
1161
  if with_vars is None:
1125
1162
  with_vars = True
1163
+ locals_start_str = color(" locals:", color.fg_colors[0])
1164
+
1126
1165
  # noinspection PyBroadException
1127
1166
  try:
1128
1167
  if limit is None:
@@ -1131,49 +1170,15 @@ def format_tb(
1131
1170
  n = 0
1132
1171
  _tb = tb
1133
1172
 
1134
- class NotFound(Exception):
1135
- """
1136
- Identifier not found.
1137
- """
1138
-
1139
- def _resolve_identifier(namespace, keys):
1140
- """
1141
- :param dict[str,typing.Any] namespace:
1142
- :param typing.Sequence[str] keys:
1143
- :return: namespace[name[0]][name[1]]...
1144
- """
1145
- if keys[0] not in namespace:
1146
- raise NotFound()
1147
- obj = namespace[keys[0]]
1148
- for part in keys[1:]:
1149
- obj = getattr(obj, part)
1150
- return obj
1151
-
1152
- # noinspection PyShadowingNames
1153
- def _try_set(old, prefix, func):
1154
- """
1155
- :param None|str old:
1156
- :param str prefix:
1157
- :param func:
1158
- :return: old
1159
- """
1160
- if old is not None:
1161
- return old
1162
- try:
1163
- return add_indent_lines(prefix, func())
1164
- except NotFound:
1165
- return old
1166
- except Exception as e:
1167
- return prefix + "!" + e.__class__.__name__ + ": " + str(e)
1168
-
1169
1173
  while _tb is not None and (limit is None or n < limit):
1170
1174
  if isframe(_tb):
1171
1175
  f = _tb
1172
1176
  elif is_stack_summary(_tb):
1173
- if isinstance(_tb[0], ExtendedFrameSummary):
1174
- f = _tb[0].tb_frame
1177
+ _tb0 = _tb[0]
1178
+ if isinstance(_tb0, ExtendedFrameSummary):
1179
+ f = _tb0.tb_frame
1175
1180
  else:
1176
- f = DummyFrame.from_frame_summary(_tb[0])
1181
+ f = DummyFrame.from_frame_summary(_tb0)
1177
1182
  else:
1178
1183
  f = _tb.tb_frame
1179
1184
  if allLocals is not None:
@@ -1216,38 +1221,82 @@ def format_tb(
1216
1221
  elif isinstance(f, DummyFrame) and not f.have_vars_available:
1217
1222
  pass
1218
1223
  else:
1219
- with output.fold_text_ctx(color(" locals:", color.fg_colors[0])):
1220
- already_printed_locals = set() # type: typing.Set[typing.Tuple[str,...]]
1224
+ with output.fold_text_ctx(locals_start_str):
1225
+ already_covered_locals = set() # type: typing.Set[typing.Tuple[str,...]]
1226
+ num_printed_locals = 0
1221
1227
  for token_str in grep_full_py_identifiers(parse_py_statement(source_code)):
1222
1228
  splitted_token = tuple(token_str.split("."))
1223
1229
  for token in [splitted_token[0:i] for i in range(1, len(splitted_token) + 1)]:
1224
- if token in already_printed_locals:
1230
+ if token in already_covered_locals:
1225
1231
  continue
1226
- token_value = None
1227
- token_value = _try_set(
1228
- token_value,
1229
- color("<local> ", color.fg_colors[0]),
1230
- lambda: format_py_obj(_resolve_identifier(f.f_locals, token)),
1231
- )
1232
- token_value = _try_set(
1233
- token_value,
1234
- color("<global> ", color.fg_colors[0]),
1235
- lambda: format_py_obj(_resolve_identifier(f.f_globals, token)),
1236
- )
1237
- token_value = _try_set(
1238
- token_value,
1239
- color("<builtin> ", color.fg_colors[0]),
1240
- lambda: format_py_obj(_resolve_identifier(f.f_builtins, token)),
1241
- )
1242
- token_value = token_value or color("<not found>", color.fg_colors[0])
1232
+ already_covered_locals.add(token)
1233
+ if token[0] in f.f_locals:
1234
+ token_base_dict = f.f_locals
1235
+ token_prefix_str = color("<local> ", color.fg_colors[0])
1236
+ elif token[0] in f.f_globals:
1237
+ token_base_dict = f.f_globals
1238
+ token_prefix_str = color("<global> ", color.fg_colors[0])
1239
+ if (
1240
+ not cfg_print_module_functions
1241
+ and len(token) == 1
1242
+ and _is_module_function(token_base_dict, token[0], obj_is_dict=True)
1243
+ ):
1244
+ continue
1245
+ elif token[0] in f.f_builtins:
1246
+ if not cfg_print_builtins:
1247
+ continue
1248
+ token_base_dict = f.f_builtins
1249
+ token_prefix_str = color("<builtin> ", color.fg_colors[0])
1250
+ else:
1251
+ if not cfg_print_not_found:
1252
+ continue
1253
+ token_base_dict = None
1254
+ token_prefix_str = None
1255
+
1243
1256
  prefix = " %s " % color(".", color.fg_colors[0], bold=True).join(
1244
1257
  token
1245
1258
  ) + color("= ", color.fg_colors[0], bold=True)
1246
- output(prefix, token_value)
1247
- already_printed_locals.add(token)
1248
- if len(already_printed_locals) == 0:
1249
- output(color(" no locals", color.fg_colors[0]))
1250
- else:
1259
+
1260
+ if token_prefix_str is None: # not found
1261
+ token_repr = color("<not found>", color.fg_colors[0])
1262
+ else:
1263
+ try:
1264
+ token_parent_obj = None
1265
+ token_obj = token_base_dict[token[0]]
1266
+ for attr in token[1:]:
1267
+ token_parent_obj = token_obj
1268
+ token_obj = getattr(token_obj, attr)
1269
+ except Exception as e:
1270
+ token_repr = token_prefix_str + "!" + e.__class__.__name__ + ": " + str(e)
1271
+ else: # found
1272
+ if (
1273
+ not cfg_print_bound_methods
1274
+ and token_parent_obj is not None
1275
+ and _is_bound_method(token_parent_obj, token[-1])
1276
+ ):
1277
+ continue
1278
+ if not cfg_print_modules and isinstance(token_obj, types.ModuleType):
1279
+ continue
1280
+ if (
1281
+ not cfg_print_module_functions
1282
+ and token_parent_obj is not None
1283
+ and _is_module_function(token_parent_obj, token[-1])
1284
+ ):
1285
+ continue
1286
+ token_repr = add_indent_lines(token_prefix_str, format_py_obj(token_obj))
1287
+
1288
+ output(prefix, token_repr)
1289
+ num_printed_locals += 1
1290
+
1291
+ if num_printed_locals == 0:
1292
+ if output.lines and output.lines[-1].endswith(locals_start_str + "\n"):
1293
+ output.lines[-1] = output.lines[-1][: -len(locals_start_str) - 1]
1294
+ elif output.lines and output.lines[-1].endswith("\n"):
1295
+ output.lines[-1] = output.lines[-1][:-1] + color(" none", color.fg_colors[0]) + "\n"
1296
+ else:
1297
+ output(color(" no locals", color.fg_colors[0]))
1298
+
1299
+ else: # no source code available
1251
1300
  output(color(" -- code not available --", color.fg_colors[0]))
1252
1301
 
1253
1302
  if clear_frames:
@@ -1685,10 +1734,11 @@ def iter_traceback(tb=None, enforce_most_recent_call_first=False):
1685
1734
  if is_frame(_tb):
1686
1735
  frame = _tb
1687
1736
  elif is_stack_summary(_tb):
1688
- if isinstance(_tb[0], ExtendedFrameSummary):
1689
- frame = _tb[0].tb_frame
1737
+ _tb0 = _tb[0]
1738
+ if isinstance(_tb0, ExtendedFrameSummary):
1739
+ frame = _tb0.tb_frame
1690
1740
  else:
1691
- frame = DummyFrame.from_frame_summary(_tb[0])
1741
+ frame = DummyFrame.from_frame_summary(_tb0)
1692
1742
  else:
1693
1743
  frame = _tb.tb_frame
1694
1744
  yield frame
@@ -1783,6 +1833,39 @@ def _StackSummary_extract(frame_gen, limit=None, lookup_lines=True, capture_loca
1783
1833
  return result
1784
1834
 
1785
1835
 
1836
+ def _is_bound_method(obj, attr_name):
1837
+ if not PY3:
1838
+ return False # not properly supported in Python 2
1839
+
1840
+ meth = getattr(obj, attr_name, None)
1841
+ meth = inspect.unwrap(meth)
1842
+
1843
+ if isinstance(meth, types.MethodType):
1844
+ if meth.__self__ is not obj:
1845
+ return False
1846
+ cls = type(obj)
1847
+ func = getattr(cls, attr_name, None)
1848
+ return meth.__func__ is func
1849
+
1850
+ elif isinstance(meth, (types.BuiltinMethodType, getattr(types, "MethodWrapperType", types.BuiltinMethodType))):
1851
+ if meth.__self__ is not obj:
1852
+ return False
1853
+ return meth.__name__ == attr_name
1854
+
1855
+ else:
1856
+ return False
1857
+
1858
+
1859
+ def _is_module_function(obj, attr_name, obj_is_dict=False):
1860
+ if obj_is_dict:
1861
+ func = obj.get(attr_name, None)
1862
+ else:
1863
+ if not isinstance(obj, types.ModuleType):
1864
+ return False
1865
+ func = getattr(obj, attr_name, None)
1866
+ return isinstance(func, types.FunctionType)
1867
+
1868
+
1786
1869
  def install():
1787
1870
  """
1788
1871
  Replaces sys.excepthook by our better_exchook.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: returnn
3
- Version: 1.20250603.232135
3
+ Version: 1.20250618.161226
4
4
  Summary: The RWTH extensible training framework for universal recurrent neural networks
5
5
  Home-page: https://github.com/rwth-i6/returnn/
6
6
  Author: Albert Zeyer
@@ -1,9 +1,9 @@
1
- returnn/PKG-INFO,sha256=Czm99-scfCrrKroopNZwjhabe7FeAhoGDQlNAwo5Nw0,5215
1
+ returnn/PKG-INFO,sha256=ek1l6FDeyEYBufWdoSAuEVH8uNi3V-WN7aUwbmNdKu8,5215
2
2
  returnn/__init__.py,sha256=biBtRsM0WZ406vShaeH-9WFoqJ8XwTbn6g0EeFJ7l8E,1012
3
3
  returnn/__main__.py,sha256=lHyZcu_0yc9f7Vf_Kfdy9PmeU0T76XVXnpalHi5WKro,31740
4
4
  returnn/__old_mod_loader__.py,sha256=nvsNY-xELdS_IPNkv66Q9Rmvg4dbGW0-EBRDcCmctos,7654
5
5
  returnn/__setup__.py,sha256=22kQn2fh11iPM0hLb2Fy5sLmoU1JGvmDxXRYuRgQkwU,4659
6
- returnn/_setup_info_generated.py,sha256=2gwgouUoAt0DDVP1iuzwI5kqXkN4kDxgXM5X8ZpjBPg,77
6
+ returnn/_setup_info_generated.py,sha256=XBGFZV-ZRw2F4mTMp3fI6LTpxLACFzTkIS0hMgWMgZc,77
7
7
  returnn/config.py,sha256=3tmKhB6FnQZaNdtcYsiB61JnEY--iZ2qmJ4yq0b6tE0,29140
8
8
  returnn/forward_iface.py,sha256=A_OJiaXsX4MlXQRzST86ylyxSUZbC402PQL1REcqHjM,911
9
9
  returnn/learning_rate_control.py,sha256=ZvWryAn_tv9DhV8sh1LV3eE34Yltl3On3mYZAG4hR9s,34684
@@ -234,7 +234,7 @@ returnn/torch/util/module.py,sha256=MXHIrF9Isu575DDJIa81212ULKwdqu1oOLxDVZecVSk,
234
234
  returnn/torch/util/scaled_gradient.py,sha256=C5e79mpqtxdtw08OTSy413TSBSlOertRisc-ioiFIaU,3191
235
235
  returnn/util/__init__.py,sha256=UIG1qw4idqhW71BV60ha7h9PktxvEVcBIu0lYRossK8,336
236
236
  returnn/util/basic.py,sha256=Ep67bFPbxiaMKgsjrUqF0seoswghAqLsUQYcpgQGeyE,142570
237
- returnn/util/better_exchook.py,sha256=98XnUZIWpYN7NfklSGt_5hYNplADVFQnh857esKxjdI,64475
237
+ returnn/util/better_exchook.py,sha256=7Xk232KYeG7EgtKTajHtB0rAiUrP18uSqr3AFhcQV9A,68993
238
238
  returnn/util/bpe.py,sha256=LWFhICZsEOnMwNws0lybPNzKRX6rSr8yKCvP65vjl9Y,19656
239
239
  returnn/util/debug.py,sha256=wuRzdg9zB84WWCGyTjmRR_zYypu8gXxlc0nZ6si9OC8,28224
240
240
  returnn/util/debug_helpers.py,sha256=0EINLK4uLtoSt5_kHs1M2NIFpMd0S7i4c4rx90U4fJk,2914
@@ -253,8 +253,8 @@ returnn/util/sig_proc.py,sha256=Tjz0VOAVyqu2qDCF5HZ1JjALjcFsHcNkcd96WgZeKfE,7265
253
253
  returnn/util/task_system.py,sha256=y4sMVXQ25Qd2z0rx03uOlXlkE-jbCYC1Sjfn-XlraVU,26003
254
254
  returnn/util/train_proc_manager.py,sha256=Pjht28k6uz6BNQ47uW6Gf880iyq5q4wx7P_K2tmoAM8,3266
255
255
  returnn/util/watch_memory.py,sha256=BR5P2kvBN6UI81cE0_1WAA6Hd1SByLbBaiDxvLhPOew,4213
256
- returnn-1.20250603.232135.dist-info/LICENSE,sha256=ywBD_U2aD4vpuoIgNAsjIGBYydl0tVKll3De0Z8s77c,11041
257
- returnn-1.20250603.232135.dist-info/METADATA,sha256=Czm99-scfCrrKroopNZwjhabe7FeAhoGDQlNAwo5Nw0,5215
258
- returnn-1.20250603.232135.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
259
- returnn-1.20250603.232135.dist-info/top_level.txt,sha256=Lsn4WZc5Pbfk0-xDQOgnFCxOoqxL4CyeM3N1TFbJncw,8
260
- returnn-1.20250603.232135.dist-info/RECORD,,
256
+ returnn-1.20250618.161226.dist-info/LICENSE,sha256=ywBD_U2aD4vpuoIgNAsjIGBYydl0tVKll3De0Z8s77c,11041
257
+ returnn-1.20250618.161226.dist-info/METADATA,sha256=ek1l6FDeyEYBufWdoSAuEVH8uNi3V-WN7aUwbmNdKu8,5215
258
+ returnn-1.20250618.161226.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
259
+ returnn-1.20250618.161226.dist-info/top_level.txt,sha256=Lsn4WZc5Pbfk0-xDQOgnFCxOoqxL4CyeM3N1TFbJncw,8
260
+ returnn-1.20250618.161226.dist-info/RECORD,,