huggingface / huggingface/transformers.js

[Bug] Library doesn't work on Alpine Linux. Is there a workaround we could have for it? Or simply the architecture doesn't comply with the library?

Open
#376 0 comments 3 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
16.3k
Forks
1.2k
Avg merge
6d 2h
Merged PRs (30d)
6

Description

Here's the Dockerfile used within a NodeJS backend, when we make the call to `await import("@xenova/transformers")()` in order to retrieve the pipeline it simply disconnects the process without throwing any error. This doesn't happen in Debian or Ubuntu.
Any clue why this is happening?

```
FROM node:lts-alpine3.18

RUN apk update && \
apk add --no-cache alpine-sdk build-base bash ca-certificates nginx gcompat && \
apk add --no-cache python3=3.10.13-r0 py3-pip gcc g++ libffi-dev musl-dev python3-dev cmake make openblas-dev && \
rm -rf /var/cache/apk/*

ENV HOMEDIR=/app
ENV NODE_PATH=/usr/local/lib/node_modules

WORKDIR $HOMEDIR
# Copy package.json and package-lock.json (or yarn.lock) to the container
COPY package*.json ./

# Install project dependencies
RUN yarn install

# Copy the rest of your application code
COPY . .
EXPOSE 9000
# Start your application
CMD ["yarn", "start"]

```

Here's a base index that I put together to be able track the issue, it's a base example:

```
const http = require('http');
const querystring = require('querystring');
const url = require('url');

class MyClassificationPipeline {
static task = 'text-classification';
static model = 'Xenova/distilbert-base-uncased-finetuned-sst-2-english';
static instance = null;

static async getInstance(progress_callback = null) {
if (this.instance === null) {
// Dynamically import the Transformers.js library
try {
let { pipeline, env } = await import('@xenova/transformers');

// NOTE: Uncomment this to change the cache directory
// env.cacheDir = './.cache';

this.instance = pipeline(this.task, this.model, { progress_callback });
} catch(e) {
console.error(e);
throw e;
}
}

return this.instance;
}
}

MyClassificationPipeline.getInstance()

// Comment out this line if you don't want to start loading the model as soon as the server starts.
// If commented out, the model will be loaded when the first request is received (i.e,. lazily).s

// Define the HTTP server
const server = http.createServer();
const hostname = '127.0.0.1';
const port = 9000;

// Listen for requests made to the server
server.on('request', async (req, res) => {
// Parse the request URL
const parsedUrl = url.parse(req.url);

// Extract the query parameters
const { text } = querystring.parse(parsedUrl.query);

// Set the response headers
res.setHeader('Content-Type', 'application/json');

let response;
console.log('parsedUrl.pathname ------------------->> ', text);
if (parsedUrl.pathname === '/classify' && text) {
const classifier = await MyClassificationPipeline.getInstance();
response = await classifier(text);
res.statusCode = 200;
} else {
response = { 'error': 'Bad request' }
res.statusCode = 400;
}

// Send the JSON response
res.end(JSON.stringify(response));
});

server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});

```

and package.json

```
{
"name": "commonjs",
"version": "1.0.0",
"description": "Server-side inference with Transformers.js (CommonJS)",
"main": "app.js",
"keywords": [],
"author": "Xenova",
"license": "ISC",
"scripts": {
"start": "node --watch index.js"
},
"dependencies": {
"@xenova/transformers": "^2.7.0",
"sharp": "^0.32.6"
}
}

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.