diff --git a/src/accelerate/commands/config/cluster.py b/src/accelerate/commands/config/cluster.py
index a653b9d6a..a3dcd2dcb 100644
--- a/src/accelerate/commands/config/cluster.py
+++ b/src/accelerate/commands/config/cluster.py
@@ -63,21 +63,21 @@ def get_cluster_input():
     if distributed_type in [DistributedType.MULTI_GPU, DistributedType.MULTI_CPU]:
         num_machines = _ask_field(
             "How many different machines will you use (use more than 1 for multi-node training)? [1]: ",
-            lambda x: int(x),
+            int,
             default=1,
         )
         if num_machines > 1:
             machine_rank = _ask_options(
                 "What is the rank of this machine?",
                 list(range(num_machines)),
-                lambda x: int(x),
+                int,
             )
             main_process_ip = _ask_field(
                 "What is the IP address of the machine that will host the main process? ",
             )
             main_process_port = _ask_field(
                 "What is the port you will use to communicate with the main process? ",
-                lambda x: int(x),
+                int,
             )
             same_network = _ask_field(
                 "Are all the machines on the same local network? Answer `no` if nodes are on the cloud and/or on different network hosts [YES/no]: ",
@@ -153,14 +153,14 @@ def get_cluster_input():
             if use_deepspeed_config:
                 deepspeed_config["deepspeed_config_file"] = _ask_field(
                     "Please enter the path to the json DeepSpeed config file: ",
-                    lambda x: str(x),
+                    str,
                     default="none",
                 )
             else:
                 deepspeed_config["zero_stage"] = _ask_options(
                     "What should be your DeepSpeed's ZeRO optimization stage?",
                     [0, 1, 2, 3],
-                    lambda x: int(x),
+                    int,
                     default=2,
                 )
 
@@ -174,7 +174,7 @@ def get_cluster_input():
                     )
                 deepspeed_config["gradient_accumulation_steps"] = _ask_field(
                     "How many gradient accumulation steps you're passing in your script? [1]: ",
-                    lambda x: int(x),
+                    int,
                     default=1,
                 )
                 use_gradient_clipping = _ask_field(
@@ -186,7 +186,7 @@ def get_cluster_input():
                 if use_gradient_clipping:
                     deepspeed_config["gradient_clipping"] = _ask_field(
                         "What is the gradient clipping value? [1.0]: ",
-                        lambda x: float(x),
+                        float,
                         default=1.0,
                     )
                 if deepspeed_config["zero_stage"] == 3:
@@ -224,7 +224,7 @@ def get_cluster_input():
                         "for more information please refer official [documentation]"
                         "(https://www.deepspeed.ai/getting-started/#resource-configuration-multi-node). "
                         "Please specify the location of hostfile: ",
-                        lambda x: str(x),
+                        str,
                     )
 
                     is_exclusion_filter = _ask_field(
@@ -236,7 +236,7 @@ def get_cluster_input():
                     if is_exclusion_filter:
                         deepspeed_config["deepspeed_exclusion_filter"] = _ask_field(
                             "DeepSpeed exclusion filter string: ",
-                            lambda x: str(x),
+                            str,
                         )
 
                     is_inclusion_filter = _ask_field(
@@ -248,7 +248,7 @@ def get_cluster_input():
                     if is_inclusion_filter:
                         deepspeed_config["deepspeed_inclusion_filter"] = _ask_field(
                             "DeepSpeed inclusion filter string: ",
-                            lambda x: str(x),
+                            str,
                         )
 
     fsdp_config = {}
@@ -284,12 +284,12 @@ def get_cluster_input():
             if fsdp_config["fsdp_auto_wrap_policy"] == FSDP_AUTO_WRAP_POLICY[0]:
                 fsdp_config["fsdp_transformer_layer_cls_to_wrap"] = _ask_field(
                     "What is the transformer layer class name (case-sensitive) to wrap ,e.g, `BertLayer`, `GPTJBlock`, `T5Block` ...? : ",
-                    lambda x: str(x),
+                    str,
                 )
             elif fsdp_config["fsdp_auto_wrap_policy"] == FSDP_AUTO_WRAP_POLICY[1]:
                 fsdp_config["fsdp_min_num_params"] = _ask_field(
                     "What should be your FSDP's minimum number of parameters for Default Auto Wrapping Policy? [1e8]: ",
-                    lambda x: int(x),
+                    int,
                     default=1e8,
                 )
             fsdp_backward_prefetch_query = "What should be your FSDP's backward prefetch policy?"
@@ -319,7 +319,7 @@ def get_cluster_input():
             prefix = "megatron_lm_"
             megatron_lm_config[prefix + "tp_degree"] = _ask_field(
                 "What is the Tensor Parallelism degree/size? [1]:",
-                lambda x: int(x),
+                int,
                 default=1,
                 error_message="Please enter an integer.",
             )
@@ -333,14 +333,14 @@ def get_cluster_input():
 
             megatron_lm_config[prefix + "pp_degree"] = _ask_field(
                 "What is the Pipeline Parallelism degree/size? [1]:",
-                lambda x: int(x),
+                int,
                 default=1,
                 error_message="Please enter an integer.",
             )
             if megatron_lm_config[prefix + "pp_degree"] > 1:
                 megatron_lm_config[prefix + "num_micro_batches"] = _ask_field(
                     "What is the number of micro-batches? [1]:",
-                    lambda x: int(x),
+                    int,
                     default=1,
                     error_message="Please enter an integer.",
                 )
@@ -362,7 +362,7 @@ def get_cluster_input():
 
             megatron_lm_config[prefix + "gradient_clipping"] = _ask_field(
                 "What is the gradient clipping value based on global L2 Norm (0 to disable)? [1.0]: ",
-                lambda x: float(x),
+                float,
                 default=1.0,
             )
 
@@ -438,14 +438,14 @@ def get_cluster_input():
             machine_type += "(s)"
         num_processes = _ask_field(
             f"How many {machine_type} should be used for distributed training? [1]:",
-            lambda x: int(x),
+            int,
             default=1,
             error_message="Please enter an integer.",
         )
     elif distributed_type in [DistributedType.FSDP, DistributedType.DEEPSPEED, DistributedType.MEGATRON_LM]:
         num_processes = _ask_field(
             "How many GPU(s) should be used for distributed training? [1]:",
-            lambda x: int(x),
+            int,
             default=1,
             error_message="Please enter an integer.",
         )
diff --git a/src/accelerate/commands/config/sagemaker.py b/src/accelerate/commands/config/sagemaker.py
index 22264b41f..af4195f29 100644
--- a/src/accelerate/commands/config/sagemaker.py
+++ b/src/accelerate/commands/config/sagemaker.py
@@ -97,7 +97,7 @@ def get_sagemaker_input():
     credentials_configuration = _ask_options(
         "How do you want to authorize?",
         ["AWS Profile", "Credentials (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) "],
-        lambda x: int(x),
+        int,
     )
     aws_profile = None
     if credentials_configuration == 0:
@@ -120,7 +120,7 @@ def get_sagemaker_input():
     role_management = _ask_options(
         "Do you already have an IAM Role for executing Amazon SageMaker Training Jobs?",
         ["Provide IAM Role name", "Create new IAM role using credentials"],
-        lambda x: int(x),
+        int,
     )
     if role_management == 0:
         iam_role_name = _ask_field("Enter your IAM role name: ")
@@ -206,13 +206,10 @@ def get_sagemaker_input():
         ec2_instance_type = _ask_field(ec2_instance_query, lambda x: str(x).lower(), default="ml.p3.2xlarge")
 
     num_machines = 1
-    if (
-        distributed_type == SageMakerDistributedType.DATA_PARALLEL
-        or distributed_type == SageMakerDistributedType.MODEL_PARALLEL
-    ):
+    if distributed_type in (SageMakerDistributedType.DATA_PARALLEL, SageMakerDistributedType.MODEL_PARALLEL):
         num_machines = _ask_field(
             "How many machines do you want use? [1]: ",
-            lambda x: int(x),
+            int,
             default=1,
         )
 
diff --git a/src/accelerate/commands/launch.py b/src/accelerate/commands/launch.py
index 8eefb9d7f..b2d95bad8 100644
--- a/src/accelerate/commands/launch.py
+++ b/src/accelerate/commands/launch.py
@@ -863,7 +863,7 @@ def _infer_type(s):
                 parser.add_argument(argument, action=action)
 
     return {
-        key: (literal_eval(value) if value == "True" or value == "False" else value)
+        key: (literal_eval(value) if value in ("True", "False") else value)
         for key, value in parser.parse_args(nargs).__dict__.items()
     }
 
diff --git a/src/accelerate/data_loader.py b/src/accelerate/data_loader.py
index 4f3930e1c..8a45856cd 100644
--- a/src/accelerate/data_loader.py
+++ b/src/accelerate/data_loader.py
@@ -13,6 +13,7 @@
 # limitations under the License.
 
 import math
+from contextlib import suppress
 from typing import List, Optional, Union
 
 import torch
@@ -364,12 +365,10 @@ def __iter__(self):
         if self.rng_types is not None:
             synchronize_rng_states(self.rng_types, self.synchronized_generator)
         self.gradient_state._set_end_of_dataloader(False)
-        try:
+        # We can safely pass because the default is -1
+        with suppress(Exception):
             length = getattr(self.dataset, "total_dataset_length", len(self.dataset))
             self.gradient_state._set_remainder(length % self.total_batch_size)
-        except Exception:
-            # We can safely pass because the default is -1
-            pass
         dataloader_iter = super().__iter__()
         # We iterate one batch ahead to check when we are at the end
         try:
@@ -448,12 +447,10 @@ def __init__(self, dataset, split_batches: bool = False, _drop_last: bool = Fals
         self.gradient_state = GradientState()
         self.state = AcceleratorState()
         self._drop_last = _drop_last
-        try:
+        # We can safely pass because the default is -1
+        with suppress(Exception):
             length = getattr(self.dataset, "total_dataset_length", len(self.dataset))
             self.gradient_state._set_remainder(length % self.total_batch_size)
-        except Exception:
-            # We can safely pass because the default is -1
-            pass
 
     def _fetch_batches(self, iterator):
         batches, batch = None, None
diff --git a/src/accelerate/tracking.py b/src/accelerate/tracking.py
index 689ee5033..75694ba72 100644
--- a/src/accelerate/tracking.py
+++ b/src/accelerate/tracking.py
@@ -593,7 +593,7 @@ def filter_trackers(
                             if getattr(tracker_init, "requires_logging_directory"):
                                 if logging_dir is None:
                                     raise ValueError(
-                                        f"Logging with `{str(log_type)}` requires a `logging_dir` to be passed in."
+                                        f"Logging with `{log_type}` requires a `logging_dir` to be passed in."
                                     )
                             loggers.append(log_type)
                         else:
diff --git a/src/accelerate/utils/dataclasses.py b/src/accelerate/utils/dataclasses.py
index bb14078d4..50013c4d5 100644
--- a/src/accelerate/utils/dataclasses.py
+++ b/src/accelerate/utils/dataclasses.py
@@ -228,7 +228,7 @@ def __str__(self):
     @classmethod
     def list(cls):
         "Method to list all the possible items in `cls`"
-        return list(map(lambda item: str(item), cls))
+        return list(map(str, cls))
 
 
 class LoggerType(BaseEnum):
diff --git a/src/accelerate/utils/launch.py b/src/accelerate/utils/launch.py
index c65df08dc..1a4dcb4eb 100644
--- a/src/accelerate/utils/launch.py
+++ b/src/accelerate/utils/launch.py
@@ -88,7 +88,7 @@ def __call__(self, index, *args):
                 store=torch.distributed.FileStore(rdv_file, world_size),
                 world_size=world_size,
             )
-        elif self.distributed_type == DistributedType.MULTI_GPU or self.distributed_type == DistributedType.MULTI_CPU:
+        elif self.distributed_type in (DistributedType.MULTI_GPU, DistributedType.MULTI_CPU):
             # Prepare the environment for torch.distributed
             os.environ["LOCAL_RANK"] = str(index)
             os.environ["RANK"] = str(index)
diff --git a/src/accelerate/utils/megatron_lm.py b/src/accelerate/utils/megatron_lm.py
index afee2fcca..ab3bd8c37 100644
--- a/src/accelerate/utils/megatron_lm.py
+++ b/src/accelerate/utils/megatron_lm.py
@@ -132,7 +132,7 @@ def prepare_model(accelerator):
         custom_model_provider_func = accelerator.state.megatron_lm_plugin.custom_model_provider_function
         model = accelerator.state.megatron_lm_plugin.custom_prepare_model_function(custom_model_provider_func)
     else:
-        if args.model_type_name == "bert" or args.model_type_name == "gpt":
+        if args.model_type_name in ("bert", "gpt"):
             model_type = ModelType.encoder_or_decoder
         elif args.model_type_name == "t5":
             model_type = ModelType.encoder_and_decoder
@@ -566,7 +566,7 @@ def loss_func_finetune(labels, logits):
                 #  We are doing regression
                 loss_fct = MSELoss()
                 loss = loss_fct(logits.view(-1), labels.view(-1))
-            elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
+            elif self.num_labels > 1 and (labels.dtype in (torch.long, torch.int)):
                 loss_fct = CrossEntropyLoss()
                 loss = loss_fct(logits.view(-1, num_labels), labels.view(-1))
             else:


Review comments: body: Disagree with this change here. It's more readable to explicitly have the `.keys()`.
diff_hunk: @@ -98,7 +98,7 @@ def __call__(self, parser, namespace, values, option_string=None):
             "optional arguments",
         ]
         if len(args) > 1:
-            used_platforms = [arg for arg in args if arg in options_to_group.keys()]
+            used_platforms = [arg for arg in args if arg in options_to_group]
body: Not convinced this is more readable.
diff_hunk: @@ -245,7 +245,7 @@ def dispatch_model(
     check_device_map(model, device_map)
 
     if main_device is None:
-        if set(device_map.values()) == {"cpu"} or set(device_map.values()) == {"cpu", "disk"}:
+        if set(device_map.values()) in ({"cpu"}, {"cpu", "disk"}):
body: While this is technically equivalent, I prefer the explicit `else`.
diff_hunk: @@ -77,8 +77,7 @@ def handle_input(cls):
         if handler:
             cls.current_selection = char
             return handler(cls)
-        else:
-            return None
+        return None
body: I prefer the explicit `else`.
diff_hunk: @@ -164,9 +165,8 @@ def __len__(self):
         elif self.even_batches:
             # When we even batches we always get +1
             return length + 1
-        else:
-            # Otherwise it depends on the process index.
-            return length + 1 if self.process_index < len(self.batch_sampler) % self.num_processes else length
+        # Otherwise it depends on the process index.
+        return length + 1 if self.process_index < len(self.batch_sampler) % self.num_processes else length
body: Same here.
diff_hunk: @@ -402,8 +400,7 @@ def total_batch_size(self):
     def total_dataset_length(self):
         if hasattr("total_length", self.dataset):
             return self.dataset.total_length
-        else:
-            return len(self.dataset)
+        return len(self.dataset)
body: Same here.
diff_hunk: @@ -548,8 +543,7 @@ def __len__(self):
             return whole_length
         elif self._drop_last:
             return whole_length // self.state.num_processes
-        else:
-            return math.ceil(whole_length / self.state.num_processes)
+        return math.ceil(whole_length / self.state.num_processes)
body: While this is equivalent, `del values[names]` is explicit about what it's doing. `values.pop(name)` is not, so this should really be reverted.
diff_hunk: @@ -500,7 +500,7 @@ def store_init_configuration(self, values: dict):
                     f'Trainer is attempting to log a value of "{value}" for key "{name}" as a parameter. MLflow\'s'
                     f" log_param() only accepts values no longer than {mlflow.utils.validation.MAX_PARAM_VAL_LENGTH} characters so we dropped this attribute."
                 )
-                del values[name]
+                values.pop(name)
body: This is not equivalent, so this change should be reverted (f-strings use the repr, `str` does not).
diff_hunk: @@ -593,7 +593,7 @@ def filter_trackers(
                             if getattr(tracker_init, "requires_logging_directory"):
                                 if logging_dir is None:
                                     raise ValueError(
-                                        f"Logging with `{str(log_type)}` requires a `logging_dir` to be passed in."
+                                        f"Logging with `{log_type}` requires a `logging_dir` to be passed in."
body: Leaving the else and return is clearer.
diff_hunk: @@ -538,8 +538,7 @@ def get_batch_transformer(data_iterator):
 
         if megatron_dataset_flag:
             return get_batch_megatron
-        else:
-            return get_batch_transformer
+        return get_batch_transformer
body: Same here.
diff_hunk: @@ -577,8 +576,7 @@ def loss_func_finetune(labels, logits):
 
         if pretraining_flag:
             return loss_func_pretrain
-        else:
-            return loss_func_finetune
+        return loss_func_finetune
body: Same here.
diff_hunk: @@ -666,8 +664,7 @@ def get_batch_transformer(data_iterator):
 
         if megatron_dataset_flag:
             return get_batch_megatron
-        else:
-            return get_batch_transformer
+        return get_batch_transformer
body: Same here.
diff_hunk: @@ -803,8 +800,7 @@ def get_batch_transformer(data_iterator):
 
         if megatron_dataset_flag:
             return get_batch_megatron
-        else:
-            return get_batch_transformer
+        return get_batch_transformer
body: Same here.
diff_hunk: @@ -1118,8 +1114,7 @@ def eval_step(self, **batch_data):
                 else:
                     loss_reduced[key] = torch.concat(losses_reduced_for_key)
             return loss_reduced
-        else:
-            return {}
+        return {}
body: As above, this should be reverted.
diff_hunk: @@ -304,7 +304,7 @@ def clean_device_map(device_map: Dict[str, Union[int, str, torch.device]], modul
     values = [v for k, v in device_map.items() if k.startswith(prefix)]
     if len(set(values)) == 1 and len(values) > 1:
         for k in [k for k in device_map if k.startswith(prefix)]:
-            del device_map[k]
+            device_map.pop(k)
body: Let's leave the else return.
diff_hunk: @@ -225,8 +225,7 @@ def gather(tensor):
         return _gpu_gather(tensor)
     elif AcceleratorState().distributed_type == DistributedType.MULTI_CPU:
         return _cpu_gather(tensor)
-    else:
-        return tensor
+    return tensor
body: Same here.
diff_hunk: @@ -297,8 +296,7 @@ def broadcast(tensor, from_process: int = 0):
         return _gpu_broadcast(tensor, src=from_process)
     elif AcceleratorState().distributed_type == DistributedType.MULTI_CPU:
         return _gpu_broadcast(tensor, src=from_process)
-    else:
-        return tensor
+    return tensor
body: Same here.
diff_hunk: @@ -439,8 +437,7 @@ def _reduce_across_processes(tensor, reduction="mean"):
         else:
             if reduction == "sum":
                 return cloned_tensor.sum()
-            else:
-                return cloned_tensor.mean()
+            return cloned_tensor.mean()
body: I'd leave the `.keys()` as it's more readable this way.
diff_hunk: @@ -40,7 +40,7 @@ def compare_versions(library_or_version: Union[str, Version], operation: str, re
         requirement_version (`str`):
             The version to compare the library version against
     """
-    if operation not in STR_OPERATION_TO_FUNC.keys():
+    if operation not in STR_OPERATION_TO_FUNC:
body: For the record I quickly tested it and it seems that it actually uses `__str__`, not `__rep__`. 

```py
class A:
    def __str__(self):
        return "Use str"

    def __repr__(self):
        return "Use repr"

a = A()
print(a)
print("%s" % a)
print(f"{a}")
print(f"{str(a)}")
print("{}".format(a))
```

Output (both in python 3.7 and 3.10)
```
Use str
Use str
Use str
Use str
Use str
```
diff_hunk: @@ -593,7 +593,7 @@ def filter_trackers(
                             if getattr(tracker_init, "requires_logging_directory"):
                                 if logging_dir is None:
                                     raise ValueError(
-                                        f"Logging with `{str(log_type)}` requires a `logging_dir` to be passed in."
+                                        f"Logging with `{log_type}` requires a `logging_dir` to be passed in."
body: Oh! My bad then.
diff_hunk: @@ -593,7 +593,7 @@ def filter_trackers(
                             if getattr(tracker_init, "requires_logging_directory"):
                                 if logging_dir is None:
                                     raise ValueError(
-                                        f"Logging with `{str(log_type)}` requires a `logging_dir` to be passed in."
+                                        f"Logging with `{log_type}` requires a `logging_dir` to be passed in."
body: It is actually a TIL for me, didn't know what to expect :)
diff_hunk: @@ -593,7 +593,7 @@ def filter_trackers(
                             if getattr(tracker_init, "requires_logging_directory"):
                                 if logging_dir is None:
                                     raise ValueError(
-                                        f"Logging with `{str(log_type)}` requires a `logging_dir` to be passed in."
+                                        f"Logging with `{log_type}` requires a `logging_dir` to be passed in."

Discussion: body: _The documentation is not available anymore as the PR was closed or merged._