You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importtorchimportloggingif__name__=="__main__":
fromtransformersimportAutoModelForCausalLM, AutoTokenizerfromtransformers_cfg.grammar_utilsimportIncrementalGrammarConstraintfromtransformers_cfg.generation.logits_processimportGrammarConstrainedLogitsProcessor# logging.basicConfig has already been called in the transformers_cfg library, so this will not work# the above function can only be called once in a python session# so we should NEVER call logging.basicConfig in a library! logging.basicConfig(level=logging.INFO)
logger=logging.getLogger(__name__)
# you will not see this message in the console because the logging level is set to WARNING inside the transformers_cfg librarylogger.info("Loading model and tokenizer")
Something which works is below:
importtorchimportloggingif__name__=="__main__":
logging.basicConfig(level=logging.INFO)
fromtransformersimportAutoModelForCausalLM, AutoTokenizer# the function call inside the transformers_cfg will not work because we have already called logging.basicConfig abovefromtransformers_cfg.grammar_utilsimportIncrementalGrammarConstraintfromtransformers_cfg.generation.logits_processimportGrammarConstrainedLogitsProcessorlogger=logging.getLogger(__name__)
# you will SEE this log message because the logging level is set to INFOlogger.info("Loading model and tokenizer")
Reason
importosimportloggingdefsetup_logging():
log_level_name=os.getenv(
"TCFG_LOG_LEVEL", "WARNING"
).upper() # Default to WARNING if not setlog_levels= {
"DEBUG": logging.DEBUG,
"INFO": logging.INFO,
"WARNING": logging.WARNING,
"ERROR": logging.ERROR,
"CRITICAL": logging.CRITICAL,
}
log_level=log_levels.get(log_level_name, logging.WARNING)
# this is BAD, this function configures the root logger of the entire program, so it will overwrite the user's logging level defined in their script when they import the librarylogging.basicConfig(level=log_level)
Solution
importlogging# Create a logger for the librarylogger=logging.getLogger('transformers_cfg')
# the level will propagate to loggers with submodule scopelogger.setLevel(logging.WARNING)
The text was updated successfully, but these errors were encountered:
The probelmatic line is here
transformers-CFG/transformers_cfg/logging_config.py
Line 18 in 651dca0
reproduce
Something which works is below:
Reason
Solution
The text was updated successfully, but these errors were encountered: