अपने ब्लॉग - भाग ६: स्थानीय जनीकरण के लिए "लेवर" बनाया (हिन्दी (Hindi))

अपने ब्लॉग - भाग ६: स्थानीय जनीकरण के लिए "लेवर" बनाया

Wednesday, 12 November 2025

//

21 minute read

चेतावनी: ये तो डीआरफ्लिक हैं जो 'के साथ गलत' है.

यह शायद नीचे क्या काम नहीं करेगा, मैं इन्हें बनाने के लिए कैसे और फिर सभी कदमों के रूप में और काम करने के लिए एक नमूना ऐप मिलता है... तुम चुपके से किया गया है और उन्हें देखा है! वे शायद मध्य-बार के लिए तैयार हो जाएगा.

## परिचय

भाग 6 में आपका स्वागत हैहम पूरी तरह से इन्फ्रास्फीति - निर्माण किया है (संग्रेसन)पार्ट 4विंडोज़ क्लाएंट (w)पार्ट 5, एम्बेडिंग तथा सदिश खोज (e)पार्ट 3, और जीपिय सेटअप (यूयूयूपी.)पार्ट 2

अब रोमांचक भाग आता है: स्थानीय टी. वी.

ध्यान दें: यह एआई के साथ मेरे परीक्षण का हिस्सा है (जैसे कि मेरे स्वयं का संपादन).

उसी आवाज़ की तरह, उसी आवाज़ में एक - दूसरे का हाथ होता है; सिर्फ तेज़ उंगलियों को ।

यह है जहां हम अंत में "अनुष्टि" के भाग बनाने के लिए...

हम आपके A4000 जीपी पर स्थानीय भाषा मॉडलों को स्थानीय रूप से चला लेंगे, अपने पिछले ब्लॉग पोस्ट पर आधारित संदर्भ जानकारी युक्त सुझाव तैयार कर रहे हैं। |--------|-----------|-------------------| | स्थानीय क्यों? | ✅ Complete | ❌ Data sent to third party | | इसके पहले, चलो समझते हैं क्यों हम स्थानीय मॉडलों पर चल रहे हैं... / मैं ... खोलने के API का उपयोग करने के बजाय. | ✅ Free after setup | ❌ Per-token pricing | | स्थानीय बनाम एपीआई तुलना | ✅ <1 second | ⚠️ Network dependent | | ALTANTATATAL स्थानीय _LYEANTH (ओनेई, ...) | ✅ Full control | ❌ Limited | | गोपनीयता | ✅ Any GGUF model | ❌ Provider's models only | | खर्च | ✅ Works offline | ❌ Requires internet | | हाल ही में@ info: whatsthis | ❌ Complex | ✅ Simple |

मनपसंद सूचना

मॉडल चयन

ऑफ़लाइन

