第三期闯关基础岛

1、 Linux 基础知识

任务描述完成所需时间
闯关任务完成SSH连接与端口映射并运行hello_world.py10min
可选任务 1将Linux基础命令在开发机上完成一遍10min
可选任务 2使用 VSCODE 远程连接开发机并创建一个conda环境10min
可选任务 3创建并运行test.sh文件10min

 1.1、SSH连接

 使用hostname查看开发机名称

使用uname -a查看开发机内核信息

使用lsb_release -a查看开发机版本信息

使用nvidia-smi查看GPU的信息

退出远程连接,输入两次exit就可以了

 1.2、配置SSH密钥进行SSH远程连接

ssh-keygen支持RSA和DSA两种认证密钥。

常用参数包括:

  • -t:指定密钥类型,如dsa、ecdsa、ed25519、rsa。
  • -b:指定密钥长度。
  • -C:添加注释。
  • -f:指定保存密钥的文件名。
  • -i:读取未加密的ssh-v2兼容的私钥/公钥文件
ssh-keygen -t rsa

1.3、 使用VScode进行SSH远程连接

1.4端口映射

一般我们在远程服务器上使用streamlit或者gradio,会在远程开启一个服务,例如在127.0.0.1:7860上,但这个端口是在远程的,我们本地是无法打开的,因此需要做一个转发,让本地通过ssh隧道访问到远程服务。

个人PC会远程连接到开发机唯一暴露在外的37367端口,(这个在SSH的时候提到过每个人的开发机暴露的端口都不一样),并设置隧道选项。暴露端口是作为中转站进行流量的转发。

  • C:启用压缩,减少传输数据量。
  • N:不执行远程命令,只建立隧道。
  • g:允许远程主机连接到本地转发的端口。

ssh -p 39917 root@ssh.intern-ai.org.cn -CNg -L 7860:127.0.0.1:7860 -o StrictHostKeyChecking=no

我们创建一个hello_world.py文件,在文件中填入以下内容:

import socket
import re
import gradio as gr
 
# 获取主机名
def get_hostname():
    hostname = socket.gethostname()
    match = re.search(r'-(\d+)$', hostname)
    name = match.group(1)
    
    return name
 
# 创建 Gradio 界面
with gr.Blocks(gr.themes.Soft()) as demo:
    html_code = f"""
            <p align="center">
            <a href="https://intern-ai.org.cn/home">
                <img src="https://intern-ai.org.cn/assets/headerLogo-4ea34f23.svg" alt="Logo" width="20%" style="border-radius: 5px;">
            </a>
            </p>
            <h1 style="text-align: center;">☁️ Welcome {get_hostname()} user, welcome to the ShuSheng LLM Practical Camp Course!</h1>
            <h2 style="text-align: center;">😀 Let’s go on a journey through ShuSheng Island together.</h2>
            <p align="center">
                <a href="https://github.com/InternLM/Tutorial/blob/camp3">
                    <img src="https://oss.lingkongstudy.com.cn/blog/202406301604074.jpg" alt="Logo" width="20%" style="border-radius: 5px;">
                </a>
            </p>

            """
    gr.Markdown(html_code)

demo.launch()

  2、Conda

conda --version来查看当前开发机中conda的版本信息

#设置清华镜像
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2

查看有哪些虚拟环境我们可以使用下面的命令:

conda env list
conda info -e
conda info --envs

如果想要退出虚拟环境的话可以使用:

conda activate
conda deactivate

这里直接安装miniconda,速度会快一些

curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh" bash Miniforge3-$(uname)-$(uname -m).sh

3、Python

务类型任务内容预计耗时
闯关任务Python实现wordcount15mins
闯关任务Vscode连接InternStudio debug笔记15mins

请实现一个wordcount函数,统计英文字符串中每个单词出现的次数。返回一个字典,key为单词,value为对应单词出现的次数。

Input:

"""Hello world!  
This is an example.  
Word count is fun.  
Is it fun to count words?  
Yes, it is fun!"""

Output:

{'hello': 1,'world!': 1,'this': 1,'is': 3,'an': 1,'example': 1,'word': 1, 
'count': 2,'fun': 1,'Is': 1,'it': 2,'to': 1,'words': 1,'Yes': 1,'fun': 1  }

import re
from collections import defaultdict

def wordcount(text):
    # 将输入字符串转换为小写
    text = text.lower()
    # 使用正则表达式分割单词
    words = re.findall(r'\b\w+\b', text)
    # 使用默认字典记录每个单词出现的次数
    word_count = defaultdict(int)
    for word in words:
        word_count[word] += 1
    return dict(word_count)

# 输入字符串
text = """Hello world!  
This is an example.  
Word count is fun.  
Is it fun to count words?  
Yes, it is fun!"""

# 调用wordcount函数
result = wordcount(text)

# 输出结果
print(result)

 4、Git

  • 任务1: 破冰活动:自我介绍
  • 任务2: 实践项目:构建个人项目

fork过来GitHub - InternLM/Tutorial: LLM Tutorial

​
git clone https://github.com/2001926342/Tutorial.git
cd Tutorial/
git branch -a
git checkout -b camp3 origin/camp3
​

 远程创建一个camp3:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

知源书院

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值