Skip to content

Commit 355b840

Browse files
committed
Merge remote-tracking branch 'origin/master' into projects
2 parents f53218c + 003d5e2 commit 355b840

2,086 files changed

Lines changed: 943021 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clang-format

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
---
2+
Language: Cpp
3+
AlignAfterOpenBracket: Align
4+
AlignArrayOfStructures: Left
5+
AlignConsecutiveAssignments: AcrossComments
6+
AlignConsecutiveBitFields: AcrossComments
7+
AlignConsecutiveDeclarations: AcrossComments
8+
AlignConsecutiveMacros: AcrossComments
9+
# AlignConsecutiveShortCaseStatements: AcrossComments
10+
AlignEscapedNewlines: Left # LeftWithLastLine
11+
AlignOperands: Align
12+
AlignTrailingComments:
13+
Kind: Always
14+
OverEmptyLines: 1
15+
AllowAllArgumentsOnNextLine: true
16+
AllowAllParametersOfDeclarationOnNextLine: false
17+
# AllowBreakBeforeNoexceptSpecifier: OnlyWithParen
18+
AllowShortBlocksOnASingleLine: Never
19+
AllowShortCaseLabelsOnASingleLine: false
20+
AllowShortFunctionsOnASingleLine: Inline
21+
AllowShortIfStatementsOnASingleLine: Never
22+
AllowShortLambdasOnASingleLine: Inline
23+
AllowShortLoopsOnASingleLine: false
24+
AlwaysBreakBeforeMultilineStrings: true
25+
# Treat CUDA keywords/attributes as "attribute macros" and avoid breaking lines inside them
26+
AttributeMacros:
27+
- __host__
28+
- __device__
29+
- __global__
30+
- __forceinline__
31+
- __launch_bounds__
32+
BinPackArguments: true
33+
BinPackParameters: false # OnePerLine
34+
BitFieldColonSpacing: Both
35+
BreakBeforeBraces: Custom # Attach
36+
BraceWrapping:
37+
AfterCaseLabel: true
38+
AfterClass: false
39+
AfterControlStatement: false
40+
AfterEnum: false
41+
AfterFunction: false
42+
AfterNamespace: false
43+
AfterObjCDeclaration: false
44+
AfterStruct: false
45+
AfterUnion: false
46+
AfterExternBlock: false
47+
BeforeCatch: false
48+
BeforeElse: false
49+
BeforeLambdaBody: false
50+
BeforeWhile: false
51+
IndentBraces: false
52+
SplitEmptyFunction: false
53+
SplitEmptyRecord: false
54+
SplitEmptyNamespace: false
55+
# BreakAdjacentStringLiterals: true
56+
BreakAfterAttributes: Never
57+
BreakBeforeBinaryOperators: None
58+
BreakBeforeInlineASMColon: OnlyMultiline
59+
BreakBeforeTernaryOperators: false
60+
# BreakBinaryOperations: Never
61+
BreakConstructorInitializers: AfterColon
62+
# BreakFunctionDefinitionParameters: false
63+
BreakInheritanceList: AfterComma
64+
BreakStringLiterals: true
65+
# BreakTemplateDeclarations: Yes
66+
ColumnLimit: 120
67+
CommentPragmas: '^ IWYU pragma:'
68+
CompactNamespaces: false
69+
ConstructorInitializerIndentWidth: 4
70+
ContinuationIndentWidth: 4
71+
Cpp11BracedListStyle: false
72+
DerivePointerAlignment: false
73+
DisableFormat: false
74+
EmptyLineBeforeAccessModifier: Leave
75+
EmptyLineAfterAccessModifier: Never
76+
ExperimentalAutoDetectBinPacking: false
77+
FixNamespaceComments: true
78+
IncludeBlocks: Regroup
79+
IncludeCategories:
80+
- Regex: '".*"'
81+
Priority: 1
82+
SortPriority: 0
83+
- Regex: '^<.*\.h>'
84+
Priority: 2
85+
SortPriority: 0
86+
- Regex: '^<.*'
87+
Priority: 3
88+
SortPriority: 0
89+
- Regex: '.*'
90+
Priority: 4
91+
SortPriority: 0
92+
IncludeIsMainRegex: '([-_](test|unittest))?$'
93+
IncludeIsMainSourceRegex: ''
94+
IndentAccessModifiers: false
95+
IndentCaseBlocks: true
96+
IndentCaseLabels: true
97+
IndentExternBlock: NoIndent
98+
IndentGotoLabels: false
99+
IndentPPDirectives: AfterHash
100+
IndentWidth: 4
101+
IndentWrappedFunctionNames: false
102+
InsertBraces: true # NOTE: may lead to incorrect formatting
103+
InsertNewlineAtEOF: true
104+
JavaScriptQuotes: Leave
105+
JavaScriptWrapImports: true
106+
KeepEmptyLinesAtTheStartOfBlocks: false
107+
LambdaBodyIndentation: Signature
108+
LineEnding: LF
109+
MacroBlockBegin: ''
110+
MacroBlockEnd: ''
111+
MaxEmptyLinesToKeep: 1
112+
NamespaceIndentation: None
113+
ObjCBinPackProtocolList: Auto
114+
ObjCBlockIndentWidth: 4
115+
ObjCSpaceAfterProperty: true
116+
ObjCSpaceBeforeProtocolList: true
117+
PPIndentWidth: -1
118+
PackConstructorInitializers: CurrentLine
119+
PenaltyBreakAssignment: 2
120+
PenaltyBreakBeforeFirstCallParameter: 1
121+
PenaltyBreakComment: 300
122+
PenaltyBreakFirstLessLess: 120
123+
PenaltyBreakString: 1000
124+
PenaltyBreakTemplateDeclaration: 10
125+
PenaltyExcessCharacter: 1000000
126+
PenaltyReturnTypeOnItsOwnLine: 200
127+
PointerAlignment: Middle
128+
QualifierAlignment: Left
129+
#QualifierOrder: ['static', 'inline', 'friend', 'constexpr', 'const', 'volatile', 'type', 'restrict']
130+
RawStringFormats:
131+
- Language: Cpp
132+
Delimiters:
133+
- cc
134+
- CC
135+
- cpp
136+
- Cpp
137+
- CPP
138+
- 'c++'
139+
- 'C++'
140+
CanonicalDelimiter: ''
141+
ReferenceAlignment: Middle
142+
ReflowComments: false # IndentOnly
143+
SeparateDefinitionBlocks: Always
144+
SortIncludes: CaseInsensitive
145+
SortUsingDeclarations: LexicographicNumeric
146+
SpaceAfterCStyleCast: true
147+
SpaceAfterLogicalNot: false
148+
SpaceAfterTemplateKeyword: true
149+
SpaceBeforeAssignmentOperators: true
150+
SpaceBeforeCpp11BracedList: false
151+
SpaceBeforeCtorInitializerColon: true
152+
SpaceBeforeInheritanceColon: true
153+
SpaceBeforeParens: ControlStatements
154+
SpaceBeforeRangeBasedForLoopColon: true
155+
SpaceInEmptyBlock: false
156+
SpaceInEmptyParentheses: false
157+
SpacesBeforeTrailingComments: 2
158+
SpacesInAngles: Never
159+
SpacesInContainerLiterals: true
160+
SpacesInLineCommentPrefix:
161+
Minimum: 1
162+
Maximum: -1
163+
SpacesInParentheses: false
164+
SpacesInSquareBrackets: false
165+
SpaceBeforeSquareBrackets: false
166+
Standard: c++17
167+
TabWidth: 4
168+
UseTab: Never
169+
WhitespaceSensitiveMacros: ['STRINGIZE']
170+
...
171+