graph TB
    A[C# Application] --> B{Integration Method}

    B --> C[LLamaSharp]
    B --> D[ONNX Runtime]
    B --> E[TorchSharp]
    B --> F[HTTP API]

    C --> G[llama.cpp bindings]
    G --> H[GGUF Models]

    D --> I[ONNX Models]
    I --> J[Limited Model Support]

    E --> K[PyTorch Models]
    K --> L[Complex Setup]

    F --> M[External Process]
    M --> N[Ollama, LM Studio]

    class C recommended
    class G,H llamaSharp

    classDef recommended stroke:#333,stroke-width:4px
    classDef llamaSharp stroke:#333,stroke-width:2px

सेटअप

एक लेखन सहायक, गोपनीयता और क़ीमती विषय के लिए ।

  • हम नहीं चाहते कि ब्लॉग मसौदा बाहरी एपीआईओं को भेजा जाए, और प्रति ekating एक दैनिक लेखन औज़ार के लिए तेजी से आगे बढ़ें।
  • C# के लिए संयोजन विकल्प
  • सी# में चलाने के कई तरीके हैं:
  • मेरा चुनाव: Loma तीव्र
  • क्यों?

एनएफएसमा के लिए देशी C# बाइंडिंग. sciz (सबसे तेज लाइब्रेरी)

जीजीयूएफ फ़ॉर्मेट समर्थित करता है (आज तक, विस्तृत मॉडलों के रूप में)

CUNA त्वरण बनायासक्रिय विकास तथा बड़े समुदाय

graph LR
    A[Original Model<br/>Llama 2 7B<br/>~28GB float32] --> B[Quantization]

    B --> C[Q4_K_M<br/>~4.1GB<br/>4-bit]
    B --> D[Q5_K_M<br/>~4.8GB<br/>5-bit]
    B --> E[Q6_K<br/>~5.5GB<br/>6-bit]
    B --> F[Q8_0<br/>~7.2GB<br/>8-bit]

    C --> G[Fast, Lower Quality]
    D --> H[Balanced]
    E --> I[Higher Quality]
    F --> J[Near Original]

    class A original
    class C,D quantized
    class H recommended

    classDef original stroke:#333,stroke-width:2px
    classDef quantized stroke:#333,stroke-width:2px
    classDef recommended stroke:#333,stroke-width:2px

Lemma, मिस्पे, पाउ, गेमा, और अधिक के साथ काम करता है:

  • मॉडल फार्मेट्स समझ रहा है (D)
  • GGUF फार्मेट
  • जीजीयूएफ
  • (GE) यह चलाने के लिए मानक है।

क्वाडाइजेशन ने समझाया

मूल मॉडल: 32- बिट फ्लोट (बहुत बड़ा, बहुत सही) |-------|---------------|------------|-----------|------------|------------|---------| | Q4: 4- बिट पूर्णांक (75% छोटा, छोटा क्वालिटी नुकसान) | 2.3GB | ~4GB | ✅ Easy | ✅ Easy | ✅ Easy | ⭐⭐⭐ Good | | Q5/Q6: ज़्यादातर प्रयोगों के लिए मीठा जगह | 4.1GB | ~6GB | ✅ Tight | ✅ Good | ✅ Easy | ⭐⭐⭐ Good | | क्यू8: पास- पृष्ठ विशेषता, अभी भी 4x छोटा | 4.1GB | ~6GB | ✅ Tight | ✅ Good | ✅ Easy | ⭐⭐⭐⭐ Better | | हार्डवेयर द्वारा मॉडल चयन | 4.1GB | ~6GB | ✅ Tight | ✅ Good | ✅ Easy | ⭐⭐⭐⭐ Better | | IMTACT मॉडल आकार (Q4_M) आलेख+BGY+REGY+RGGEGEGGESUGEGGY+RGEGGGERSGY+EGEGEARS(Q_KS_KS_KSG_M) | 4.7GB | ~7GB | ⚠️ Very Tight | ✅ Good | ✅ Easy | ⭐⭐⭐⭐⭐ Best | | Ph-3 मिनी (3. 8B) | 7.4GB | ~10GB | ❌ No | ⚠️ Tight | ✅ Good | ⭐⭐⭐⭐ Better |

लाला 2 7B

  • मिस्टी 7Bगेमा 7Bलाला 3 8Bलाला 2 13B**GPS द्वारा व्याख्या:**8GB वीरैम
  • : इससे प्रारंभ करें: मिस्टी 7BयाPhh-3 मिनी(बेंड)
  • 12GB वीरैम: लाला 3 8B(सबसे अच्छा क्वालिटी) यामिस्टी 7B
  • **(तेज)**16GB वीरैम (मेरे सेटअप)

लाला 3 8B: कोशिश करें या कोशिश करें13B मॉडलसिर्फ सीपीयू: कोई मॉडल काम करता है, बस धीमी गति के साथ शुरू होता है (Mh-3M के साथ शुरू होता है)

  • मेरी सिफारिश
  • मिस्टी 7B
  • (लेट संस्करण) या
  • लालाला 3

8B

तकनीकी लेखन के लिए बढ़िया विशेषता

सारे GPS आकार में कार्य करता है

  1. अंतर्क्रियात्मक प्रयोग के लिए पर्याप्तनिर्देशनों का पालन करते हुए अच्छा
  2. मॉडल डाउनलोड किया जा रहा है"mistral 7b gguf"
  3. मॉडलों को हिलते हुए मुख पर वितरित किया जाता है.

**हम gGUF संस्करण का उपयोग करेंगे.**जीजीफ़ मॉडल पाना

Bakkks के quinीकरण के लिए देखो (सबसे लोकप्रिय)

# Install huggingface-cli
pip install huggingface-hub

# Download Mistral 7B Q5_K_M (recommended)
huggingface-cli download TheBloke/Mistral-7B-Instruct-v0.2-GGUF \
    mistral-7b-instruct-v0.2.Q5_K_M.gguf \
    --local-dir C:\models\mistral-7b \
    --local-dir-use-symlinks False

प्रत्यक्ष लिंक

  1. (ब्लॉक्स’sterss):
  2. मिस्सेंट- 7- माह0.2- zUFmistral-7b-instruct-v0.2.Q5_K_M.ggufएलला- 7BB- चैट-च्फ़
  3. एलला- 3- 8BB-GUF
  4. विशिष्ट क्वाडाइज़ेशन डाउनलोड करेंC:\models\mistral-7b\

या डाउनलोड दस्ती रूप से करें:

"फ़ाइल तथा संस्करण" टैब पर क्लिक करें

cd Mostlylucid.BlogLLM.Core
dotnet add package LLamaSharp  # Latest version
dotnet add package LLamaSharp.Backend.Cuda12  # Latest, matching CUDA version

ढूंढें

लाम्बिया तीव्र सेटअप

नुआ पैकेज संस्थापित करें

using LLama;
using LLama.Common;

// Check if CUDA is available
bool cudaAvailable = NativeLibraryConfig.Instance.CudaEnabled;
Console.WriteLine($"CUDA Available: {cudaAvailable}");

दो पैकेज क्यों?false- कोर लाइब्रेरी

  1. सीयूडीए
  2. LLamaSharp.Backend.Cuda1212 घर की साफ - सफाई के लिए
  3. सीयूडीए बैकएण्ड सत्यापित करें

LUNA को स्वचालित पता चलेगा यदि सही संस्थापित किया गया है.

यदि

using LLama;
using LLama.Common;

namespace Mostlylucid.BlogLLM.Core.Services
{
    public class ModelParameters
    {
        public string ModelPath { get; set; } = string.Empty;
        public int ContextSize { get; set; } = 4096;  // Context window
        public int GpuLayerCount { get; set; } = 35;  // Layers on GPU (35 = all for 7B)
        public int Seed { get; set; } = 1337;  // For reproducibility
        public float Temperature { get; set; } = 0.7f;  // Creativity (0.0 = deterministic, 1.0 = creative)
        public float TopP { get; set; } = 0.9f;  // Nucleus sampling
        public int MaxTokens { get; set; } = 500;  // Max generation length
    }
}

, चेक करें::

  • **सीयूडी 12.x संस्थापित (- पार्ट 2)**पैकेज संस्थापित

    • पथ में सीयूडीएएस डिरेक्ट्री शामिल है
    • कलीएम सेवा करना
  • मॉडल पैरामीटर्सपैरामीटर व्याख्या

    • कॉन्टेक्स्ट आकार
    • : मॉडल कितना पाठ "देखो" को एक साथ देख सकते हैं
    • 4096 चिन्ह आदमियों के लिए 3000 शब्द
  • इससे बड़ा/ अधिक संदर्भ लेकिन धीमा व ज्यादा वीरैमगॉर्नेनोusa. kgm

    • : GuUP पर कितने ट्रांसमीटर चल रहा है
    • 7B मॉडलों में ~32 परतों है
    • 35 = गापी पर सब कुछ डाल (तेज)
  • निचला मूल्य = कम वीरैम परंतु धीमा करेंतापक्रम

    • : बेतरतीब गति
      1. 0 = हमेशा संभव चिह्न चुनें (बोत, बारंबार)

0. 7 = अच्छा संतुलन (हमारा डिफ़ॉल्ट)

using LLama;
using LLama.Common;
using Microsoft.Extensions.Logging;

namespace Mostlylucid.BlogLLM.Core.Services
{
    public interface ILlmService
    {
        Task<string> GenerateAsync(string prompt, CancellationToken cancellationToken = default);
        Task<string> GenerateWithContextAsync(string prompt, List<string> contextChunks, CancellationToken cancellationToken = default);
    }

    public class LlmService : ILlmService, IDisposable
    {
        private readonly LLamaWeights _model;
        private readonly LLamaContext _context;
        private readonly ILogger<LlmService> _logger;
        private readonly ModelParameters _parameters;

        public LlmService(ModelParameters parameters, ILogger<LlmService> logger)
        {
            _parameters = parameters;
            _logger = logger;

            _logger.LogInformation("Loading model from {ModelPath}", parameters.ModelPath);

            // Configure model parameters
            var modelParams = new ModelParams(parameters.ModelPath)
            {
                ContextSize = (uint)parameters.ContextSize,
                GpuLayerCount = parameters.GpuLayerCount,
                Seed = (uint)parameters.Seed,
                UseMemoryLock = true,  // Keep model in RAM
                UseMemorymap = true    // Memory-map the model file
            };

            // Load model
            _model = LLamaWeights.LoadFromFile(modelParams);
            _context = _model.CreateContext(modelParams);

            _logger.LogInformation("Model loaded successfully. VRAM used: ~{VRAM}GB",
                EstimateVRAMUsage(parameters.GpuLayerCount));
        }

        public async Task<string> GenerateAsync(string prompt, CancellationToken cancellationToken = default)
        {
            var executor = new InteractiveExecutor(_context);

            var inferenceParams = new InferenceParams
            {
                Temperature = _parameters.Temperature,
                TopP = _parameters.TopP,
                MaxTokens = _parameters.MaxTokens,
                AntiPrompts = new[] { "\n\nUser:", "###" }  // Stop generation at these
            };

            var result = new StringBuilder();

            _logger.LogInformation("Generating response for prompt: {Prompt}", TruncateForLog(prompt));

            await foreach (var token in executor.InferAsync(prompt, inferenceParams, cancellationToken))
            {
                result.Append(token);
            }

            var response = result.ToString().Trim();
            _logger.LogInformation("Generated {Tokens} tokens", CountTokens(response));

            return response;
        }

        public async Task<string> GenerateWithContextAsync(
            string prompt,
            List<string> contextChunks,
            CancellationToken cancellationToken = default)
        {
            // Build prompt with retrieved context
            var fullPrompt = BuildContextualPrompt(prompt, contextChunks);

            _logger.LogInformation("Context chunks: {Count}, Total prompt tokens: ~{Tokens}",
                contextChunks.Count, CountTokens(fullPrompt));

            return await GenerateAsync(fullPrompt, cancellationToken);
        }

        private string BuildContextualPrompt(string userPrompt, List<string> contextChunks)
        {
            var sb = new StringBuilder();

            sb.AppendLine("You are a helpful writing assistant for a technical blog.");
            sb.AppendLine("Use the following excerpts from past blog posts as context:");
            sb.AppendLine();

            for (int i = 0; i < contextChunks.Count; i++)
            {
                sb.AppendLine($"--- Context {i + 1} ---");
                sb.AppendLine(contextChunks[i]);
                sb.AppendLine();
            }

            sb.AppendLine("---");
            sb.AppendLine();
            sb.AppendLine("Based on the context above, help with the following:");
            sb.AppendLine(userPrompt);
            sb.AppendLine();
            sb.AppendLine("Response:");

            return sb.ToString();
        }

        private int CountTokens(string text)
        {
            // Rough estimate: 1 token ≈ 4 characters
            return text.Length / 4;
        }

        private string TruncateForLog(string text, int maxLength = 100)
        {
            if (text.Length <= maxLength) return text;
            return text.Substring(0, maxLength) + "...";
        }

        private double EstimateVRAMUsage(int gpuLayers)
        {
            // Rough estimate for 7B model
            return (gpuLayers / 35.0) * 6.0;  // ~6GB for full 7B model
        }

        public void Dispose()
        {
            _context?.Dispose();
            _model?.Dispose();
        }
    }
}

1. 1. 0+ = बहुत जटिल (प्रयोगात्मक हो सकता है):

  1. शीर्षP: वुल्फहाउंडिंग
  2. 0.9 = उन लक्षणों पर गौर कीजिए जो संभावना का 90% भार पैदा करते हैंबेवजह सबूतों से पीछा छुड़ाने से बचा जा सकता है
  3. LM सेवा कार्यान्वयनयह कैसे काम करता है
  4. मॉडल लोड कर रहा है: निर्दिष्ट पैरामीटरों के उपयोग से GGUF मॉडल को वीरैम में लोड करें
  5. इंटरएक्टिव एक्स- स्केलर: चैट जैसा व्यवहार के लिए Luea तीव्र मौत मोड

सम्मिलित करने का दावा करें (S)

using Microsoft.Extensions.Logging;

class Program
{
    static async Task Main(string[] args)
    {
        // Setup logging
        var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
        var logger = loggerFactory.CreateLogger<LlmService>();

        // Configure model
        var parameters = new ModelParameters
        {
            ModelPath = @"C:\models\mistral-7b\mistral-7b-instruct-v0.2.Q5_K_M.gguf",
            ContextSize = 4096,
            GpuLayerCount = 35,
            Temperature = 0.7f,
            MaxTokens = 200
        };

        // Create service
        using var llmService = new LlmService(parameters, logger);

        // Test simple generation
        Console.WriteLine("=== Test 1: Simple Generation ===\n");
        var response1 = await llmService.GenerateAsync(
            "Explain what Docker Compose is in 2-3 sentences."
        );
        Console.WriteLine(response1);
        Console.WriteLine("\n");

        // Test with context
        Console.WriteLine("=== Test 2: Generation with Context ===\n");
        var context = new List<string>
        {
            "Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application's services.",
            "In development, Docker Compose makes it easy to spin up all dependencies (databases, caches, etc.) with one command: docker-compose up."
        };

        var response2 = await llmService.GenerateWithContextAsync(
            "Write an introduction paragraph for a blog post about using Docker Compose for development dependencies.",
            context
        );
        Console.WriteLine(response2);
    }
}

: संकेतों के रूप में वे तैयार कर रहे हैं (सच्चे समय आउटपुट):

=== Test 1: Simple Generation ===

Docker Compose is a tool that allows you to define and run multi-container Docker applications using a simple YAML configuration file. It simplifies the process of managing multiple containers, networking, and volumes, making it ideal for development environments.

=== Test 2: Generation with Context ===

If you've ever found yourself juggling multiple terminal windows to start databases, caches, and other services for local development, Docker Compose is about to become your new best friend. This powerful tool lets you define your entire development environment in a single YAML file and spin everything up with one command. In this post, we'll explore how to leverage Docker Compose to manage all your development dependencies, making your local setup reproducible, shareable, and incredibly easy to manage.

कॉन्टेक्स्ट बिल्डिंग

: फिर से ब्लॉग रीफ्रेंस द्वारा एक साथ जोड़ता है

एन्टी- साइन्स

: कुछ वाक्यांशों में पीढ़ी को बन्द करता है (प्रयोगी मेढ़ेलिंग)

namespace Mostlylucid.BlogLLM.Client.Services
{
    public class SuggestionService : ISuggestionService
    {
        private readonly BatchEmbeddingService _embeddingService;
        private readonly QdrantVectorStore _vectorStore;
        private readonly ILlmService _llmService;  // NEW

        public SuggestionService(
            BatchEmbeddingService embeddingService,
            QdrantVectorStore vectorStore,
            ILlmService llmService)  // NEW
        {
            _embeddingService = embeddingService;
            _vectorStore = vectorStore;
            _llmService = llmService;
        }

        public async Task<string> GenerateAiSuggestionAsync(
            string currentText,
            List<SimilarPost> context)
        {
            // Extract text from similar posts
            var contextChunks = context
                .Take(3)  // Top 3 most similar
                .Select(p => p.FullText)
                .ToList();

            // Determine what type of suggestion to generate
            var prompt = DeterminePromptType(currentText);

            // Generate suggestion
            var suggestion = await _llmService.GenerateWithContextAsync(
                prompt,
                contextChunks
            );

            return suggestion;
        }

        private string DeterminePromptType(string currentText)
        {
            // Analyze what user is writing
            var lines = currentText.Split('\n');
            var lastLine = lines.LastOrDefault(l => !string.IsNullOrWhiteSpace(l)) ?? "";

            // Is user starting a new section?
            if (lastLine.StartsWith("## "))
            {
                return "Suggest 3-5 bullet points for what this section could cover.";
            }

            // Is user writing code?
            if (lastLine.Contains("```"))
            {
                return "Suggest relevant code examples that might be useful here.";
            }

            // Is user writing an introduction?
            if (currentText.Length < 500 && currentText.Contains("## Introduction"))
            {
                return "Suggest 2-3 sentences to continue this introduction based on similar posts.";
            }

            // Default: continue current thought
            return "Suggest 1-2 sentences to continue the current paragraph in a natural way.";
        }
    }
}

सेवा की जाँच की जा रही है

public partial class SuggestionsViewModel : ViewModelBase
{
    [RelayCommand]
    private async Task RegenerateSuggestion()
    {
        IsGenerating = true;
        AiSuggestion = "Generating...";

        try
        {
            var currentText = GetCurrentEditorText();  // From messaging
            var suggestion = await _suggestionService.GenerateAiSuggestionAsync(
                currentText,
                SimilarPosts.ToList()
            );

            AiSuggestion = suggestion;
        }
        catch (Exception ex)
        {
            AiSuggestion = $"Error: {ex.Message}";
        }
        finally
        {
            IsGenerating = false;
        }
    }
}

प्रत्याशित आउटपुट

आश्‍चर्यजनक!

मॉडल काम कर रहा है और कोरे, संदर्भ-क्रम पाठ तैयार कर रहा है.

public class LlmServiceFactory
{
    private static LlmService? _instance;
    private static readonly object _lock = new();

    public static LlmService GetInstance(ModelParameters parameters, ILogger<LlmService> logger)
    {
        if (_instance == null)
        {
            lock (_lock)
            {
                if (_instance == null)
                {
                    _instance = new LlmService(parameters, logger);
                }
            }
        }

        return _instance;
    }
}

सुझाव पैनलों के साथ बधाई

अब हम भाग 5 से हमारे विंडोज़ क्लाएंट में एकीकृत की पीढ़ी है.

public class StatefulLlmService
{
    private readonly InferenceParams _defaultParams;
    private string _cachedPromptPrefix = string.Empty;

    public async Task<string> GenerateWithPrefixAsync(string prefix, string newPrompt)
    {
        // If prefix matches cached, reuse KV cache
        if (prefix == _cachedPromptPrefix)
        {
            // Only process new tokens
            return await GenerateAsync(newPrompt);
        }

        // Process entire prompt and cache
        _cachedPromptPrefix = prefix;
        return await GenerateAsync(prefix + newPrompt);
    }
}

सुझाव निवेदन अद्यतन करें

सुझावों को अपडेट करें

परफ़ॉर्मेंस ऑप्टीमाइज़ेशन

public async Task<List<string>> GenerateBatchAsync(List<string> prompts)
{
    var results = new List<string>();

    foreach (var prompt in prompts)
    {
        // With KV cache reuse, subsequent prompts are faster
        results.Add(await GenerateAsync(prompt));
    }

    return results;
}

मॉडल कैशिंग

निवेदन के बीच भरी हुई मॉडल को रखें:

केवी कैश रीफ़

private string PromptContinueWriting(string currentText, List<string> context)
{
    return $@"You are a technical blog writing assistant.

Here are excerpts from similar blog posts:
{string.Join("\n\n", context.Select((c, i) => $"--- Post {i + 1} ---\n{c}"))}

Current draft:
{currentText}

Task: Suggest 2-3 sentences to naturally continue the current paragraph.
Keep the same technical depth and casual, pragmatic tone.

Suggestion:";
}

एल्दा तीव्र समर्थन के लिए केवीवी कैश फिर से इस्तेमाल की गयी पीढ़ियों के लिए:

private string PromptSectionStructure(string sectionTitle, List<string> context)
{
    return $@"You are a technical blog writing assistant.

Similar sections from past posts:
{string.Join("\n\n", context)}

New section: {sectionTitle}

Task: Suggest 4-6 bullet points for what this section should cover.
Format as a markdown list.

Bullets:";
}

यह विशेष रूप से हमारे मामले का उपयोग करने के लिए उपयोगी है - संदर्भ एक ही रहते हैं, सिर्फ उपयोगकर्ता के प्रश्न परिवर्तन.

private string PromptCodeExample(string description, List<string> context)
{
    return $@"You are a C# coding assistant.

Relevant code from past posts:
{string.Join("\n\n", context)}

Task: {description}

Provide a clean, well-commented C# code example.

Code:";
}

बैचिंग

बहुत से सुझावों के लिए, उन्हें बैच करें:

लिखने की सहायता के लिए इंजीनियरिंग को संकेत दें

public class VramMonitor
{
    [DllImport("nvml.dll")]
    private static extern int nvmlDeviceGetMemoryInfo(IntPtr device, ref NvmlMemory memory);

    [StructLayout(LayoutKind.Sequential)]
    public struct NvmlMemory
    {
        public ulong Total;
        public ulong Free;
        public ulong Used;
    }

    public static (ulong used, ulong total) GetVramUsage()
    {
        // Simplified - actual implementation needs proper NVML initialization
        var memory = new NvmlMemory();
        // nvmlDeviceGetMemoryInfo(device, ref memory);

        return (memory.Used / 1024 / 1024, memory.Total / 1024 / 1024);  // Convert to MB
    }
}

अच्छा निर्देश = अच्छा आउटपुट.

public class LlmServiceWithUnload : IDisposable
{
    private LlmService? _service;
    private readonly Timer _unloadTimer;
    private DateTime _lastUsed;

    public LlmServiceWithUnload()
    {
        _unloadTimer = new Timer(CheckForUnload, null, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1));
    }

    private void CheckForUnload(object? state)
    {
        if (_service != null && (DateTime.Now - _lastUsed) > TimeSpan.FromMinutes(10))
        {
            _service.Dispose();
            _service = null;
            GC.Collect();
            Console.WriteLine("Model unloaded due to inactivity");
        }
    }

    public async Task<string> GenerateAsync(string prompt)
    {
        _lastUsed = DateTime.Now;

        if (_service == null)
        {
            // Reload model
            _service = CreateService();
        }

        return await _service.GenerateAsync(prompt);
    }
}

