Skip to content

Commit

Permalink
🎨 ltp-extension 支持更多机器
Browse files Browse the repository at this point in the history
  • Loading branch information
AlongWY committed Sep 6, 2022
1 parent 3c6cf4d commit c999b63
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 20 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ltp-extension-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ jobs:
uses: messense/maturin-action@v1
with:
target: x86_64
args: --release --out dist --sdist -m python/extension/Cargo.toml
args: --release --out dist --sdist -m python/extension/Cargo.toml --features="malloc"
- name: Install built wheel - x86_64
run: |
pip3 install ltp_extension --no-index --find-links dist --force-reinstall
python3 -c "import ltp_extension"
- name: Build wheels - universal2
uses: messense/maturin-action@v1
with:
args: --release --universal2 --out dist -m python/extension/Cargo.toml
args: --release --universal2 --out dist -m python/extension/Cargo.toml --features="malloc"
- name: Install built wheel - universal2
run: |
pip3 install ltp_extension --no-index --find-links dist --force-reinstall
Expand Down Expand Up @@ -83,7 +83,7 @@ jobs:
uses: messense/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist -m python/extension/Cargo.toml
args: --release --out dist -m python/extension/Cargo.toml --features="malloc"
- name: Install built wheel
run: |
pip3 install ltp_extension --no-index --find-links dist --force-reinstall
Expand Down Expand Up @@ -127,7 +127,7 @@ jobs:
rust-toolchain: nightly
target: ${{ matrix.target }}
manylinux: auto
args: --release --out dist -m python/extension/Cargo.toml
args: --release --out dist -m python/extension/Cargo.toml --features="malloc"
- name: Install built wheel
if: matrix.target == 'x86_64'
run: |
Expand Down
2 changes: 1 addition & 1 deletion python/core/ltp_core/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.1"
__version__ = "0.1.2"
2 changes: 1 addition & 1 deletion python/core/ltp_core/algorithms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def eisner(scores, mask, remove_root=False):
result = torch.nn.utils.rnn.pad_sequence(
[
torch.tensor(sequence, device=mask.device)
for sequence in rust_eisner(scores, length, remove_root)
for sequence in rust_eisner(scores.tolist(), length.tolist(), remove_root)
],
batch_first=True,
padding_value=0,
Expand Down
2 changes: 1 addition & 1 deletion python/core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name="ltp_core",
version="0.1.1",
version="0.1.2",
author="Yunlong Feng",
author_email="[email protected]",
url="https://github.com/HIT-SCIR/ltp",
Expand Down
6 changes: 3 additions & 3 deletions python/extension/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ rayon = { version = "1.5" }
anyhow = { version = "1.0" }
serde = { version = "1.0", features = ["derive"] }
pyo3 = { version = "0.17", features = ["extension-module", "anyhow", "serde"] }
mimalloc = { version = "0.1", default-features = false, optional = true }

[dependencies.ltp]
version = "*"
path = "../../rust/ltp"
features = ["serialization", "parallel"]

[target.'cfg(not(target_env = "musl"))'.dependencies]
mimalloc = { version = "0.1", default-features = false }

[features]
default = ["abi3"]
abi3 = ["pyo3/abi3", "pyo3/abi3-py37"]
malloc = ["mimalloc"]
secure = ["mimalloc/secure"]
4 changes: 2 additions & 2 deletions python/extension/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(not(target_env = "musl"))]
#[cfg(feature = "malloc")]
use mimalloc::MiMalloc;

#[cfg(not(target_env = "musl"))]
#[cfg(feature = "malloc")]
#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;

Expand Down
2 changes: 1 addition & 1 deletion python/interface/ltp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "4.2.8"
__version__ = "4.2.9"

from ltp_extension.algorithms import StnSplit

Expand Down
4 changes: 2 additions & 2 deletions python/interface/ltp/nerual.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def _dep_post(

s_arc = s_arc.view(-1).cpu().numpy()
length = torch.sum(attention_mask, dim=1).view(-1).cpu().numpy() + 1
arcs = [sequence for sequence in eisner(s_arc, length, True)]
arcs = [sequence for sequence in eisner(s_arc.tolist(), length.tolist(), True)]
rels = torch.argmax(s_rel[:, 1:], dim=-1).cpu().numpy()
rels = [
[self.dep_vocab[rels[s, t, a]] for t, a in enumerate(arc)]
Expand Down Expand Up @@ -470,7 +470,7 @@ def _sdp_post(
# eisner 解码
e_arcs = s_arc.view(-1).cpu().numpy()
length = torch.sum(attention_mask, dim=1).view(-1).cpu().numpy() + 1
e_arcs = [sequence for sequence in eisner(e_arcs, length, True)]
e_arcs = [sequence for sequence in eisner(e_arcs.tolist(), length.tolist(), True)]

if tree:
rels = torch.argmax(s_rel[:, 1:], dim=-1).cpu().numpy()
Expand Down
2 changes: 1 addition & 1 deletion python/interface/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name="ltp",
version="4.2.8",
version="4.2.9",
author="Yunlong Feng",
author_email="[email protected]",
url="https://github.com/HIT-SCIR/ltp",
Expand Down
6 changes: 4 additions & 2 deletions rust/ltp-cffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ crate-type = ["cdylib", "staticlib"]
[dependencies]
rayon = { version = "1.5" }
ltp = { version = "*", path = "../ltp", features = ["serialization", "parallel"] }
mimalloc = { version = "0.1", default-features = false, optional = true }

[target.'cfg(not(target_env = "musl"))'.dependencies]
mimalloc = { version = "0.1", default-features = false }
[features]
malloc = ["mimalloc"]
secure = ["mimalloc/secure"]
4 changes: 2 additions & 2 deletions rust/ltp-cffi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(not(target_env = "musl"))]
#[cfg(feature = "malloc")]
use mimalloc::MiMalloc;

#[cfg(not(target_env = "musl"))]
#[cfg(feature = "malloc")]
#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;

Expand Down

0 comments on commit c999b63

Please sign in to comment.