Skip to content

Commit 94ae4ae

Browse files
authored
Merge pull request #47 from dferguson992/main
Bumped TAR, usability improvements for Transformers
2 parents 53ce9a5 + e0503e4 commit 94ae4ae

7 files changed

Lines changed: 58 additions & 29 deletions

File tree

generators/app/templates/Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ ARG BASE_IMAGE=lmsysorg/sglang:v0.5.4.post1
8888
FROM ${BASE_IMAGE}
8989

9090
# Set the model name for the transformer model
91-
ENV OPTION_MODEL="<%= modelName %>"
91+
<% if (modelServer === 'vllm') { %>
92+
ENV VLLM_MODEL="<%= modelName %>"
93+
<% } else if (modelServer === 'sglang') { %>
94+
ENV SGLANG_MODEL_PATH="<%= modelName %>"
95+
<% } %>
9296

9397
<% if (hfToken) { %>
9498
# Set HuggingFace authentication token

generators/app/templates/code/serve

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,33 @@ SERVER_ARGS=(--host 0.0.0.0 --port 8080)
1212
PREFIX="<%= modelServer === 'vllm' ? 'VLLM_' : 'SGLANG_' %>"
1313
ARG_PREFIX="--"
1414

15+
# Define environment variables to exclude (internal variables set by base images)
16+
<% if (modelServer === 'vllm') { %>
17+
EXCLUDE_VARS=("VLLM_USAGE_SOURCE")
18+
<% } else { %>
19+
EXCLUDE_VARS=()
20+
<% } %>
21+
1522
# Declare and populate array of matching environment variables
1623
mapfile -t env_vars < <(env | grep "^${PREFIX}")
1724

1825
# Loop through the array and convert to command-line arguments
1926
for var in "${env_vars[@]}"; do
2027
IFS='=' read -r key value <<< "$var"
28+
29+
# Skip excluded variables
30+
skip=false
31+
for exclude in "${EXCLUDE_VARS[@]}"; do
32+
if [ "$key" = "$exclude" ]; then
33+
skip=true
34+
break
35+
fi
36+
done
37+
38+
if [ "$skip" = true ]; then
39+
continue
40+
fi
41+
2142
# Remove prefix, convert to lowercase, and replace underscores with dashes
2243
arg_name=$(echo "${key#"${PREFIX}"}" | tr '[:upper:]' '[:lower:]' | tr '_' '-')
2344
SERVER_ARGS+=("${ARG_PREFIX}${arg_name}")

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@
8181
"tough-cookie": "^4.1.3",
8282
"tmp": "^0.2.3",
8383
"qs": "^6.14.1",
84-
"request": "2.88.2"
84+
"request": "2.88.2",
85+
"tar": "^7.5.3"
8586
},
8687
"resolutions": {
8788
"semver-regex": "4.0.5"

test/input-parsing-and-generation/hf-token-dockerfile.property.test.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ describe('HuggingFace Token Dockerfile Template - Property-Based Tests', () => {
7878
console.log(' ✅ Property 7 validated: ENV HF_TOKEN injection working correctly for all non-empty tokens');
7979
});
8080

81-
it('should place ENV HF_TOKEN after OPTION_MODEL and before COPY', async function() {
81+
it('should place ENV HF_TOKEN after VLLM_MODEL and before COPY', async function() {
8282
this.timeout(10000);
8383

8484
console.log('\n 🧪 Property 7b: ENV Directive Placement');
85-
console.log(' 📝 For any token value, ENV HF_TOKEN should appear after ENV OPTION_MODEL and before COPY command');
85+
console.log(' 📝 For any token value, ENV HF_TOKEN should appear after ENV VLLM_MODEL and before COPY command');
8686
console.log(' 📝 Validates: Requirements 4.4');
8787

8888
// Feature: huggingface-token-authentication, Property 7: Dockerfile ENV Injection (placement)
@@ -110,13 +110,13 @@ describe('HuggingFace Token Dockerfile Template - Property-Based Tests', () => {
110110
const dockerfileContent = fs.readFileSync(dockerfilePath, 'utf8');
111111

112112
// Find positions of key directives
113-
const optionModelPos = dockerfileContent.indexOf('ENV OPTION_MODEL=');
113+
const vllmModelPos = dockerfileContent.indexOf('ENV VLLM_MODEL=');
114114
const hfTokenPos = dockerfileContent.indexOf('ENV HF_TOKEN=');
115115
const copyPos = dockerfileContent.indexOf('COPY code/serve');
116116

117117
// Verify all directives exist
118-
if (optionModelPos === -1) {
119-
console.log(' ❌ ENV OPTION_MODEL not found');
118+
if (vllmModelPos === -1) {
119+
console.log(' ❌ ENV VLLM_MODEL not found');
120120
return false;
121121
}
122122
if (hfTokenPos === -1) {
@@ -128,9 +128,9 @@ describe('HuggingFace Token Dockerfile Template - Property-Based Tests', () => {
128128
return false;
129129
}
130130

131-
// Verify correct order: OPTION_MODEL < HF_TOKEN < COPY
132-
if (!(optionModelPos < hfTokenPos && hfTokenPos < copyPos)) {
133-
console.log(` ❌ Incorrect directive order: OPTION_MODEL=${optionModelPos}, HF_TOKEN=${hfTokenPos}, COPY=${copyPos}`);
131+
// Verify correct order: VLLM_MODEL < HF_TOKEN < COPY
132+
if (!(vllmModelPos < hfTokenPos && hfTokenPos < copyPos)) {
133+
console.log(` ❌ Incorrect directive order: VLLM_MODEL=${vllmModelPos}, HF_TOKEN=${hfTokenPos}, COPY=${copyPos}`);
134134
return false;
135135
}
136136

@@ -323,8 +323,11 @@ describe('HuggingFace Token Dockerfile Template - Property-Based Tests', () => {
323323
console.log(' ❌ FROM directive missing');
324324
return false;
325325
}
326-
if (!dockerfileContent.includes('ENV OPTION_MODEL=')) {
327-
console.log(' ❌ ENV OPTION_MODEL missing');
326+
// Check for model server-specific ENV variable
327+
const hasVllmModel = dockerfileContent.includes('ENV VLLM_MODEL=');
328+
const hasSglangModel = dockerfileContent.includes('ENV SGLANG_MODEL_PATH=');
329+
if (!hasVllmModel && !hasSglangModel) {
330+
console.log(' ❌ ENV VLLM_MODEL or ENV SGLANG_MODEL_PATH missing');
328331
return false;
329332
}
330333
if (!dockerfileContent.includes('COPY code/serve')) {

test/input-parsing-and-generation/hf-token-dockerfile.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('HuggingFace Token Dockerfile Template - Unit Tests', () => {
2424
setupTestHooks('HuggingFace Token Dockerfile Template Unit Tests');
2525

2626
describe('ENV Directive Placement', () => {
27-
it('should place ENV HF_TOKEN after OPTION_MODEL and before COPY', async function() {
27+
it('should place ENV HF_TOKEN after VLLM_MODEL and before COPY', async function() {
2828
this.timeout(5000);
2929

3030
console.log('\n 🧪 Testing ENV directive placement in Dockerfile');
@@ -51,17 +51,17 @@ describe('HuggingFace Token Dockerfile Template - Unit Tests', () => {
5151
const dockerfileContent = fs.readFileSync(dockerfilePath, 'utf8');
5252

5353
// Find positions of key directives
54-
const optionModelPos = dockerfileContent.indexOf('ENV OPTION_MODEL=');
54+
const vllmModelPos = dockerfileContent.indexOf('ENV VLLM_MODEL=');
5555
const hfTokenPos = dockerfileContent.indexOf('ENV HF_TOKEN=');
5656
const copyPos = dockerfileContent.indexOf('COPY code/serve');
5757

5858
// Verify all directives exist
59-
assert.ok(optionModelPos !== -1, 'ENV OPTION_MODEL should exist');
59+
assert.ok(vllmModelPos !== -1, 'ENV VLLM_MODEL should exist');
6060
assert.ok(hfTokenPos !== -1, 'ENV HF_TOKEN should exist');
6161
assert.ok(copyPos !== -1, 'COPY command should exist');
6262

63-
// Verify correct order: OPTION_MODEL < HF_TOKEN < COPY
64-
assert.ok(optionModelPos < hfTokenPos, 'ENV OPTION_MODEL should come before ENV HF_TOKEN');
63+
// Verify correct order: VLLM_MODEL < HF_TOKEN < COPY
64+
assert.ok(vllmModelPos < hfTokenPos, 'ENV VLLM_MODEL should come before ENV HF_TOKEN');
6565
assert.ok(hfTokenPos < copyPos, 'ENV HF_TOKEN should come before COPY command');
6666

6767
console.log(' ✅ ENV directive placement correct');
@@ -87,7 +87,7 @@ describe('HuggingFace Token Dockerfile Template - Unit Tests', () => {
8787
assert.fileContent('Dockerfile', /ENV HF_TOKEN=/);
8888

8989
// Verify it's in the transformers section (after FROM)
90-
assert.fileContent('Dockerfile', /FROM.*\n[\s\S]*ENV OPTION_MODEL=[\s\S]*ENV HF_TOKEN=/);
90+
assert.fileContent('Dockerfile', /FROM.*\n[\s\S]*ENV VLLM_MODEL=[\s\S]*ENV HF_TOKEN=/);
9191

9292
console.log(' ✅ ENV directive placement correct for vLLM');
9393
});
@@ -112,7 +112,7 @@ describe('HuggingFace Token Dockerfile Template - Unit Tests', () => {
112112
assert.fileContent('Dockerfile', /ENV HF_TOKEN=/);
113113

114114
// Verify it's in the transformers section (after FROM)
115-
assert.fileContent('Dockerfile', /FROM.*\n[\s\S]*ENV OPTION_MODEL=[\s\S]*ENV HF_TOKEN=/);
115+
assert.fileContent('Dockerfile', /FROM.*\n[\s\S]*ENV SGLANG_MODEL_PATH=[\s\S]*ENV HF_TOKEN=/);
116116

117117
console.log(' ✅ ENV directive placement correct for SGLang');
118118
});
@@ -149,7 +149,7 @@ describe('HuggingFace Token Dockerfile Template - Unit Tests', () => {
149149
assert.ok(dockerfileContent.includes('ENV HF_TOKEN='), 'ENV HF_TOKEN should be present');
150150

151151
// Verify it's in the transformers section (check for transformers-specific markers)
152-
assert.ok(dockerfileContent.includes('ENV OPTION_MODEL='), 'Should have OPTION_MODEL (transformers marker)');
152+
assert.ok(dockerfileContent.includes('ENV VLLM_MODEL='), 'Should have VLLM_MODEL (transformers marker)');
153153
assert.ok(dockerfileContent.includes('COPY code/serve'), 'Should have serve script (transformers marker)');
154154

155155
console.log(' ✅ ENV HF_TOKEN correctly in transformers section');

test/input-parsing-and-generation/hf-token-integration.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ describe('HuggingFace Token Integration Tests', () => {
6565
assert.ok(dockerfileContent.includes(`ENV HF_TOKEN="${testToken}"`),
6666
'Dockerfile should contain ENV HF_TOKEN with CLI token value');
6767

68-
// Verify ENV is in correct location (after OPTION_MODEL, before COPY)
69-
const optionModelPos = dockerfileContent.indexOf('ENV OPTION_MODEL=');
68+
// Verify ENV is in correct location (after VLLM_MODEL, before COPY)
69+
const vllmModelPos = dockerfileContent.indexOf('ENV VLLM_MODEL=');
7070
const hfTokenPos = dockerfileContent.indexOf('ENV HF_TOKEN=');
7171
const copyPos = dockerfileContent.indexOf('COPY code/serve');
7272

73-
assert.ok(optionModelPos < hfTokenPos && hfTokenPos < copyPos,
74-
'ENV HF_TOKEN should be between OPTION_MODEL and COPY');
73+
assert.ok(vllmModelPos < hfTokenPos && hfTokenPos < copyPos,
74+
'ENV HF_TOKEN should be between VLLM_MODEL and COPY');
7575

7676
console.log(' ✅ Complete project generated with CLI --hf-token');
7777
});
@@ -372,8 +372,8 @@ describe('HuggingFace Token Integration Tests', () => {
372372
'Dockerfile should contain ENV HF_TOKEN');
373373

374374
// Check other required directives
375-
assert.ok(dockerfileContent.includes('ENV OPTION_MODEL='),
376-
'Dockerfile should contain ENV OPTION_MODEL');
375+
assert.ok(dockerfileContent.includes('ENV VLLM_MODEL='),
376+
'Dockerfile should contain ENV VLLM_MODEL');
377377
assert.ok(dockerfileContent.includes('COPY code/serve'),
378378
'Dockerfile should contain COPY code/serve');
379379
assert.ok(dockerfileContent.includes('ENTRYPOINT'),

0 commit comments

Comments
 (0)