Skip to content

Commit e5c0e70

Browse files
authored
various updates to whats new (#42868)
1 parent 99ba3f7 commit e5c0e70

File tree

9 files changed

+31
-41
lines changed

9 files changed

+31
-41
lines changed

docs/core/whats-new/dotnet-8/runtime.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,11 +500,11 @@ IDataView predictions = model.Transform(split.TestSet);
500500

501501
.NET 8 introduces several new types aimed at improving app performance.
502502

503-
- The new <xref:System.Collections.Frozen?displayProperty=fullName> namespace includes the collection types <xref:System.Collections.Frozen.FrozenDictionary%602> and <xref:System.Collections.Frozen.FrozenSet%601>. These types don't allow any changes to keys and values once a collection created. That requirement allows faster read operations (for example, `TryGetValue()`). These types are particularly useful for collections that are populated on first use and then persisted for the duration of a long-lived service, for example:
503+
- The new <xref:System.Collections.Frozen?displayProperty=fullName> namespace includes the collection types <xref:System.Collections.Frozen.FrozenDictionary%602> and <xref:System.Collections.Frozen.FrozenSet%601>. These types don't allow any changes to keys and values once a collection is created. That requirement allows faster read operations (for example, `TryGetValue()`). These types are particularly useful for collections that are populated on first use and then persisted for the duration of a long-lived service, for example:
504504

505505
```csharp
506506
private static readonly FrozenDictionary<string, bool> s_configurationData =
507-
LoadConfigurationData().ToFrozenDictionary(optimizeForReads: true);
507+
LoadConfigurationData().ToFrozenDictionary();
508508

509509
// ...
510510
if (s_configurationData.TryGetValue(key, out bool setting) && setting)

docs/core/whats-new/dotnet-9/libraries.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
title: What's new in .NET libraries for .NET 9
33
description: Learn about the new .NET libraries features introduced in .NET 9.
44
titleSuffix: ""
5-
ms.date: 09/09/2024
5+
ms.date: 10/08/2024
66
ms.topic: whats-new
77
---
88

99
# What's new in .NET libraries for .NET 9
1010

11-
This article describes new features in the .NET libraries for .NET 9. It's been updated for .NET 9 RC 1.
11+
This article describes new features in the .NET libraries for .NET 9. It's been updated for .NET 9 RC 2.
1212

1313
## Base64Url
1414

@@ -44,7 +44,7 @@ The following example demonstrates using [Dictionary<TKey,TValue>.GetAlternateLo
4444

4545
### `OrderedDictionary<TKey, TValue>`
4646

47-
In many scenarios, you might want to store key-value pairs in a way where order can be maintained (a list of key-value pairs) but where fast lookup by key is also supported (a dictionary of key-value pairs). Since the early days of .NET, the <xref:System.Collections.Specialized.OrderedDictionary> type has supported this scenario, but only in a non-generic manner, with keys and values typed as <xref:System.Collections.Generic.OrderedDictionary%602> collection, which provides an efficient, generic type to support these scenarios.
47+
In many scenarios, you might want to store key-value pairs in a way where order can be maintained (a list of key-value pairs) but where fast lookup by key is also supported (a dictionary of key-value pairs). Since the early days of .NET, the <xref:System.Collections.Specialized.OrderedDictionary> type has supported this scenario, but only in a non-generic manner, with keys and values typed as `object`. .NET 9 introduces the long-requested <xref:System.Collections.Generic.OrderedDictionary%602> collection, which provides an efficient, generic type to support these scenarios.
4848

4949
The following code uses the new class.
5050

docs/core/whats-new/dotnet-9/overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: What's new in .NET 9
33
description: Learn about the new .NET features introduced in .NET 9 for the runtime, libraries, and SDK. Also find links to what's new in other areas, such as ASP.NET Core.
44
titleSuffix: ""
5-
ms.date: 09/10/2024
5+
ms.date: 10/08/2024
66
ms.topic: whats-new
77
---
88

docs/core/whats-new/dotnet-9/runtime.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
title: What's new in .NET 9 runtime
33
description: Learn about the new .NET features introduced in the .NET 9 runtime.
44
titleSuffix: ""
5-
ms.date: 09/09/2024
5+
ms.date: 10/08/2024
66
ms.topic: whats-new
77
---
88
# What's new in the .NET 9 runtime
99

10-
This article describes new features and performance improvements in the .NET runtime for .NET 9. It's been updated for .NET 9 Preview 7.
10+
This article describes new features and performance improvements in the .NET runtime for .NET 9. It's been updated for .NET 9 RC 2.
1111

1212
## Attribute model for feature switches with trimming support
1313

docs/core/whats-new/dotnet-9/sdk.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
title: What's new in the SDK for .NET 9
33
description: Learn about the new .NET SDK features introduced in .NET 9, including for unit testing, terminal logger, tool roll-forward, and build script analyzers.
44
titleSuffix: ""
5-
ms.date: 09/09/2024
5+
ms.date: 10/08/2024
66
ms.topic: whats-new
77
---
88

99
# What's new in the SDK for .NET 9
1010

11-
This article describes new features in the .NET SDK for .NET 9. It's been updated for .NET RC 1.
11+
This article describes new features in the .NET SDK for .NET 9. It's been updated for .NET RC 2.
1212

1313
## Unit testing
1414

docs/machine-learning/whats-new/snippets/csharp/CodeGen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static void RunIt()
1212
using Stream vocabStream = File.OpenRead(phi2VocabPath);
1313
using Stream mergesStream = File.OpenRead(phi2MergePath);
1414

15-
Tokenizer phi2Tokenizer = Tokenizer.CreateCodeGen(vocabStream, mergesStream);
15+
Tokenizer phi2Tokenizer = CodeGenTokenizer.Create(vocabStream, mergesStream);
1616
IReadOnlyList<int> ids = phi2Tokenizer.EncodeToIds("Hello, World");
1717
// </CodeGen>
1818
}

docs/machine-learning/whats-new/snippets/csharp/Llama.cs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using Microsoft.ML.Tokenizers;
2-
using System;
1+
using System;
32
using System.Collections.Generic;
43
using System.IO;
5-
using System.Net.Http;
4+
using System.Linq;
5+
using Microsoft.ML.Tokenizers;
66

77
internal class Llama
88
{
@@ -12,7 +12,7 @@ public static void RunIt()
1212
// Create the Tokenizer.
1313
string modelUrl = @"https://huggingface.co/hf-internal-testing/llama-llamaTokenizer/resolve/main/llamaTokenizer.model";
1414
using Stream remoteStream = File.OpenRead(modelUrl);
15-
Tokenizer llamaTokenizer = Tokenizer.CreateLlama(remoteStream);
15+
Tokenizer llamaTokenizer = LlamaTokenizer.Create(remoteStream);
1616

1717
string text = "Hello, World!";
1818

@@ -32,27 +32,21 @@ public static void RunIt()
3232
// idsCount = 5
3333

3434
// Full encoding.
35-
EncodingResult result = llamaTokenizer.Encode(text);
36-
Console.WriteLine($"result.Tokens = {{'{string.Join("', '", result.Tokens)}'}}");
35+
IReadOnlyList<EncodedToken> result = llamaTokenizer.EncodeToTokens(text, out string? normalizedString);
36+
Console.WriteLine($"result.Tokens = {{'{string.Join("', '", result.Select(t => t.Value))}'}}");
3737
// result.Tokens = {'<s>', '▁Hello', ',', '▁World', '!'}
38-
Console.WriteLine($"result.Offsets = {{{string.Join(", ", result.Offsets)}}}");
39-
// result.Offsets = {(0, 0), (0, 6), (6, 1), (7, 6), (13, 1)}
40-
Console.WriteLine($"result.Ids = {{{string.Join(", ", result.Ids)}}}");
38+
Console.WriteLine($"result.Ids = {{{string.Join(", ", result.Select(t => t.Id))}}}");
4139
// result.Ids = {1, 15043, 29892, 2787, 29991}
4240

4341
// Encode up 2 tokens.
44-
int index1 = llamaTokenizer.IndexOfTokenCount(text, maxTokenCount: 2, out string processedText1, out int tokenCount1);
45-
Console.WriteLine($"processedText1 = {processedText1}");
46-
// processedText1 = ▁Hello,▁World!
42+
int index1 = llamaTokenizer.GetIndexByTokenCount(text, maxTokenCount: 2, out string? processedText1, out int tokenCount1);
4743
Console.WriteLine($"tokenCount1 = {tokenCount1}");
4844
// tokenCount1 = 2
4945
Console.WriteLine($"index1 = {index1}");
5046
// index1 = 6
5147

5248
// Encode from end up to one token.
53-
int index2 = llamaTokenizer.LastIndexOfTokenCount(text, maxTokenCount: 1, out string processedText2, out int tokenCount2);
54-
Console.WriteLine($"processedText2 = {processedText2}");
55-
// processedText2 = ▁Hello,▁World!
49+
int index2 = llamaTokenizer.GetIndexByTokenCountFromEnd(text, maxTokenCount: 1, out string? processedText2, out int tokenCount2);
5650
Console.WriteLine($"tokenCount2 = {tokenCount2}");
5751
// tokenCount2 = 1
5852
Console.WriteLine($"index2 = {index2}");
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
Tiktoken.RunIt();
1+
//Tiktoken.RunIt();
2+
Llama.RunIt();

docs/machine-learning/whats-new/snippets/csharp/Tiktoken.cs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using Microsoft.ML.Tokenizers;
45

56
internal class Tiktoken
67
{
78
public static void RunIt()
89
{
910
// <Tiktoken>
10-
Tokenizer tokenizer = Tokenizer.CreateTiktokenForModel("gpt-4");
11+
Tokenizer tokenizer = TiktokenTokenizer.CreateForModel("gpt-4");
1112
string text = "Hello, World!";
1213

1314
// Encode to IDs.
@@ -26,36 +27,30 @@ public static void RunIt()
2627
// idsCount = 4
2728

2829
// Full encoding.
29-
EncodingResult result = tokenizer.Encode(text);
30-
Console.WriteLine($"result.Tokens = {{'{string.Join("', '", result.Tokens)}'}}");
30+
IReadOnlyList<EncodedToken> result = tokenizer.EncodeToTokens(text, out string? normalizedString);
31+
Console.WriteLine($"result.Tokens = {{'{string.Join("', '", result.Select(t => t.Value))}'}}");
3132
// result.Tokens = {'Hello', ',', ' World', '!'}
32-
Console.WriteLine($"result.Offsets = {{{string.Join(", ", result.Offsets)}}}");
33-
// result.Offsets = {(0, 5), (5, 1), (6, 6), (12, 1)}
34-
Console.WriteLine($"result.Ids = {{{string.Join(", ", result.Ids)}}}");
33+
Console.WriteLine($"result.Ids = {{{string.Join(", ", result.Select(t => t.Id))}}}");
3534
// result.Ids = {9906, 11, 4435, 0}
3635

3736
// Encode up to number of tokens limit.
38-
int index1 = tokenizer.IndexOfTokenCount(
37+
int index1 = tokenizer.GetIndexByTokenCount(
3938
text,
4039
maxTokenCount: 1,
41-
out string processedText1,
40+
out string? processedText1,
4241
out int tokenCount1
4342
); // Encode up to one token.
44-
Console.WriteLine($"processedText1 = {processedText1}");
45-
// processedText1 = Hello, World!
4643
Console.WriteLine($"tokenCount1 = {tokenCount1}");
4744
// tokenCount1 = 1
4845
Console.WriteLine($"index1 = {index1}");
4946
// index1 = 5
5047

51-
int index2 = tokenizer.LastIndexOfTokenCount(
48+
int index2 = tokenizer.GetIndexByTokenCountFromEnd(
5249
text,
5350
maxTokenCount: 1,
54-
out string processedText2,
51+
out string? processedText2,
5552
out int tokenCount2
5653
); // Encode from end up to one token.
57-
Console.WriteLine($"processedText2 = {processedText2}");
58-
// processedText2 = Hello, World!
5954
Console.WriteLine($"tokenCount2 = {tokenCount2}");
6055
// tokenCount2 = 1
6156
Console.WriteLine($"index2 = {index2}");

0 commit comments

Comments
 (0)