From 66c9f5e6c82b592eaee5b3e9d50de57285952e0c Mon Sep 17 00:00:00 2001 From: Ruhollah Majdoddin Date: Tue, 15 Aug 2023 15:58:04 +0000 Subject: [PATCH 1/3] Adding pytest with the tiny model to macOS and windows (except amd64_arm64) runners --- .github/workflows/build.yml | 66 ++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f8b216b..16bbbe8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -68,6 +68,21 @@ jobs: run: | brew update + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: "3.10" + + - name: Pip setup + run: | + python -m pip install --upgrade pip + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + + - name: Build clang + id: make_build_clang + run: | + make run CC=clang + - name: Build id: make_build run: | @@ -77,16 +92,18 @@ jobs: id: make_build_runfast run: | make runfast + + - name: Test with pytest + run: pytest + + - - name: Build clang - id: make_build_clang - run: | - make run CC=clang windows-latest-make: runs-on: windows-latest strategy: + fail-fast: false #necessary, otherwise the matrix breaks matrix: arch: - amd64 @@ -106,11 +123,30 @@ jobs: with: arch: ${{ matrix.arch }} + - name: Set up Python 3.10 + if: matrix.arch != 'amd64_arm64' + uses: actions/setup-python@v3 + with: + python-version: "3.10" + + - name: Pip setup + if: matrix.arch != 'amd64_arm64' + run: | + python -m pip install --upgrade pip + if (Test-Path requirements.txt) { + pip install -r requirements.txt + } + - name: Build ${{ matrix.arch }} id: build_msvc run: | .\build_msvc.bat + #cross-comiled, cannot be run on host + - name: Test with pytest + if: matrix.arch != 'amd64_arm64' + run: pytest + windows-latest-mingw: runs-on: windows-latest @@ -135,6 +171,26 @@ jobs: install: mingw-w64-${{matrix.env}}-gcc make - name: Build ${{ matrix.sys }} ${{ matrix.env }} - id: build_mingw + id: build_mingw run: | make win64 + + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: "3.10" + + - name: Pip setup + shell: powershell + run: | + python -m pip install --upgrade pip + if (Test-Path requirements.txt) { + pip install -r requirements.txt + } + + - name: Test with pytest + shell: powershell + run: pytest + + + \ No newline at end of file From 87b11edf270feefd9606662e73dd2a202c5b4b7a Mon Sep 17 00:00:00 2001 From: Ruhollah Majdoddin Date: Tue, 15 Aug 2023 16:01:53 +0000 Subject: [PATCH 2/3] modifiying test_all so it can safely run on windows --- test_all.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/test_all.py b/test_all.py index 625af44..4423cb7 100644 --- a/test_all.py +++ b/test_all.py @@ -30,7 +30,7 @@ def attempt_download_files(): root_url = "https://huggingface.co/karpathy/tinyllamas/resolve/main/stories260K" need = ["stories260K.bin", "stories260K.pt", "tok512.bin", "tok512.model"] for file in need: - url = os.path.join(root_url, file) + url = root_url + '/' + file #os.path.join inserts \\ on windows filename = os.path.join(test_ckpt_dir, file) if not os.path.exists(filename): download_file(url, filename) @@ -46,13 +46,17 @@ def test_runc(): model_path = os.path.join(test_ckpt_dir, "stories260K.bin") tokenizer_path = os.path.join(test_ckpt_dir, "tok512.bin") - command = ["./run", model_path, "-z", tokenizer_path, "-t", "0.0", "-n", "200"] - proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - - stdout, stderr = proc.communicate() - + command = ["./run", model_path, "-z", tokenizer_path, "-t", "0.0", "-n", "200"] + with open('err.txt', mode='wb') as fe: + with open('stdout.txt', mode='wb') as fo: + proc = subprocess.Popen(command, stdout=fo, stderr=fe) #pipe in windows terminal does funny things like replacing \n with \r\n + proc.wait() + + with open('stdout.txt', mode='r') as f: + stdout = f.read() # strip the very last \n that is added by run.c for aesthetic reasons - stdout = stdout[:-1] + stdout = stdout[:-1].encode('ascii') + assert stdout == expected_stdout def test_python(): @@ -82,4 +86,6 @@ def test_python(): text = enc.decode(pt_tokens) text = text.encode('ascii') # turn into bytes - assert text == expected_stdout \ No newline at end of file + assert text == expected_stdout + +test_runc() \ No newline at end of file From 62a6d69d86670fca162473f866011ffb617e8ba4 Mon Sep 17 00:00:00 2001 From: Andrej Karpathy Date: Wed, 16 Aug 2023 02:22:13 +0000 Subject: [PATCH 3/3] style changes and remove spurious runc test call at the bottom --- .github/workflows/build.yml | 25 +++++++++++-------------- test_all.py | 12 +++++------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 16bbbe8..7e6474d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -92,10 +92,10 @@ jobs: id: make_build_runfast run: | make runfast - + - name: Test with pytest run: pytest - + @@ -103,7 +103,7 @@ jobs: runs-on: windows-latest strategy: - fail-fast: false #necessary, otherwise the matrix breaks + fail-fast: false #necessary, otherwise the matrix breaks matrix: arch: - amd64 @@ -128,7 +128,7 @@ jobs: uses: actions/setup-python@v3 with: python-version: "3.10" - + - name: Pip setup if: matrix.arch != 'amd64_arm64' run: | @@ -144,8 +144,8 @@ jobs: #cross-comiled, cannot be run on host - name: Test with pytest - if: matrix.arch != 'amd64_arm64' - run: pytest + if: matrix.arch != 'amd64_arm64' + run: pytest windows-latest-mingw: runs-on: windows-latest @@ -171,15 +171,15 @@ jobs: install: mingw-w64-${{matrix.env}}-gcc make - name: Build ${{ matrix.sys }} ${{ matrix.env }} - id: build_mingw + id: build_mingw run: | make win64 - + - name: Set up Python 3.10 uses: actions/setup-python@v3 with: python-version: "3.10" - + - name: Pip setup shell: powershell run: | @@ -187,10 +187,7 @@ jobs: if (Test-Path requirements.txt) { pip install -r requirements.txt } - + - name: Test with pytest shell: powershell - run: pytest - - - \ No newline at end of file + run: pytest diff --git a/test_all.py b/test_all.py index 4423cb7..a4d0976 100644 --- a/test_all.py +++ b/test_all.py @@ -30,7 +30,7 @@ def attempt_download_files(): root_url = "https://huggingface.co/karpathy/tinyllamas/resolve/main/stories260K" need = ["stories260K.bin", "stories260K.pt", "tok512.bin", "tok512.model"] for file in need: - url = root_url + '/' + file #os.path.join inserts \\ on windows + url = root_url + '/' + file #os.path.join inserts \\ on windows filename = os.path.join(test_ckpt_dir, file) if not os.path.exists(filename): download_file(url, filename) @@ -46,17 +46,17 @@ def test_runc(): model_path = os.path.join(test_ckpt_dir, "stories260K.bin") tokenizer_path = os.path.join(test_ckpt_dir, "tok512.bin") - command = ["./run", model_path, "-z", tokenizer_path, "-t", "0.0", "-n", "200"] - with open('err.txt', mode='wb') as fe: + command = ["./run", model_path, "-z", tokenizer_path, "-t", "0.0", "-n", "200"] + with open('err.txt', mode='wb') as fe: with open('stdout.txt', mode='wb') as fo: proc = subprocess.Popen(command, stdout=fo, stderr=fe) #pipe in windows terminal does funny things like replacing \n with \r\n proc.wait() - + with open('stdout.txt', mode='r') as f: stdout = f.read() # strip the very last \n that is added by run.c for aesthetic reasons stdout = stdout[:-1].encode('ascii') - + assert stdout == expected_stdout def test_python(): @@ -87,5 +87,3 @@ def test_python(): text = text.encode('ascii') # turn into bytes assert text == expected_stdout - -test_runc() \ No newline at end of file