
import json
import os
from dataclasses import dataclass
from functools import partial
from typing import Callable

import flax.linen as nn
import jax
import jax.numpy as jnp
import joblib
import optax
import wandb
from flax import jax_utils, struct, traverse_util
from flax.serialization import from_bytes, to_bytes
from flax.training import train_state
from flax.training.common_utils import shard
from tqdm.auto import tqdm

from transformers import BigBirdConfig, FlaxBigBirdForQuestionAnswering
from transformers.models.big_bird.modeling_flax_big_bird import FlaxBigBirdForQuestionAnsweringModule




class 					_lowerCamelCase			(   _SCREAMING_SNAKE_CASE			):





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		 =	42
     SCREAMING_SNAKE_CASE_		 =	jnp.floataa
     SCREAMING_SNAKE_CASE_		 =	True






     def  __SCREAMING_SNAKE_CASE      (				self	)	-> Tuple:




           """simple docstring"""







           super().setup()
           UpperCamelCase__     : List[str]											=					nn.Dense(5    ,    dtype=self.dtype	)






     def __call__(				self    ,    *__SCREAMING_SNAKE_CASE    ,    **__SCREAMING_SNAKE_CASE	)	-> int:




           """simple docstring"""







           UpperCamelCase__     : List[str]											=					super().__call__(*__UpperCAmelCase    ,    **__UpperCAmelCase	)
           UpperCamelCase__     : List[str]											=					self.cls(outputs[2]	)
           return outputs[:2] + (cls_out,)




class 					_lowerCamelCase			(   _SCREAMING_SNAKE_CASE			):





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		 =	FlaxBigBirdForNaturalQuestionsModule


def 				SCREAMING_SNAKE_CASE_   (      UpperCamelCase__			,		UpperCamelCase__			,		UpperCamelCase__			,		UpperCamelCase__			,		UpperCamelCase__			,		UpperCamelCase__		):
      def cross_entropy(UpperCamelCase__			,		UpperCamelCase__			,		UpperCamelCase__=None		):
            UpperCamelCase__     : str											=					logits.shape[-1]
            UpperCamelCase__     : List[str]											=					(labels[..., None] == jnp.arange(lowerCamelCase_		)[None]).astype('''f4'''		)
            UpperCamelCase__     : Optional[int]											=					jax.nn.log_softmax(lowerCamelCase_			,		axis=-1		)
            UpperCamelCase__     : str											=					-jnp.sum(labels * logits			,		axis=-1		)
            if reduction is not None:
                  UpperCamelCase__     : int											=					reduction(lowerCamelCase_		)
            return loss

      UpperCamelCase__     : Dict											=					partial(lowerCamelCase_			,		reduction=jnp.mean		)
      UpperCamelCase__     : List[str]											=					cross_entropy(lowerCamelCase_			,		lowerCamelCase_		)
      UpperCamelCase__     : List[Any]											=					cross_entropy(lowerCamelCase_			,		lowerCamelCase_		)
      UpperCamelCase__     : Optional[Any]											=					cross_entropy(lowerCamelCase_			,		lowerCamelCase_		)
      return (start_loss + end_loss + pooled_loss) / 3




@dataclass
class 					_lowerCamelCase			:





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		 =	"google/bigbird-roberta-base"
     SCREAMING_SNAKE_CASE_		 =	3000
     SCREAMING_SNAKE_CASE_		 =	1_0500

     SCREAMING_SNAKE_CASE_		 =	128
     SCREAMING_SNAKE_CASE_		 =	3

     SCREAMING_SNAKE_CASE_		 =	1
     SCREAMING_SNAKE_CASE_		 =	5

     # tx_args
     SCREAMING_SNAKE_CASE_		 =	3e-5
     SCREAMING_SNAKE_CASE_		 =	0.0
     SCREAMING_SNAKE_CASE_		 =	2_0000
     SCREAMING_SNAKE_CASE_		 =	0.0095

     SCREAMING_SNAKE_CASE_		 =	"bigbird-roberta-natural-questions"
     SCREAMING_SNAKE_CASE_		 =	"training-expt"
     SCREAMING_SNAKE_CASE_		 =	"data/nq-training.jsonl"
     SCREAMING_SNAKE_CASE_		 =	"data/nq-validation.jsonl"






     def  __SCREAMING_SNAKE_CASE      (				self	)	-> Tuple:




           """simple docstring"""







           os.makedirs(self.base_dir    ,    exist_ok=__UpperCAmelCase	)
           UpperCamelCase__     : Dict											=					os.path.join(self.base_dir    ,    self.save_dir	)
           UpperCamelCase__     : Optional[Any]											=					self.batch_size_per_device * jax.device_count()




