-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make example Dockerfile friendlier - use prebuilt artifacts
- Loading branch information
Daulet Zhanguzin
committed
May 5, 2023
1 parent
6f28395
commit 12abe54
Showing
8 changed files
with
67 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
libtokenizers.a | ||
/release | ||
/artifacts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# syntax=docker/dockerfile:1.3 | ||
|
||
FROM rust:1.69 as builder-rust | ||
ARG TARGETPLATFORM | ||
WORKDIR /workspace | ||
COPY ./lib . | ||
RUN --mount=type=cache,target=/usr/local/cargo/registry,id=${TARGETPLATFORM} \ | ||
--mount=type=cache,target=/root/target,id=${TARGETPLATFORM} \ | ||
cargo build --release | ||
|
||
FROM golang:1.19 as builder-go | ||
ARG TARGETPLATFORM | ||
WORKDIR /workspace | ||
COPY --from=builder-rust /workspace/target/release/libtokenizers.a . | ||
COPY ./release . | ||
COPY ./test/data ./test/data | ||
RUN --mount=type=cache,target=/root/.cache/go-build \ | ||
--mount=type=cache,target=/var/cache/go,id=${TARGETPLATFORM} \ | ||
CGO_ENABLED=1 CGO_LDFLAGS="-Wl,--copy-dt-needed-entries" go run main.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/daulet/tokenizers/example | ||
|
||
go 1.20 | ||
|
||
require github.com/daulet/tokenizers v0.2.1 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/daulet/tokenizers v0.2.1 h1:Sb7gfk8N1yIWFCwG6wu5SEo8MsG+Onm7ejIoZe0ZkNg= | ||
github.com/daulet/tokenizers v0.2.1/go.mod h1:tGnMdZthXdcWY6DGD07IygpwJqiPvG85FQUnhs/wSCs= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/daulet/tokenizers" | ||
) | ||
|
||
func main() { | ||
tk, err := tokenizers.FromFile("./test/data/bert-base-uncased.json") | ||
if err != nil { | ||
panic(err) | ||
} | ||
// release native resources | ||
defer tk.Close() | ||
fmt.Println("Vocab size:", tk.VocabSize()) | ||
// Vocab size: 30522 | ||
fmt.Println(tk.Encode("brown fox jumps over the lazy dog", false)) | ||
// [2829 4419 14523 2058 1996 13971 3899] | ||
fmt.Println(tk.Encode("brown fox jumps over the lazy dog", true)) | ||
// [101 2829 4419 14523 2058 1996 13971 3899 102] | ||
fmt.Println(tk.Decode([]uint32{2829, 4419, 14523, 2058, 1996, 13971, 3899}, true)) | ||
// brown fox jumps over the lazy dog | ||
} |