Skip to content

Commit

Permalink
Docs: add S2311 (#70)
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Qian <[email protected]>
  • Loading branch information
bekcpear authored Jan 3, 2024
1 parent 9d9ea07 commit 997f5cd
Show file tree
Hide file tree
Showing 5 changed files with 244 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Docs/S2311/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM milkvtech/milkv-duo:latest

RUN echo "Asia/Shanghai" >/etc/timezone

RUN apt update && \
apt upgrade -y && \
apt install -y \
tmux \
zsh \
zsh-autosuggestions \
zsh-syntax-highlighting \
locales && \
apt clean all && \
apt autoremove && \
locale-gen en_US.UTF-8

ENV TERM=xterm-256color
ENV LANG=en_US.UTF-8

RUN mkdir -p /home/worker
COPY dot-zshrc /root/.zshrc

WORKDIR /home/worker
CMD ["/bin/zsh", "-l"]
53 changes: 53 additions & 0 deletions Docs/S2311/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# S2311: Baby LLaMA 2 on Duo 速度优化(儿童讲故事场景)

## 赛题演示文档

[S2311.PDF](./S2311.PDF)

## 赛题演示回放地址

TBA

## 赛题演示中一些材料

- scp2duo 函数
```bash
scp2duo() {
local DUO_IP="${DUO_IP:-192.168.88.104}"
local D NEXT_IS_D=0
local -a S
for arg {
case $arg in
-d)
NEXT_IS_D=1
;;
*)
if [[ $NEXT_IS_D == 1 ]]; then
D="$arg"
NEXT_IS_D=0
else
S+=("$arg")
fi
;;
esac
}
: ${D:="~/"}
set -- scp -O "${S[@]}" root@${DUO_IP}:"$D"
echo ">>>" "$@" >&2
"$@"
}
```
- resizefs.sh 脚本:[resizefs.sh](./resizefs.sh)
> 视频演示中遇到的
> ```
> open: No such file or directory while opening /dev/sdd2
> ```
> 这个问题,怀疑是在 fdisk 操作完成之后,在短暂的时间内实际没有同步到磁盘导致的。
> 目前在原有脚本的基础上,增加了其间的 sync 操作,来尽量避免这个问题。
- milkvtech/milkv-duo 基础上新增的 Docker Image
- [Dockerfile](./Dockerfile)
- [.zshrc](./dot-zshrc)
## 回放视频最后为何把 Stories15M.bin 文件删除的原因
运行操作时,使用了 `run` 函数而非 `./run` 二进制,这个函数是我环境下的用来快速编译 c/cpp 并运行的函数,导致出现此次失误。
Binary file added Docs/S2311/S2311.PDF
Binary file not shown.
48 changes: 48 additions & 0 deletions Docs/S2311/dot-zshrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
setopt extended_history
HISTFILE=/home/worker/.zsh_history
HISTSIZE=1000000
SAVEHIST=100000
bindkey -v
KEYTIMEOUT=1
zstyle ':completion:*' completer _complete _ignored _approximate
zstyle ':completion:*' expand prefix
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*:descriptions' format '%U%d%b%u'
zstyle ':completion:*:warnings' format '%BSorry, no matches for: %d%b'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' ignore-parents parent pwd
zstyle ':completion:*' insert-unambiguous true
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-prompt '%SAt %p: Hit TAB for more, or the character to insert%s'
zstyle ':completion:*' list-suffixes true
zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]}'
zstyle ':completion:*' max-errors 0 not-numeric
zstyle ':completion:*' original true
zstyle ':completion:*' preserve-prefix '//[^/]##/'
zstyle ':completion:*' squeeze-slashes true
zstyle :compinstall filename '~/.zshrc'
autoload -Uz compinit promptinit vcs_info
compinit
promptinit
bindkey '^R' history-incremental-search-backward
setopt autocd
setopt extendedglob
source /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh
source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
precmd() {
local _last_ret=$?
local _color=209
if [[ ${_last_ret} != 0 ]]; then
case ${_last_ret} in
130)
_last_ret='^C'
_color=212
;;
*)
;;
esac
printf '\x1b[48;5;%dm[DOCKER] ⤒%s \x1b[0m\n' ${_color} ${_last_ret}
fi
}
PROMPT='%B[docker:milkv-duo-self] %~ %#%b '
alias ls="ls -p --color=auto"
119 changes: 119 additions & 0 deletions Docs/S2311/resizefs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/bin/bash
#

