第一关
(base) PS C:\Users\vc-vc> ssh -p 44978 root@ssh.intern-ai.org.cn -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
Warning: Permanently added '[ssh.intern-ai.org.cn]:44978' (ED25519) to the list of known hosts.
root@ssh.intern-ai.org.cn's password:
Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.10.134-13.al8.x86_64 x86_64)
Last login: Sat Aug 3 16:59:33 2024 from 127.0.0.1
---------------------------------- 欢迎使用 InternStudio 开发机 ------------------------------
+--------+------------+----------------------------------------------------------------------+
| 目录 | 名称 | 简介 |
+--------+------------+----------------------------------------------------------------------+
| / | 系统目录 | 每次停止开发机会将其恢复至系统(镜像)初始状态。不建议存储数据。 |
+--------+------------+----------------------------------------------------------------------+
| /root | 用户家目录 | 您的所有开发机共享此目录,不受开发机的启停影响。强烈建议将 conda |
| | | 环境、代码仓库等所有数据存储在此目录下。 |
| | | 【注意】该目录有存储限额,超过限额后新写入的数据会被静默删除! |
+--------+------------+----------------------------------------------------------------------+
| /share | 共享目录 | 常用微调数据集、模型仓库、教程、xtuner 配置文件都存放在此。 |
+--------+------------+----------------------------------------------------------------------+
Tips:
1. 快速从本地上传文件:
scp -o StrictHostKeyChecking=no -r -P {端口} {本地目录} root@ssh.intern-ai.org.cn:{开发机目录}
*注:在开发机 SSH 连接功能查看端口号
2. 避免因终端关闭或 SSH 连接断开导致任务终止, 强烈建议使用 tmux 将实验进程与终端窗口分离:
https://www.ruanyifeng.com/blog/2019/10/tmux.html
3. 查看 GPU 显存和算力使用率: studio-smi
4. 使用InternStudio开箱即用的conda环境:
studio-conda -h
5. 将conda环境一键添加到jupyterlab:
lab add {YOUR_CONDA_ENV_NAME}
----------------------------------------------------------------------------------------------
(base) root@intern-studio-50141768:~# cd test/
(base) root@intern-studio-50141768:~/test# ls
hello_world.py
(base) root@intern-studio-50141768:~/test# python hello_world.py
Running on local URL: http://127.0.0.1:7860
To create a public link, set `share=True` in `launch()`.
^CKeyboard interruption in main thread... closing server.
(base) root@intern-studio-50141768:~/test# exit
exit
root@intern-studio-50141768:~# exit
logout
Connection to ssh.intern-ai.org.cn closed.
(base) PS C:\Users\vc-vc> ssh -p 44978 root@ssh.intern-ai.org.cn -CNg -L 7860:127.0.0.1:7860 -o StrictHostKeyChecking=no
Warning: Permanently added '[ssh.intern-ai.org.cn]:44978' (ED25519) to the list of known hosts.
root@ssh.intern-ai.org.cn's password:
第二关
wordcount代码
import re
def wordcount(text):
# 去掉标点符号,只保留字母和空格
cleaned_text = re.sub(r'[^\w\s]', '', text)
# 将所有单词转换为小写
cleaned_text = cleaned_text.lower()
# 将字符串拆分为单词列表
words = cleaned_text.split()
# 统计每个单词出现的次数
word_count = {}
for word in words:
if word in word_count:
word_count[word] += 1
else:
word_count[word] = 1
return word_count
# 示例输入
text = """
Got this panda plush toy for my daughter's birthday,
who loves it and takes it everywhere. It's soft and
super cute, and its face has a friendly look. It's
a bit small for what I paid though. I think there
might be other options that are bigger for the
same price. It arrived a day earlier than expected,
so I got to play with it myself before I gave it
to her.
"""
# 调用函数并打印结果
print(wordcount(text))
Debug笔记
调试过程:
-
断点1:在
wordcount
函数的第一行-
观察变量
text
的值是否正确 -
继续执行
-
"\nGot this panda plush toy for my daughter's birthday,\nwho loves it and takes it everywhere. It's soft and\nsuper cute, and its face has a friendly look. It's\na bit small for what I paid though. I think there\nmight be other options that are bigger for the\nsame price. It arrived a day earlier than expected,\nso I got to play with it myself before I gave it\nto her.\n"
-
断点2:在
cleaned_text = re.sub(r'[^\w\s]', '', text)
之后-
检查
cleaned_text
是否去掉了标点符号 -
继续执行
-
'\nGot this panda plush toy for my daughters birthday\nwho loves it and takes it everywhere Its soft and\nsuper cute and its face has a friendly look Its\na bit small for what I paid though I think there\nmight be other options that are bigger for the\nsame price It arrived a day earlier than expected\nso I got to play with it myself before I gave it\nto her\n'
-
断点3:在
cleaned_text = cleaned_text.lower()
之后-
检查
cleaned_text
是否转换为小写 -
继续执行
-
'\ngot this panda plush toy for my daughters birthday\nwho loves it and takes it everywhere its soft and\nsuper cute and its face has a friendly look its\na bit small for what i paid though i think there\nmight be other options that are bigger for the\nsame price it arrived a day earlier than expected\nso i got to play with it myself before i gave it\nto her\n'
-
断点4:在
words = cleaned_text.split()
之后-
检查
words
列表是否正确拆分了单词 -
继续执行
-
['got', 'this', 'panda', 'plush', 'toy', 'for', 'my', 'daughters', 'birthday', 'who', 'loves', 'it', 'and', 'takes', 'it', 'everywhere', 'its', 'soft', 'and', 'super', 'cute', 'and', 'its', 'face', 'has', 'a', 'friendly', 'look', 'its', 'a', 'bit', 'small', 'for', 'what', 'i', 'paid', 'though', 'i', 'think', 'there', 'might', 'be', 'other', 'options', 'that', 'are', 'bigger', 'for', 'the', 'same', 'price', 'it', 'arrived', 'a', 'day', 'earlier', 'than', 'expected', 'so', ...]
-
断点5:在
word_count[word] += 1
或word_count[word] = 1
处。-
检查
word_count
字典是否正确统计了单词出现的次数。 -
继续执行直到程序结束。
-
{'got': 2, 'this': 1, 'panda': 1, 'plush': 1, 'toy': 1, 'for': 3, 'my': 1, 'daughters': 1, 'birthday': 1, 'who': 1, 'loves': 1, 'it': 5, 'and': 3, 'takes': 1, 'everywhere': 1, 'its': 3, 'soft': 1, 'super': 1, 'cute': 1, 'face': 1, 'has': 1, 'a': 3, 'friendly': 1, 'look': 1, 'bit': 1, 'small': 1, 'what': 1, 'i': 4, 'paid': 1, 'though': 1, 'think': 1, 'there': 1, 'might': 1, 'be': 1, 'other': 1, 'options': 1, 'that': 1, 'are': 1, 'bigger': 1, 'the': 1, 'same': 1, 'price': 1, 'arrived': 1, 'day': 1, 'earlier': 1, 'than': 1, 'expected': 1, 'so': 1, 'to': 2, 'play': 1, 'with': 1, 'myself': 1, 'before': 1, 'gave': 1, 'her': 1}
调试结果:
-
程序成功统计了字符串中每个单词出现的次数,并返回了正确的字典。
第三关
git_3869_introduction by AlexaOscar · Pull Request #1484 · InternLM/Tutorial · GitHub