.clang-tidy

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
Checks: >
3+
bugprone-*,
4+
-bugprone-easily-swappable-parameters,
5+
-bugprone-implicit-widening-of-multiplication-result,
6+
-bugprone-misplaced-widening-cast,
7+
-bugprone-narrowing-conversions,
8+
readability-*,
9+
-readability-avoid-unconditional-preprocessor-if,
10+
-readability-function-cognitive-complexity,
11+
-readability-identifier-length,
12+
-readability-implicit-bool-conversion,
13+
-readability-magic-numbers,
14+
-readability-uppercase-literal-suffix,
15+
-readability-simplify-boolean-expr,
16+
-readability-math-missing-parentheses,
17+
clang-analyzer-*,
18+
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
19+
performance-*,
20+
-performance-enum-size,
21+
portability-*,
22+
-portability-simd-intrinsics,
23+
misc-*,
24+
-misc-const-correctness,
25+
-misc-non-private-member-variables-in-classes,
26+
-misc-no-recursion,
27+
-misc-use-anonymous-namespace,
28+
FormatStyle: none

.devops/cann.Dockerfile

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# ==============================================================================
2+
# ARGUMENTS
3+
# ==============================================================================
4+
5+
# Define the CANN base image for easier version updates later
6+
ARG CHIP_TYPE=910b
7+
ARG CANN_BASE_IMAGE=quay.io/ascend/cann:8.3.rc2-${CHIP_TYPE}-openeuler24.03-py3.11
8+
9+
# ==============================================================================
10+
# BUILD STAGE
11+
# Compile all binary files and libraries
12+
# ==============================================================================
13+
FROM ${CANN_BASE_IMAGE} AS build
14+
15+
# -- Install build dependencies --
16+
RUN yum install -y gcc g++ cmake make git libcurl-devel python3 python3-pip && \
17+
yum clean all && \
18+
rm -rf /var/cache/yum
19+
20+
# -- Set the working directory --
21+
WORKDIR /app
22+
23+
# -- Copy project files --
24+
COPY . .
25+
26+
# -- Set CANN environment variables (required for compilation) --
27+
# Using ENV instead of `source` allows environment variables to persist across the entire image layer
28+
ENV ASCEND_TOOLKIT_HOME=/usr/local/Ascend/ascend-toolkit/latest
29+
ENV LD_LIBRARY_PATH=${ASCEND_TOOLKIT_HOME}/lib64:${LD_LIBRARY_PATH}
30+
ENV PATH=${ASCEND_TOOLKIT_HOME}/bin:${PATH}
31+
ENV ASCEND_OPP_PATH=${ASCEND_TOOLKIT_HOME}/opp
32+
ENV LD_LIBRARY_PATH=${ASCEND_TOOLKIT_HOME}/runtime/lib64/stub:$LD_LIBRARY_PATH
33+
# ... You can add other environment variables from the original file as needed ...
34+
# For brevity, only core variables are listed here. You can paste the original ENV list here.
35+
36+
# -- Build llama.cpp --
37+
# Use the passed CHIP_TYPE argument and add general build options
38+
ARG CHIP_TYPE
39+
RUN source /usr/local/Ascend/ascend-toolkit/set_env.sh --force \
40+
&& \
41+
cmake -B build \
42+
-DGGML_CANN=ON \
43+
-DCMAKE_BUILD_TYPE=Release \
44+
-DSOC_TYPE=ascend${CHIP_TYPE} \
45+
. && \
46+
cmake --build build --config Release -j$(nproc)
47+
48+
# -- Organize build artifacts for copying in later stages --
49+
# Create a lib directory to store all .so files
50+
RUN mkdir -p /app/lib && \
51+
find build -name "*.so*" -exec cp -P {} /app/lib \;
52+
53+
# Create a full directory to store all executables and Python scripts
54+
RUN mkdir -p /app/full && \
55+
cp build/bin/* /app/full/ && \
56+
cp *.py /app/full/ && \
57+
cp -r gguf-py /app/full/ && \
58+
cp -r requirements /app/full/ && \
59+
cp requirements.txt /app/full/
60+
# If you have a tools.sh script, make sure it is copied here
61+
# cp .devops/tools.sh /app/full/tools.sh
62+
63+
# ==============================================================================
64+
# BASE STAGE
65+
# Create a minimal base image with CANN runtime and common libraries
66+
# ==============================================================================
67+
FROM ${CANN_BASE_IMAGE} AS base
68+
69+
# -- Install runtime dependencies --
70+
RUN yum install -y libgomp curl && \
71+
yum clean all && \
72+
rm -rf /var/cache/yum
73+
74+
# -- Set CANN environment variables (required for runtime) --
75+
ENV ASCEND_TOOLKIT_HOME=/usr/local/Ascend/ascend-toolkit/latest
76+
ENV LD_LIBRARY_PATH=/app:${ASCEND_TOOLKIT_HOME}/lib64:${LD_LIBRARY_PATH}
77+
ENV PATH=${ASCEND_TOOLKIT_HOME}/bin:${PATH}
78+
ENV ASCEND_OPP_PATH=${ASCEND_TOOLKIT_HOME}/opp
79+
# ... You can add other environment variables from the original file as needed ...
80+
81+
WORKDIR /app
82+
83+
# Copy compiled .so files from the build stage
84+
COPY --from=build /app/lib/ /app
85+
86+
# ==============================================================================
87+
# FINAL STAGES (TARGETS)
88+
# ==============================================================================
89+
90+
### Target: full
91+
# Complete image with all tools, Python bindings, and dependencies
92+
# ==============================================================================
93+
FROM base AS full
94+
95+
COPY --from=build /app/full /app
96+
97+
# Install Python dependencies
98+
RUN yum install -y git python3 python3-pip && \
99+
pip3 install --no-cache-dir --upgrade pip setuptools wheel && \
100+
pip3 install --no-cache-dir -r requirements.txt && \
101+
yum clean all && \
102+
rm -rf /var/cache/yum
103+
104+
# You need to provide a tools.sh script as the entrypoint
105+
ENTRYPOINT ["/app/tools.sh"]
106+
# If there is no tools.sh, you can set the default to start the server
107+
# ENTRYPOINT ["/app/llama-server"]
108+
109+
### Target: light
110+
# Lightweight image containing only llama-cli and llama-completion
111+
# ==============================================================================
112+
FROM base AS light
113+
114+
COPY --from=build /app/full/llama-cli /app/full/llama-completion /app
115+
116+
ENTRYPOINT [ "/app/llama-cli" ]
117+
118+
### Target: server
119+
# Dedicated server image containing only llama-server
120+
# ==============================================================================
121+
FROM base AS server
122+
123+
ENV LLAMA_ARG_HOST=0.0.0.0
124+
125+
COPY --from=build /app/full/llama-server /app
126+
127+
HEALTHCHECK --interval=5m CMD [ "curl", "-f", "http://localhost:8080/health" ]
128+
129+
ENTRYPOINT [ "/app/llama-server" ]

0 commit comments

Comments
 (0)