@dataclass
class 					_lowerCamelCase			:





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		 =	42
     SCREAMING_SNAKE_CASE_		 =	4096  # no dynamic padding on TPUs






     def __call__(				self    ,    __SCREAMING_SNAKE_CASE	)	-> int:




           """simple docstring"""







           UpperCamelCase__     : Union[str, Any]											=					self.collate_fn(__UpperCAmelCase	)
           UpperCamelCase__     : Any											=					jax.tree_util.tree_map(__UpperCAmelCase    ,    __UpperCAmelCase	)
           return batch






     def  __SCREAMING_SNAKE_CASE      (				self    ,    __SCREAMING_SNAKE_CASE	)	-> int:




           """simple docstring"""







           UpperCamelCase__     : Optional[Any]											=					self.fetch_inputs(features['''input_ids''']	)
           UpperCamelCase__     : Optional[int]											=					{
               '''input_ids''': jnp.array(__UpperCAmelCase    ,    dtype=jnp.intaa	),
               '''attention_mask''': jnp.array(__UpperCAmelCase    ,    dtype=jnp.intaa	),
               '''start_labels''': jnp.array(features['''start_token''']    ,    dtype=jnp.intaa	),
               '''end_labels''': jnp.array(features['''end_token''']    ,    dtype=jnp.intaa	),
               '''pooled_labels''': jnp.array(features['''category''']    ,    dtype=jnp.intaa	),
           }
           return batch






     def  __SCREAMING_SNAKE_CASE      (				self    ,    __SCREAMING_SNAKE_CASE	)	-> Optional[Any]:




           """simple docstring"""







           UpperCamelCase__     : Tuple											=					[self._fetch_inputs(__UpperCAmelCase	) for ids in input_ids]
           return zip(*__UpperCAmelCase	)






     def  __SCREAMING_SNAKE_CASE      (				self    ,    __SCREAMING_SNAKE_CASE	)	-> str:




           """simple docstring"""







           UpperCamelCase__     : Dict											=					[1 for _ in range(len(__UpperCAmelCase	)	)]
           while len(__UpperCAmelCase	) < self.max_length:
                 input_ids.append(self.pad_id	)
                 attention_mask.append(0	)
           return input_ids, attention_mask


