Skip to content

Conversation

@KareemMusleh
Copy link
Contributor

@KareemMusleh KareemMusleh commented Jan 8, 2025

I kept getting SyntaxWarnings when importing unsloth from the terminal.

flake8 | grep escape

@KareemMusleh KareemMusleh changed the title fixed most of syntax warnings fixed most syntax warnings Jan 8, 2025
@KareemMusleh KareemMusleh changed the title fixed most syntax warnings fixed syntax warnings Jan 9, 2025
@danielhanchen
Copy link
Contributor

Oh thanks for this - let me confirm all issues in a new runtime!

@steve2972
Copy link

I also keep getting SyntaxWarnings. Hope this PR fixes this!
Weird thing is, I only get these syntax warnings when using cold builds. Every subsequent run doesn't seem to have this problem.

Unsloth: Patching Xformers to fix some performance issues.
🦥 Unsloth: Will patch your computer to enable 2x faster free finetuning.
/home/user/.../.venv/lib/python3.12/site-packages/unsloth/models/llama.py:1599: SyntaxWarning: invalid escape sequence '\ '
  f"   \\\   /|    GPU: {gpu_stats.name}. Max memory: {max_memory} GB. Platform: {platform_system}.\n"\
/home/user/.../.venv/lib/python3.12/site-packages/unsloth/models/llama.py:1600: SyntaxWarning: invalid escape sequence '\_'
  f"O^O/ \_/ \\    Torch: {torch.__version__}. CUDA: {gpu_stats.major}.{gpu_stats.minor}. CUDA Toolkit: {torch.version.cuda}. Triton: {triton_version}\n"\
/home/user/.../.venv/lib/python3.12/site-packages/unsloth/models/llama.py:1601: SyntaxWarning: invalid escape sequence '\ '
  f"\        /    Bfloat16 = {str(SUPPORTS_BFLOAT16).upper()}. FA [Xformers = {xformers_version}. FA2 = {HAS_FLASH_ATTENTION}]\n"\
/home/user/.../.venv/lib/python3.12/site-packages/unsloth/models/llama.py:1752: SyntaxWarning: invalid escape sequence '\.'
  start = re.search('logger\.info\([\"\'].+?Running training', inner_training_loop).span(0)[0]
/home/user/.../.venv/lib/python3.12/site-packages/unsloth/models/llama.py:1755: SyntaxWarning: invalid escape sequence '\s'
  spaces = re.search('\n([\s\t]{1,})', original_debug).group(0)[1:]
/home/user/.../.venv/lib/python3.12/site-packages/unsloth/models/llama.py:1756: SyntaxWarning: invalid escape sequence '\s'
  front_spaces = re.match('([\s\t]{1,})', inner_training_loop).group(0)
/home/user/.../.venv/lib/python3.12/site-packages/unsloth/models/_utils.py:584: SyntaxWarning: invalid escape sequence '\.'
  source = re.sub("([^\.])nn\.", r"\1torch.nn.", source)
... {Multiple other SyntaxWarnings}
🦥 Unsloth Zoo will now patch everything to make training faster!
/home/user/.../.venv/lib/python3.12/site-packages/unsloth/save.py:481: SyntaxWarning: invalid escape sequence '\s'
  gb_found = re.match("([0-9]{1,})[\s]{0,}GB", max_shard_size, flags = re.IGNORECASE)
/home/user/.../.venv/lib/python3.12/site-packages/unsloth/save.py:482: SyntaxWarning: invalid escape sequence '\s'
  mb_found = re.match("([0-9]{1,})[\s]{0,}MB", max_shard_size, flags = re.IGNORECASE)
/home/user/.../.venv/lib/python3.12/site-packages/unsloth/save.py:1011: SyntaxWarning: invalid escape sequence '\ '
  f"   \\\   /|    [0] Installing llama.cpp might take 3 minutes.\n"\
/home/user/.../.venv/lib/python3.12/site-packages/unsloth/save.py:1012: SyntaxWarning: invalid escape sequence '\_'
  f"O^O/ \_/ \\    [1] Converting HF to GGUF 16bits might take 3 minutes.\n"\
/home/user/.../.venv/lib/python3.12/site-packages/unsloth/save.py:1013: SyntaxWarning: invalid escape sequence '\ '
  f"\        /    [2] Converting GGUF 16bits to {quantization_method} might take 10 minutes each.\n"\
/home/user/.../.venv/lib/python3.12/site-packages/unsloth/models/vision.py:101: SyntaxWarning: invalid escape sequence '\ '
  f"   \\\   /|    GPU: {gpu_stats.name}. Max memory: {max_memory} GB. Platform: {platform_system}.\n"\
/home/user/.../.venv/lib/python3.12/site-packages/unsloth/models/vision.py:102: SyntaxWarning: invalid escape sequence '\_'
  f"O^O/ \_/ \\    Torch: {torch.__version__}. CUDA: {gpu_stats.major}.{gpu_stats.minor}. CUDA Toolkit: {torch.version.cuda}. Triton: {triton_version}\n"\
/home/user/.../.venv/lib/python3.12/site-packages/unsloth/models/vision.py:103: SyntaxWarning: invalid escape sequence '\ '
  f"\        /    Bfloat16 = {str(SUPPORTS_BFLOAT16).upper()}. FA [Xformers = {xformers_version}. FA2 = {HAS_FLASH_ATTENTION}]\n"\
/home/user/.../.venv/lib/python3.12/site-packages/unsloth/chat_templates.py:1683: SyntaxWarning: invalid escape sequence '\{'
  try: found = next(re.finditer("(" + try_find + ").+?\{INPUT\}", chat_template, flags = re.DOTALL | re.MULTILINE))
/home/user/.../.venv/lib/python3.12/site-packages/unsloth/chat_templates.py:2124: SyntaxWarning: invalid escape sequence '\d'
  gguf_tokenized = re.findall("([\d]{1,}) \-\> \'([^\']{1,})\'", gguf_tokens, flags = re.MULTILINE)

Copy link

@InCogNiTo124 InCogNiTo124 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested it locally on Python 3.12

@danielhanchen
Copy link
Contributor

Apologies on the delay - it seems like dumbly I forgot to use r"..." for regex, and I also changed \\ to chr(92)

@danielhanchen
Copy link
Contributor

Thanks for the PR again!!

@danielhanchen danielhanchen merged commit 7feb2ff into unslothai:main Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants