mirror of
https://github.com/mii443/tokenizers.git
synced 2025-08-30 20:19:21 +00:00
Node - Fix EncodeTask
This commit is contained in:
@ -39,7 +39,7 @@ impl Task for EncodeTask {
|
|||||||
fn perform(&self) -> Result<Self::Output, Self::Error> {
|
fn perform(&self) -> Result<Self::Output, Self::Error> {
|
||||||
match self {
|
match self {
|
||||||
EncodeTask::Single(worker, input) => {
|
EncodeTask::Single(worker, input) => {
|
||||||
let mut input = unsafe { std::ptr::read(input) };
|
let mut input = unsafe { std::ptr::replace(&input as *const _ as *mut _, None) };
|
||||||
let tokenizer: &Tokenizer = unsafe { &*worker.ptr };
|
let tokenizer: &Tokenizer = unsafe { &*worker.ptr };
|
||||||
tokenizer
|
tokenizer
|
||||||
.encode(input.take().ok_or("No provided input")?)
|
.encode(input.take().ok_or("No provided input")?)
|
||||||
@ -47,7 +47,7 @@ impl Task for EncodeTask {
|
|||||||
.map(|encoding| EncodeOutput::Single(encoding))
|
.map(|encoding| EncodeOutput::Single(encoding))
|
||||||
}
|
}
|
||||||
EncodeTask::Batch(worker, input) => {
|
EncodeTask::Batch(worker, input) => {
|
||||||
let mut input = unsafe { std::ptr::read(input) };
|
let mut input = unsafe { std::ptr::replace(&input as *const _ as *mut _, None) };
|
||||||
let tokenizer: &Tokenizer = unsafe { &*worker.ptr };
|
let tokenizer: &Tokenizer = unsafe { &*worker.ptr };
|
||||||
tokenizer
|
tokenizer
|
||||||
.encode_batch(input.take().ok_or("No provided input")?)
|
.encode_batch(input.take().ok_or("No provided input")?)
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
extern crate tokenizers as tk;
|
extern crate tokenizers as tk;
|
||||||
|
|
||||||
use crate::encoding::*;
|
|
||||||
use crate::models::*;
|
use crate::models::*;
|
||||||
use crate::tasks::tokenizer::{EncodeTask, WorkingTokenizer};
|
use crate::tasks::tokenizer::{EncodeTask, WorkingTokenizer};
|
||||||
use neon::prelude::*;
|
use neon::prelude::*;
|
||||||
@ -16,7 +15,7 @@ pub struct Tokenizer {
|
|||||||
|
|
||||||
impl Tokenizer {
|
impl Tokenizer {
|
||||||
pub fn prepare_for_task(&self) -> Option<WorkingTokenizer> {
|
pub fn prepare_for_task(&self) -> Option<WorkingTokenizer> {
|
||||||
if std::sync::Arc::strong_count(&self.running_task) > 0 {
|
if std::sync::Arc::strong_count(&self.running_task) > 1 {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
Reference in New Issue
Block a user