Skip to content

Commit b537c06

Browse files
authored
Merge pull request #1356 from martindevans/binary_update_qwen3.5
Update For Qwen3.5/Gemma4 Support
2 parents 5d22db3 + 2a2d6d9 commit b537c06

18 files changed

Lines changed: 222 additions & 63 deletions

LLama.Unittest/MtmdWeightsTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void BasicPropertyChecks()
8181
Assert.True(_mtmdWeights.SupportsVision);
8282
Assert.False(_mtmdWeights.UsesMRope);
8383
Assert.True(_mtmdWeights.UsesNonCausalAttention);
84-
Assert.Equal(-1, _mtmdWeights.AudioBitrate);
84+
Assert.Equal(-1, _mtmdWeights.SampleRate);
8585
}
8686

8787
[Fact,Trait("Category", "NoCI")]
@@ -143,8 +143,8 @@ public void TokenizeProvidesChunkMetadata()
143143
Assert.True(_mtmdWeights.SupportsVision);
144144
Assert.False(_mtmdWeights.SupportsAudio);
145145

146-
var audioBitrate = _mtmdWeights.AudioBitrate;
147-
Assert.True(audioBitrate <= 0);
146+
var audioSampleRate = _mtmdWeights.SampleRate;
147+
Assert.True(audioSampleRate <= 0);
148148
}
149149
}
150150
}

LLama/Batched/BatchedExecutor.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ public sealed class BatchedExecutor
4343
/// The <see cref="LLamaWeights"/> this executor is using
4444
/// </summary>
4545
public LLamaWeights Model { get; }
46-
46+
47+
/// <summary>
48+
/// The optional <see cref="MtmdWeights"/> this executor is using
49+
/// </summary>
50+
public MtmdWeights? ClipModel { get; }
51+
4752
/// <summary>
4853
/// Get the number of tokens in the batch, waiting for <see cref="Infer"/> to be called
4954
/// </summary>
@@ -79,21 +84,15 @@ public int BatchedTokenCount
7984
/// </summary>
8085
/// <param name="model">The model to use</param>
8186
/// <param name="contextParams">Parameters to create a new context</param>
82-
public BatchedExecutor(LLamaWeights model, IContextParams contextParams)
83-
: this(model, contextParams, null)
84-
{
85-
}
86-
87-
public BatchedExecutor(LLamaWeights model, IContextParams contextParams, MtmdWeights? clipModel)
87+
/// <param name="clipModel">Clip model to use for multimodal capabilities</param>
88+
public BatchedExecutor(LLamaWeights model, IContextParams contextParams, MtmdWeights? clipModel = null)
8889
{
8990
Model = model;
9091
Context = model.CreateContext(contextParams);
9192
ClipModel = clipModel;
9293
Epoch = 1;
9394
}
9495

95-
public MtmdWeights? ClipModel { get; }
96-
9796
/// <summary>
9897
/// Start a new <see cref="Conversation"/>
9998
/// </summary>

LLama/LLamaEmbedder.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
43
using System.Threading;
54
using System.Threading.Tasks;
65
using LLama.Abstractions;
76
using LLama.Exceptions;
87
using LLama.Native;
9-
using Microsoft.Extensions.AI;
108
using Microsoft.Extensions.Logging;
11-
using static System.Net.Mime.MediaTypeNames;
129

1310
namespace LLama;
1411