SECTORSIZE=512 # bytes
DISK=$(realpath "$1")
PARTNUM=${2:-2}
PARTSIZE=${3:-16G}

set -e

_do() {
set -- "$@"
echo -e "\x1b[1;32m>>>\x1b[0m" "$@" >&2
"$@"
}

_fatal() {
echo "$@" >&2
exit 1
}

if [[ $EUID != 0 ]]; then
_fatal "This script must be executed with a priviledged user!"
fi

# check disk parameter
if [[ -n "$DISK" ]]; then
if [[ ! -b $DISK ]]; then
_fatal "The specified file is not a block device!"
fi
else
_fatal "Must specify a disk!"
fi

# check transport protocol
TRAN=$(lsblk -d -n -o TRAN "$DISK")
if [[ $TRAN != "usb" ]]; then
_fatal "Normally, the TF card should communicate with the system" \
$'\n'"via a USB interface! But the current transport protocol" \
$'\n'"is \"$TRAN\"! To avoid damaging this computer's own discs," \
$'\n'"this script does not support operations in this situation."
fi

# warn user
echo -e "\x1b[1;33;40m"
echo "===================================================="
echo "=== PLEASE PAY ATTENTION TO PROTECT YOUR DATA!!! ==="
echo "===================================================="
echo -ne "\x1b[0m"
echo
echo -e "\x1b[1;31mThe operation will be performed on"
echo -e " device: \x1b[1;32m$DISK ($(lsblk -d -n -o SIZE "$DISK"))\x1b[1;31m"
echo -e " partition #: \x1b[1;32m$PARTNUM\x1b[1;31m"
echo -e " size of sector: \x1b[1;32m$SECTORSIZE bytes\x1b[1;31m"
echo -e " size to: \x1b[1;32m$PARTSIZE\x1b[0m"
_do lsblk --output NAME,SIZE,FSTYPE,MOUNTPOINT,SERIAL,MODEL,TRAN,TYPE "$DISK"

# confirm action
echo
read -r -p "Confirm? (y/N) " INPUT
if [[ ! $INPUT =~ ^[yY]([eE][sS])?$ ]]; then
_fatal "Abort!"
fi
echo

# wait
WAIT=5
echo -e "\x1b[1;31mWait for $WAIT seconds,"$'\n'"If here's something wrong, CTRL-C to abort.\x1b[0m"
while [[ ${WAIT} -gt 0 ]]; do
echo -en "\x1b[1;33m${WAIT} \x1b[m"
WAIT=$((WAIT - 1))
sleep 1
done
echo
echo

##########
## MAIN ##
##########

START_SECTOR=$(_do partx -o START -g --nr "$PARTNUM" "$DISK")
PARTITIONS=$(_do partx -l "$DISK" | _do wc -l)

# generate fdisk script
FDISK_SCRIPT=""
gen_fd_script() {
local i

FDISK_SCRIPT+=$'\n'"p"
for (( i=PARTITIONS; i>=PARTNUM; i-- )); do
FDISK_SCRIPT+=$'\n'"d"
FDISK_SCRIPT+=$'\n'"$i"
done
FDISK_SCRIPT+=$'\n'"n"
FDISK_SCRIPT+=$'\n'"p"
FDISK_SCRIPT+=$'\n'"$PARTNUM"
FDISK_SCRIPT+=$'\n'"$START_SECTOR"
FDISK_SCRIPT+=$'\n'"+${PARTSIZE#+}"
FDISK_SCRIPT+=$'\n'"p"
FDISK_SCRIPT+=$'\n'"w"
}

# do fdisk
gen_fd_script
_do echo "$FDISK_SCRIPT" | _do fdisk "$DISK"

# get partition device
PARTDEV=$(_do echo -e "i\n$PARTNUM" | _do fdisk "$DISK" | _do awk -F' ' '/^\s*Device:/ {printf $2"\n"}')
PARTSECTORS=$(_do echo -e "i\n$PARTNUM" | _do fdisk "$DISK" | _do awk -F' ' '/^\s*Sectors:/ {printf $2"\n"}')

_do sync

# resize
_do resize2fs "$PARTDEV" $((PARTSECTORS * SECTORSIZE / 1024))K

# fsck
_do e2fsck -f -p "$PARTDEV"

_do sync

0 comments on commit 997f5cd

Please sign in to comment.