यहाँ अलग - अलग उदाहरणों के लिए नमूना दिए गए हैं:

लिखना जारी रखें

public async Task<string> GenerateWithRetryAsync(string prompt, int maxRetries = 3)
{
    for (int i = 0; i < maxRetries; i++)
    {
        try
        {
            return await GenerateAsync(prompt);
        }
        catch (OutOfMemoryException)
        {
            _logger.LogWarning("OOM error, reducing max tokens");
            _parameters.MaxTokens = Math.Max(100, _parameters.MaxTokens / 2);
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Generation failed, attempt {Attempt}/{Max}", i + 1, maxRetries);

            if (i == maxRetries - 1) throw;

            await Task.Delay(1000 * (i + 1));  // Exponential backoff
        }
    }

    throw new Exception("Generation failed after retries");
}

खण्ड स्ट्रक्चर

कोड उदाहरण

  1. ✅ Chose मेमोरी प्रबंधनबड़े - बड़े मॉडलों के साथ, याददाश्‍त प्रबंधन अत्यावश्‍यक है ।
  2. ✅ Understood मॉनीटर वीरैम उपयोगजब निष्क्रिय हो तो मॉडल अनलोड करें
  3. ✅ Selected appropriate model (सिंकिंग में त्रुटि / अचानक ही हालात बिगड़ सकते हैं ।हैंडल करें:
  4. ✅ Implemented LlmService with CUDA acceleration
  5. ✅ Integrated with Windows client for suggestions
  6. ✅ Implemented prompt engineering for writing tasks
  7. ✅ Added performance optimizations (caching, batching)
  8. ✅ Handled memory management and errors

सारांश

हम सफलतापूर्वक स्थानीय एनएफएम को एकीकृत किया है:**एलएचएआ तीव्र**C# एकीकरण के लिए

  • जीजीयूएफ फ़ॉर्मेट
  • और साधारण बरतने की चीज़ भी किसी को नहीं देते
  • मिस्टी 7B
  • लालाला 3
  • 8B)
  • अगला क्या है?
  • में

पार्ट 7: सामग्री बनाना बनाने की इंजीनियरिंग की पूर्वसूचना देता है (g)

, हम पूरे संतुष्ट पीढ़ी पर ध्यान केंद्रित करेंगे:

पार्ट 1: परिचय व गुण

भाग ६: स्थानीय संयोजन(यह पोस्ट)!

Finding related posts...
logo

© 2026 Scott Galloway — Unlicense — All content and source code on this site is free to use, copy, modify, and sell.