@@ -79,7 +76,7 @@ public async Task<IReadOnlyList<float[]>> GetEmbeddings(string input, Cancellati
7976
Context.Dispose();
8077

8178
Context = _weights.CreateContext(_params, _logger);
82-
NativeApi.llama_set_embeddings(Context.NativeHandle, true);
79+
Context.NativeHandle.SetEmbeddings(true);
8380

8481
// Add all of the tokens to the batch
8582
var tokens = Context.Tokenize(input, special: true);

LLama/LLamaReranker.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using System.Text;
63
using System.Threading;
74
using System.Threading.Tasks;
8-
using System.Xml.Linq;
95
using LLama.Abstractions;
106
using LLama.Exceptions;
117
using LLama.Native;
@@ -44,7 +40,7 @@ public LLamaReranker(LLamaWeights weights, IContextParams @params, ILogger? logg
4440
if (@params.PoolingType != LLamaPoolingType.Rank)
4541
throw new NotSupportedException("Computing rank score, PoolingType must be equal to LLamaPoolingType.Rank");
4642
Context = weights.CreateContext(@params, logger);
47-
NativeApi.llama_set_embeddings(Context.NativeHandle, true);
43+
Context.NativeHandle.SetEmbeddings(true);
4844
}
4945

5046
/// <inheritdoc />

LLama/LLamaSharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
</ItemGroup>
6060

6161
<PropertyGroup>
62-
<BinaryReleaseId>ff4affb4c1aa7eb4_v3</BinaryReleaseId>
62+
<BinaryReleaseId>3f7c29d318e317b6</BinaryReleaseId>
6363
</PropertyGroup>
6464

6565
<PropertyGroup>

LLama/MtmdWeights.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ public int DecodeImageChunk(IntPtr chunkPtr, SafeLLamaContextHandle llamaContext
137137
public bool UsesMRope => NativeHandle.DecodeUseMRope();
138138

139139
/// <summary>
140-
/// Gets the audio bitrate advertised by the model.
140+
/// Gets the audio sample rate advertised by the model.
141141
/// </summary>
142-
public int AudioBitrate => NativeHandle.GetAudioBitrate();
142+
public int SampleRate => NativeHandle.GetAudioSampleRate();
143143

144144
/// <inheritdoc />
145145
public void Dispose() => NativeHandle.Dispose();

LLama/Native/GPUSplitMode.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,10 @@ public enum GPUSplitMode
2020
/// split layers and KV across GPUs, use tensor parallelism if supported
2121
/// </summary>
2222
Row = 2,
23+
24+
// Undocumented in llama.h
25+
/// <summary>
26+
///
27+
/// </summary>
28+
Tensor = 3,
2329
}

LLama/Native/LLamaFtype.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,17 @@ public enum LLamaFtype
206206
/// except 1d tensors
207207
/// </summary>
208208
LLAMA_FTYPE_MOSTLY_MXFP4_MOE = 38,
209-
209+
210+
/// <summary>
211+
/// Except 1d tensors
212+
/// </summary>
213+
LLAMA_FTYPE_MOSTLY_NVFP4 = 39,
214+
215+
/// <summary>
216+
/// Except 1d tensors
217+
/// </summary>
218+
LLAMA_FTYPE_MOSTLY_Q1_0 = 40,
219+
210220
/// <summary>
211221
/// File type was not specified
212222
/// </summary>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace LLama.Native;
2+
3+
/* /// <summary>
4+
///
5+
/// </summary>
6+
/// <remarks>llama_model_imatrix_data</remarks>
7+
public unsafe struct LLamaModelImatrixData
8+
{
9+
char* name;
10+
float* data;
11+
nuint size;
12+
} */

LLama/Native/LLamaModelQuantizeParams.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,35 @@ public bool keep_split
7979
}
8080
private sbyte _keep_split;
8181

82+
/// <summary>
83+
/// calculate and show the final quantization size without performing quantization
84+
/// </summary>
85+
public bool dry_run
86+
{
87+
get => Convert.ToBoolean(_dry_run);
88+
set => _dry_run = Convert.ToSByte(value);
89+
}
90+
private sbyte _dry_run;
91+
8292
/// <summary>
8393
/// pointer to importance matrix data
8494
/// </summary>
85-
public IntPtr imatrix;
95+
public IntPtr imatrix; // LLamaModelImatrixData *
8696

8797
/// <summary>
8898
/// pointer to vector containing overrides
8999
/// </summary>
90-
public IntPtr kv_overrides;
100+
public IntPtr kv_overrides; // llama_model_kv_override *
91101

92102
/// <summary>
93103
/// pointer to vector containing tensor types
94104
/// </summary>
95-
public IntPtr tensor_types;
105+
public IntPtr tensor_types; // llama_model_tensor_override *
96106

97107
/// <summary>
98108
/// Pointer to vector containing layer indices to prune
99109
/// </summary>
100-
public IntPtr prune_layers;
110+
public IntPtr prune_layers; // int32 *
101111

102112
/// <summary>
103113
/// Create a LLamaModelQuantizeParams with default values

0 commit comments

Comments
 (0)