def 				SCREAMING_SNAKE_CASE_   (      UpperCamelCase__			,		UpperCamelCase__			,		UpperCamelCase__=None		):
      if seed is not None:
            UpperCamelCase__     : Optional[Any]											=					dataset.shuffle(seed=lowerCamelCase_		)
      for i in range(len(lowerCamelCase_		) // batch_size		):
            UpperCamelCase__     : List[str]											=					dataset[i * batch_size : (i + 1) * batch_size]
            yield dict(lowerCamelCase_		)


@partial(jax.pmap			,		axis_name='''batch'''		)
def 				SCREAMING_SNAKE_CASE_   (      UpperCamelCase__			,		UpperCamelCase__			,		**UpperCamelCase__		):
      def loss_fn(UpperCamelCase__		):
            UpperCamelCase__     : Optional[int]											=					model_inputs.pop('''start_labels'''		)
            UpperCamelCase__     : List[str]											=					model_inputs.pop('''end_labels'''		)
            UpperCamelCase__     : Optional[Any]											=					model_inputs.pop('''pooled_labels'''		)

            UpperCamelCase__     : Optional[Any]											=					state.apply_fn(**lowerCamelCase_			,		params=lowerCamelCase_			,		dropout_rng=lowerCamelCase_			,		train=lowerCamelCase_		)
            UpperCamelCase__     : Any											=					outputs

            return state.loss_fn(
                lowerCamelCase_			,		lowerCamelCase_			,		lowerCamelCase_			,		lowerCamelCase_			,		lowerCamelCase_			,		lowerCamelCase_			,		)

      UpperCamelCase__     : Dict											=					jax.random.split(lowerCamelCase_		)
      UpperCamelCase__     : str											=					jax.value_and_grad(lowerCamelCase_		)
      UpperCamelCase__     : int											=					grad_fn(state.params		)
      UpperCamelCase__     : List[Any]											=					jax.lax.pmean({'''loss''': loss}			,		axis_name='''batch'''		)
      UpperCamelCase__     : Any											=					jax.lax.pmean(lowerCamelCase_			,		'''batch'''		)

      UpperCamelCase__     : int											=					state.apply_gradients(grads=lowerCamelCase_		)
      return state, metrics, new_drp_rng


@partial(jax.pmap			,		axis_name='''batch'''		)
def 				SCREAMING_SNAKE_CASE_   (      UpperCamelCase__			,		**UpperCamelCase__		):
      UpperCamelCase__     : Union[str, Any]											=					model_inputs.pop('''start_labels'''		)
      UpperCamelCase__     : Optional[Any]											=					model_inputs.pop('''end_labels'''		)
      UpperCamelCase__     : str											=					model_inputs.pop('''pooled_labels'''		)

      UpperCamelCase__     : Dict											=					state.apply_fn(**lowerCamelCase_			,		params=state.params			,		train=lowerCamelCase_		)
      UpperCamelCase__     : Optional[int]											=					outputs

      UpperCamelCase__     : Any											=					state.loss_fn(lowerCamelCase_			,		lowerCamelCase_			,		lowerCamelCase_			,		lowerCamelCase_			,		lowerCamelCase_			,		lowerCamelCase_		)
      UpperCamelCase__     : Optional[Any]											=					jax.lax.pmean({'''loss''': loss}			,		axis_name='''batch'''		)
      return metrics




class 					_lowerCamelCase			(   train_state.TrainState			):





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		 =	struct.field(pytree_node=_SCREAMING_SNAKE_CASE			)




@dataclass
class 					_lowerCamelCase			:





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		 =	42
     SCREAMING_SNAKE_CASE_		 =	42
     SCREAMING_SNAKE_CASE_		 =	42
     SCREAMING_SNAKE_CASE_		 =	42
     SCREAMING_SNAKE_CASE_		 =	42
     SCREAMING_SNAKE_CASE_		 =	42
     SCREAMING_SNAKE_CASE_		 =	None






     def  __SCREAMING_SNAKE_CASE      (				self    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE=None	)	-> List[str]:




           """simple docstring"""







           UpperCamelCase__     : Optional[Any]											=					model.params
           UpperCamelCase__     : Union[str, Any]											=					TrainState.create(
               apply_fn=model.__call__    ,    params=__UpperCAmelCase    ,    tx=__UpperCAmelCase    ,    loss_fn=__UpperCAmelCase    ,    )
           if ckpt_dir is not None:
                 UpperCamelCase__     : List[Any]											=					restore_checkpoint(__UpperCAmelCase    ,    __UpperCAmelCase	)
                 UpperCamelCase__     : List[str]											=					{
                     '''lr''': args.lr,
                     '''init_lr''': args.init_lr,
                     '''warmup_steps''': args.warmup_steps,
                     '''num_train_steps''': num_train_steps,
                     '''weight_decay''': args.weight_decay,
                 }
                 UpperCamelCase__     : str											=					build_tx(**__UpperCAmelCase	)
                 UpperCamelCase__     : List[str]											=					train_state.TrainState(
                     step=__UpperCAmelCase    ,    apply_fn=model.__call__    ,    params=__UpperCAmelCase    ,    tx=__UpperCAmelCase    ,    opt_state=__UpperCAmelCase    ,    )
                 UpperCamelCase__     : Optional[int]											=					args
                 UpperCamelCase__     : Tuple											=					data_collator
                 UpperCamelCase__     : Any											=					lr
                 UpperCamelCase__     : Dict											=					params
           UpperCamelCase__     : Optional[int]											=					jax_utils.replicate(__UpperCAmelCase	)
           return state






     def  __SCREAMING_SNAKE_CASE      (				self    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE	)	-> Dict:




           """simple docstring"""







           UpperCamelCase__     : List[Any]											=					self.args
           UpperCamelCase__     : Tuple											=					len(__UpperCAmelCase	) // args.batch_size

           UpperCamelCase__     : Any											=					jax.random.PRNGKey(0	)
           UpperCamelCase__     : int											=					jax.random.split(__UpperCAmelCase    ,    jax.device_count()	)
           for epoch in range(args.max_epochs	):
                 UpperCamelCase__     : Tuple											=					jnp.array(0    ,    dtype=jnp.floataa	)
                 UpperCamelCase__     : int											=					get_batched_dataset(__UpperCAmelCase    ,    args.batch_size    ,    seed=__UpperCAmelCase	)
                 UpperCamelCase__     : Tuple											=					0
                 for batch in tqdm(__UpperCAmelCase    ,    total=__UpperCAmelCase    ,    desc=F'''Running EPOCH-{epoch}'''	):
                       UpperCamelCase__     : Any											=					self.data_collator(__UpperCAmelCase	)
                       UpperCamelCase__     : Optional[Any]											=					self.train_step_fn(__UpperCAmelCase    ,    __UpperCAmelCase    ,    **__UpperCAmelCase	)
                       running_loss += jax_utils.unreplicate(metrics['''loss''']	)
                       i += 1
                       if i % args.logging_steps == 0:
                             UpperCamelCase__     : Tuple											=					jax_utils.unreplicate(state.step	)
                             UpperCamelCase__     : List[Any]											=					running_loss.item() / i
                             UpperCamelCase__     : Optional[int]											=					self.scheduler_fn(state_step - 1	)

                             UpperCamelCase__     : str											=					self.evaluate(__UpperCAmelCase    ,    __UpperCAmelCase	)
                             UpperCamelCase__     : List[str]											=					{
                                 '''step''': state_step.item(),
                                 '''eval_loss''': eval_loss.item(),
                                 '''tr_loss''': tr_loss,
                                 '''lr''': lr.item(),
                             }
                             tqdm.write(str(__UpperCAmelCase	)	)
                             self.logger.log(__UpperCAmelCase    ,    commit=__UpperCAmelCase	)

                       if i % args.save_steps == 0:
                             self.save_checkpoint(args.save_dir + F'''-e{epoch}-s{i}'''    ,    state=__UpperCAmelCase	)






     def  __SCREAMING_SNAKE_CASE      (				self    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE	)	-> List[Any]:




           """simple docstring"""







           UpperCamelCase__     : List[str]											=					get_batched_dataset(__UpperCAmelCase    ,    self.args.batch_size	)
           UpperCamelCase__     : int											=					len(__UpperCAmelCase	) // self.args.batch_size
           UpperCamelCase__     : Optional[int]											=					jnp.array(0    ,    dtype=jnp.floataa	)
           UpperCamelCase__     : Optional[int]											=					0
           for batch in tqdm(__UpperCAmelCase    ,    total=__UpperCAmelCase    ,    desc='''Evaluating ... '''	):
                 UpperCamelCase__     : List[str]											=					self.data_collator(__UpperCAmelCase	)
                 UpperCamelCase__     : List[str]											=					self.val_step_fn(__UpperCAmelCase    ,    **__UpperCAmelCase	)
                 running_loss += jax_utils.unreplicate(metrics['''loss''']	)
                 i += 1
           return running_loss / i






     def  __SCREAMING_SNAKE_CASE      (				self    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE	)	-> Any:




           """simple docstring"""







           UpperCamelCase__     : Optional[int]											=					jax_utils.unreplicate(__UpperCAmelCase	)
           print(F'''SAVING CHECKPOINT IN {save_dir}'''    ,    end=''' ... '''	)
           self.model_save_fn(__UpperCAmelCase    ,    params=state.params	)
           with open(os.path.join(__UpperCAmelCase    ,    '''opt_state.msgpack'''	)    ,    '''wb'''	) as f:
                 f.write(to_bytes(state.opt_state	)	)
           joblib.dump(self.args    ,    os.path.join(__UpperCAmelCase    ,    '''args.joblib'''	)	)
           joblib.dump(self.data_collator    ,    os.path.join(__UpperCAmelCase    ,    '''data_collator.joblib'''	)	)
           with open(os.path.join(__UpperCAmelCase    ,    '''training_state.json'''	)    ,    '''w'''	) as f:
                 json.dump({'''step''': state.step.item()}    ,    __UpperCAmelCase	)
           print('''DONE'''	)


def 				SCREAMING_SNAKE_CASE_   (      UpperCamelCase__			,		UpperCamelCase__		):
      print(f'''RESTORING CHECKPOINT FROM {save_dir}'''			,		end=''' ... '''		)
      with open(os.path.join(lowerCamelCase_			,		'''flax_model.msgpack'''		)			,		'''rb'''		) as f:
            UpperCamelCase__     : List[str]											=					from_bytes(state.params			,		f.read()		)

      with open(os.path.join(lowerCamelCase_			,		'''opt_state.msgpack'''		)			,		'''rb'''		) as f:
            UpperCamelCase__     : Optional[int]											=					from_bytes(state.opt_state			,		f.read()		)

      UpperCamelCase__     : Dict											=					joblib.load(os.path.join(lowerCamelCase_			,		'''args.joblib'''		)		)
      UpperCamelCase__     : str											=					joblib.load(os.path.join(lowerCamelCase_			,		'''data_collator.joblib'''		)		)

      with open(os.path.join(lowerCamelCase_			,		'''training_state.json'''		)			,		'''r'''		) as f:
            UpperCamelCase__     : Dict											=					json.load(lowerCamelCase_		)
      UpperCamelCase__     : List[Any]											=					training_state['''step''']

      print('''DONE'''		)
      return params, opt_state, step, args, data_collator


def 				SCREAMING_SNAKE_CASE_   (      UpperCamelCase__			,		UpperCamelCase__			,		UpperCamelCase__			,		UpperCamelCase__		):
      UpperCamelCase__     : List[str]											=					num_train_steps - warmup_steps
      UpperCamelCase__     : List[Any]											=					optax.linear_schedule(init_value=lowerCamelCase_			,		end_value=lowerCamelCase_			,		transition_steps=lowerCamelCase_		)
      UpperCamelCase__     : Optional[Any]											=					optax.linear_schedule(init_value=lowerCamelCase_			,		end_value=1e-7			,		transition_steps=lowerCamelCase_		)
      UpperCamelCase__     : Union[str, Any]											=					optax.join_schedules(schedules=[warmup_fn, decay_fn]			,		boundaries=[warmup_steps]		)
      return lr


def 				SCREAMING_SNAKE_CASE_   (      UpperCamelCase__			,		UpperCamelCase__			,		UpperCamelCase__			,		UpperCamelCase__			,		UpperCamelCase__		):
      def weight_decay_mask(UpperCamelCase__		):
            UpperCamelCase__     : int											=					traverse_util.flatten_dict(lowerCamelCase_		)
            UpperCamelCase__     : List[Any]											=					{k: (v[-1] != '''bias''' and v[-2:] != ('''LayerNorm''', '''scale''')) for k, v in params.items()}
            return traverse_util.unflatten_dict(lowerCamelCase_		)

      UpperCamelCase__     : str											=					scheduler_fn(lowerCamelCase_			,		lowerCamelCase_			,		lowerCamelCase_			,		lowerCamelCase_		)

      UpperCamelCase__     : str											=					optax.adamw(learning_rate=lowerCamelCase_			,		weight_decay=lowerCamelCase_			,		mask=lowerCamelCase_		)
      return tx, lr





import os
import unittest

from huggingface_hub.utils import are_progress_bars_disabled

import transformers.models.bart.tokenization_bart
from transformers import logging
from transformers.testing_utils import CaptureLogger, mockenv, mockenv_context
from transformers.utils.logging import disable_progress_bar, enable_progress_bar







class 					__lowercase  (						unittest.TestCase				):





							"""simple docstring"""

							def       snake_case			(					self						)		->       Union[str, Any]:
														A      :					Dict      		=					logging.get_logger()

														# the current default level is logging.WARNING
														A      :					List[Any]      		=					logging.get_verbosity()

														logging.set_verbosity_error()
														self.assertEqual(logger.getEffectiveLevel()    ,						logging.get_verbosity()						)

														logging.set_verbosity_warning()
														self.assertEqual(logger.getEffectiveLevel()    ,						logging.get_verbosity()						)

														logging.set_verbosity_info()
														self.assertEqual(logger.getEffectiveLevel()    ,						logging.get_verbosity()						)

														logging.set_verbosity_debug()
														self.assertEqual(logger.getEffectiveLevel()    ,						logging.get_verbosity()						)

														# restore to the original level
														logging.set_verbosity(__UpperCAmelCase						)




							def       snake_case			(					self						)		->       str:
														A      :					Any      		=					logging.get_verbosity()

														A      :					Optional[Any]      		=					logging.get_logger('''transformers.models.bart.tokenization_bart'''						)
														A      :					Tuple      		=					'''Testing 1, 2, 3'''

														# should be able to log warnings (if default settings weren't overridden by `pytest --log-level-all`)
														if level_origin <= logging.WARNING:
																					with CaptureLogger(__UpperCAmelCase						) as cl:
																												logger.warning(__UpperCAmelCase						)
																					self.assertEqual(cl.out    ,						msg + '''\n'''						)

														# this is setting the level for all of `transformers.*` loggers
														logging.set_verbosity_error()

														# should not be able to log warnings
														with CaptureLogger(__UpperCAmelCase						) as cl:
																					logger.warning(__UpperCAmelCase						)
														self.assertEqual(cl.out    ,						''''''						)

														# should be able to log warnings again
														logging.set_verbosity_warning()
														with CaptureLogger(__UpperCAmelCase						) as cl:
																					logger.warning(__UpperCAmelCase						)
														self.assertEqual(cl.out    ,						msg + '''\n'''						)

														# restore to the original level
														logging.set_verbosity(__UpperCAmelCase						)




							@mockenv(TRANSFORMERS_VERBOSITY='''error'''						)
							def       snake_case			(					self						)		->       Optional[int]:
														# reset for the env var to take effect, next time some logger call is made
														transformers.utils.logging._reset_library_root_logger()
														# this action activates the env var
														A      :					int      		=					logging.get_logger('''transformers.models.bart.tokenization_bart'''						)

														A      :					Any      		=					os.getenv('''TRANSFORMERS_VERBOSITY'''    ,						__UpperCAmelCase						)
														A      :					List[str]      		=					logging.log_levels[env_level_str]

														A      :					Optional[int]      		=					logging.get_verbosity()
														self.assertEqual(
														    __UpperCAmelCase    ,						__UpperCAmelCase    ,						f'TRANSFORMERS_VERBOSITY={env_level_str}/{env_level}, but internal verbosity is {current_level}'    ,						)

														# restore to the original level
														A      :					str      		=					''''''
														transformers.utils.logging._reset_library_root_logger()




							@mockenv(TRANSFORMERS_VERBOSITY='''super-error'''						)
							def       snake_case			(					self						)		->       Optional[int]:
														# reset for the env var to take effect, next time some logger call is made
														transformers.utils.logging._reset_library_root_logger()
														A      :					str      		=					logging.logging.getLogger()
														with CaptureLogger(__UpperCAmelCase						) as cl:
																					# this action activates the env var
																					logging.get_logger('''transformers.models.bart.tokenization_bart'''						)
														self.assertIn('''Unknown option TRANSFORMERS_VERBOSITY=super-error'''    ,						cl.out						)

														# no need to restore as nothing was changed






							def       snake_case			(					self						)		->       Optional[int]:
														# testing `logger.warning_advice()`
														transformers.utils.logging._reset_library_root_logger()

														A      :					Union[str, Any]      		=					logging.get_logger('''transformers.models.bart.tokenization_bart'''						)
														A      :					Optional[int]      		=					'''Testing 1, 2, 3'''

														with mockenv_context(TRANSFORMERS_NO_ADVISORY_WARNINGS='''1'''						):
																					# nothing should be logged as env var disables this method
																					with CaptureLogger(__UpperCAmelCase						) as cl:
																												logger.warning_advice(__UpperCAmelCase						)
																					self.assertEqual(cl.out    ,						''''''						)

														with mockenv_context(TRANSFORMERS_NO_ADVISORY_WARNINGS=''''''						):
																					# should log normally as TRANSFORMERS_NO_ADVISORY_WARNINGS is unset
																					with CaptureLogger(__UpperCAmelCase						) as cl:
																												logger.warning_advice(__UpperCAmelCase						)
																					self.assertEqual(cl.out    ,						msg + '''\n'''						)






def        snake_case__		(    ):
							disable_progress_bar()
							assert are_progress_bars_disabled()

							enable_progress_bar()
							assert not are_progress_bars_disabled()






