Skip to content

Commit 9f0901e

Browse files
authored
Merge branch 'main' into pre-commit-ci-update-config
2 parents 39b3b2e + 9985036 commit 9f0901e

15 files changed

Lines changed: 93 additions & 34 deletions

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ select = [
152152
"RUF100", # see: https://docs.astral.sh/ruff/rules/unused-noqa/
153153
]
154154
ignore = [
155-
"E731", # Do not assign a lambda expression, use a def
156155
"E501", # todo: Line too long (235 > 120 characters)
157156
# TODO(crcrpar): Resolves the following ignores as these are added while enabling ruff check in pre-commit
158157
"F821", # https://docs.astral.sh/ruff/rules/undefined-name/

thunder/benchmarks/__init__.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,15 @@
4444
def list_benchmarks(use_classname: bool = True) -> None:
4545
print("Available benchmarks:")
4646

47-
name_fn = lambda x: x[0]
48-
if not use_classname:
49-
name_fn = lambda x: x[1].name
47+
if use_classname:
48+
49+
def name_fn(x):
50+
return x[0]
51+
52+
else:
53+
54+
def name_fn(x):
55+
return x[1].name
5056

5157
for x in sorted(benchmarks, key=name_fn):
5258
name = name_fn(x)
@@ -486,7 +492,10 @@ def _run_benchmark(
486492
# Determines the "wait for computation function," to be run after calls to make_batch() and the benchmark
487493
# function to ensure that computation has finished
488494
devices: list[str] = benchmark.devices
489-
wait_for_computation_fn = lambda: None
495+
496+
def wait_for_computation_fn():
497+
return None
498+
490499
for device in devices:
491500
device: thunder.core.devices.Device = thunder.core.devices.device_from_string(device)
492501
if device.devicetype is thunder.core.devices.DeviceType.CUDA:

thunder/benchmarks/benchmark_litgpt.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,9 @@ def setup_distributed(self, model):
621621
size_auto_wrap_policy = functools.partial(
622622
size_based_auto_wrap_policy, min_num_params=self.fsdp_bucket_params
623623
)
624-
zero_bucket_wrap_policy = lambda module, recurse, nonwrapped_numel: nonwrapped_numel >= 0
624+
625+
def zero_bucket_wrap_policy(module, recurse, nonwrapped_numel):
626+
return nonwrapped_numel >= 0
625627

626628
self.bucketing_mode = self.bucketing_mode or "block"
627629
custom_wrap_policy = {
@@ -657,7 +659,9 @@ def setup_activation_checkpointing(self):
657659
)
658660
return
659661

660-
check_fn = lambda submodule: isinstance(submodule, Block)
662+
def check_fn(submodule):
663+
return isinstance(submodule, Block)
664+
661665
apply_activation_checkpointing(self.model, checkpoint_wrapper_fn=checkpoint_wrapper, check_fn=check_fn)
662666

663667
# TODO(crcrpar): Think of apply `torch.compile` or `thunder.jit` per block/module
@@ -737,10 +741,13 @@ def calculate_model_flops(self):
737741
meta_model = self.init_model()
738742

739743
x = torch.randint(0, 1, (self.micro_batch_size, meta_model.config.block_size), device=meta)
740-
model_fwd = lambda: meta_model(x)
741-
model_loss = lambda y: torch.nn.functional.cross_entropy(
742-
y.reshape(-1, y.size(-1)), x.reshape(-1), ignore_index=-1
743-
)
744+
745+
def model_fwd():
746+
return meta_model(x)
747+
748+
def model_loss(y):
749+
return torch.nn.functional.cross_entropy(y.reshape(-1, y.size(-1)), x.reshape(-1), ignore_index=-1)
750+
744751
self.perf_metrics["model_flops"] = measure_flops(meta_model, model_fwd, model_loss)
745752
finally:
746753
self.device = device

thunder/benchmarks/targets.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,10 @@ def test_hf_transformers(
930930
fn = executor(b.fn())
931931

932932
if compute_type == ComputeType.TRAINING_BACKWARD:
933-
return_fn = lambda *args, **kwargs: fn(*args, **kwargs).loss
933+
934+
def return_fn(*args, **kwargs):
935+
return fn(*args, **kwargs).loss
936+
934937
else:
935938
kwargs["labels"] = None
936939
return_fn = fn

thunder/core/proxies.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,9 @@ def _infer_tensor_properties(
12751275
else:
12761276
# deferred computation of numel
12771277
# TODO: similar to how `shape` is handled, this should be CSE or lifted for efficiency
1278-
_numel = lambda *args: reduce(operator.mul, _shape, 1)
1278+
1279+
def _numel(*args):
1280+
return reduce(operator.mul, _shape, 1)
12791281

12801282
# TODO Alias rank to ndim?
12811283
_ndim = len(_shape)
@@ -2017,11 +2019,14 @@ def tensorproxy(t: torch.Tensor, /, *, name: None | str, history: None | tuple =
20172019
shape_pr = ProvenanceRecord(
20182020
PseudoInst.LOAD_ATTR, inputs=[copy.copy(history), wrap_const("shape").provenance]
20192021
)
2020-
dim_pr = lambda idx: ProvenanceRecord(
2021-
PseudoInst.BINARY_SUBSCR, inputs=[shape_pr, wrap_const(idx).provenance]
2022-
)
2022+
2023+
def dim_pr(idx):
2024+
return ProvenanceRecord(PseudoInst.BINARY_SUBSCR, inputs=[shape_pr, wrap_const(idx).provenance])
2025+
20232026
else:
2024-
dim_pr = lambda idx: None
2027+
2028+
def dim_pr(idx):
2029+
return None
20252030

20262031
shape = tuple(
20272032
IntegerProxy(

thunder/core/pytree.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,12 @@ def register_pytree_node_dataclass(cls):
103103
def unpack(cls) -> dict:
104104
return {field.name: getattr(cls, field.name) for field in dataclasses.fields(cls)}
105105

106-
_flatten = lambda obj: tree_flatten(unpack(obj), namespace=OPTREE_NAMESPACE)
107-
_unflatten = lambda spec, children: cls(**spec.unflatten(children))
106+
def _flatten(obj):
107+
return tree_flatten(unpack(obj), namespace=OPTREE_NAMESPACE)
108+
109+
def _unflatten(spec, children):
110+
return cls(**spec.unflatten(children))
111+
108112
optree.register_pytree_node(cls, _flatten, _unflatten, namespace=OPTREE_NAMESPACE)
109113
return cls
110114

thunder/core/transforms.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3110,7 +3110,10 @@ def _split_saved_for_backward_into_tensors_and_other(
31103110
Returns:
31113111
tuple[Sequence[Variable], Sequence[Variable]]: Tuple of tensors and other.
31123112
"""
3113-
is_tensor = lambda x: isinstance(x, TensorProxy)
3113+
3114+
def is_tensor(x):
3115+
return isinstance(x, TensorProxy)
3116+
31143117
other, tensors = utils.partition(is_tensor, saved_for_backward)
31153118
return tuple(tensors), tuple(other)
31163119

thunder/executors/fa3ex.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ def fa3_bwd_impl(
7676
dq, dk, dv = torch.empty_like(q), torch.empty_like(k), torch.empty_like(v)
7777

7878
# fa3 bwd requires last dim to be contiguous: https://github.com/Dao-AILab/flash-attention/issues/1109#issuecomment-2270043573
79-
maybe_contiguous = lambda x: x.contiguous() if x.stride(-1) != 1 else x
79+
80+
def maybe_contiguous(x):
81+
return x.contiguous() if x.stride(-1) != 1 else x
82+
8083
dq, dk, dv = (maybe_contiguous(a) for a in (q, k, v))
8184

8285
if softmax_scale is None:

thunder/executors/triton_crossentropy_impl.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,10 @@ def forward(
453453
# result = torch.empty_like(indices, dtype=dtype, device=device)
454454
neg_logprobs = torch.empty_like(logits, dtype=buffer_dtype, device=device)
455455
weights_buffer = torch.empty_like(result, dtype=buffer_dtype)
456-
grid = lambda opt: (logits.numel() // n_cols,)
456+
457+
def grid(opt):
458+
return (logits.numel() // n_cols,)
459+
457460
log_size_logits = int(math.log(math.prod(logits.shape) / n_cols))
458461
_forward[grid](
459462
logits,
@@ -512,10 +515,13 @@ def backward(ctx, dneg_logprobs):
512515
# run the kernel
513516
# neg_logprobs will be modified in place to become our gradient:
514517
n_cols = neg_logprobs.shape[-1]
515-
grid = lambda opt: (
516-
neg_logprobs.numel() // n_cols,
517-
triton.cdiv(n_cols, opt["BLOCK"]),
518-
)
518+
519+
def grid(opt):
520+
return (
521+
neg_logprobs.numel() // n_cols,
522+
triton.cdiv(n_cols, opt["BLOCK"]),
523+
)
524+
519525
log_size_logits = int(math.log(math.prod(neg_logprobs.shape) / n_cols))
520526
_backward[grid](
521527
neg_logprobs,

thunder/tests/distributed/test_tensor_parallel.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,10 @@ def forward(self, x):
190190
for p_name, p_ref in layer.named_parameters(recurse=False):
191191
param_fqn = f"{l_name}.{p_name}"
192192
ref_grad = p_ref.grad
193-
msg = lambda err_msg: f"[{prefix} {param_fqn}] {err_msg}"
193+
194+
def msg(err_msg):
195+
return f"[{prefix} {param_fqn}] {err_msg}"
196+
194197
if is_tensor_parallel and (ref_grad.ndim > 1 or dim == 0):
195198
ref_grad = ref_grad.chunk(self.world_size, dim)[self.rank]
196199
grad = tp_model.get_parameter(param_fqn).grad

0 commit comments

Comments
 (0)