Which tasks parallelize well, and which do not?
Answer:
Tasks that heavily load the CPU and actively use memory parallelize poorly. In Python, this is especially noticeable due to the GIL: CPU-bound calculations will still use only one thread, and parallel execution will not provide a speedup. Moreover, due to thread switching, the program may even slow down.
If a task combines IO and heavy processing — for example, downloading and parsing — it is better to separate it: keep IO in threads, and assign CPU load to processes (via multiprocessing) or move it to a queue.
tags: #interview
Please open Telegram to view this post
VIEW IN TELEGRAM
❤1
What is the order of execution of decorators if there are several on one function?
Answer:
tags: #interview
Please open Telegram to view this post
VIEW IN TELEGRAM
❔ Interview question
What is the difference between using
Answer: is a context manager that globally disables gradient calculation for all operations within its block. It's used during inference to reduce memory usage and speed up computation. is a tensor-specific method that creates a new tensor sharing the same data but detached from the current computation graph. This stops gradients from flowing back to the original graph through this tensor, effectively creating a fork.
tags: #interview #pytorch #machinelearning
➡ @DataScienceQ
What is the difference between using
tensor.detach() and wrapping code in with torch.no_grad()?Answer:
with torch.no_grad()tensor.detach()tags: #interview #pytorch #machinelearning
➡ @DataScienceQ
❔ Interview question
When saving a PyTorch model, what is the difference between saving the entire model versus saving just the model's
Answer:Saving the entire model ( ) pickles the entire Python object, including the model architecture and its parameters. Saving just the ( ) saves only a dictionary of the model's parameters (weights and biases).
The recommended approach is to save the because it is more flexible and robust. It decouples the saved weights from the specific code that defined the model, making your code easier to refactor and share without breaking the loading process.
tags: #interview #pytorch #machinelearning
➡ @DataScienceQ
━━━━━━━━━━━━━━━
By: @DataScienceQ ✨
When saving a PyTorch model, what is the difference between saving the entire model versus saving just the model's
state_dict? Which approach is generally recommended and why?Answer:
torch.save(model, PATH)state_dicttorch.save(model.state_dict(), PATH)The recommended approach is to save the
state_dicttags: #interview #pytorch #machinelearning
➡ @DataScienceQ
━━━━━━━━━━━━━━━
By: @DataScienceQ ✨
❔ Interview question
What is the purpose of a pooling layer in a Convolutional Neural Network (CNN)?
Answer:A pooling layer (like Max Pooling or Average Pooling) is used to progressively reduce the spatial size (width and height) of the feature maps. This serves two main purposes: 1) It reduces the number of parameters and computational complexity, which helps to control overfitting. 2) It introduces a degree of translation invariance, meaning the network becomes more robust to small shifts and distortions in the position of features in the input image.
tags: #interview #cnn #deeplearning
━━━━━━━━━━━━━━━
By: @DataScienceQ ✨
What is the purpose of a pooling layer in a Convolutional Neural Network (CNN)?
Answer:
tags: #interview #cnn #deeplearning
━━━━━━━━━━━━━━━
By: @DataScienceQ ✨
❔ Interview question
What is the difference between the
Answer: Theis for loose comparison, checking for value equality after type juggling. For example, is for strict comparison, checking for both value AND type equality, without any type conversion. So, to use to avoid unexpected bugs.
tags: #interview #php
━━━━━━━━━━━━━━━
By: @DataScienceQ ✨
What is the difference between the
== (loose comparison) and === (strict comparison) operators in PHP?Answer: The
== operator 1 == "1" is true. The === operator 1 === "1" is false. It's generally safer ===tags: #interview #php
━━━━━━━━━━━━━━━
By: @DataScienceQ ✨
❔ Interview question
What is the difference between
Answer:only if a variable is declared and is not . In contrast, is considered "falsy", which includes or an empty array. A key difference is that a variable like is set (so is true), but also considered empty (so is true).
tags: #interview #php
━━━━━━━━━━━━━━━
By: @DataScienceQ ✨
What is the difference between
isset() and empty() in PHP?Answer:
isset() returns true NULLempty() returns true if a variable NULL, false, 0, "0", an empty string "", $var = 0; isset()empty()tags: #interview #php
━━━━━━━━━━━━━━━
By: @DataScienceQ ✨
❤1
❔ Interview question
Why is it better to use
Answer: Becausehandles cross-platform compatibility automatically. Operating systems use different path separators (e.g., for Linux/macOS and for Windows). Hardcoding a separator like will break on a different OS. or depending on the system, making the code robust and portable.
tags: #interview #python #os
━━━━━━━━━━━━━━━
By: @DataScienceQ ✨
Why is it better to use
os.path.join() to construct paths instead of simple string concatenation?Answer: Because
os.path.join() /\'folder' + '/' + 'file' os.path.join('folder', 'file') correctly produces folder/filefolder\filetags: #interview #python #os
━━━━━━━━━━━━━━━
By: @DataScienceQ ✨
❤1
How to get the current module's name?
Answer:
tags:
Please open Telegram to view this post
VIEW IN TELEGRAM
❤1
❔ Interview question
When would you use the
Answer:The attribute is used for memory optimization. By defining it in a class, you prevent the creation of a for each instance, instead allocating a fixed amount of space for the specified attributes. This is highly effective when creating a large number of objects. The primary trade-off is that you lose the ability to add new attributes to instances at runtime.
tags: #python #interview
━━━━━━━━━━━━━━━
By: @DataScienceQ ✨
When would you use the
__slots__ attribute in a Python class, and what is its main trade-off?Answer:
__slots____dict__tags: #python #interview
━━━━━━━━━━━━━━━
By: @DataScienceQ ✨
What is
None in Python?Answer:
tags: #interview
Please open Telegram to view this post
VIEW IN TELEGRAM
What is GIL in Python, why is it needed, and how can it be bypassed?
Answer:
However, due to the GIL, multithreading in Python does not provide true CPU-level parallelism: even if multiple threads are created, they will run sequentially rather than simultaneously, which limits performance in computationally intensive tasks.
This limitation can be bypassed by using modules like multiprocessing, which run separate processes with their own memory and their own GIL. Heavy logic can also be moved to native C extensions or interpreters without a GIL, such as Jython or experimental versions of PyPy.
tags: #interview
Please open Telegram to view this post
VIEW IN TELEGRAM
What is the difference between asynchrony, multithreading, and multiprocessing?
Answer:
Multithreading uses multiple threads within one process that share memory and can run in parallel with coordination among them.
Multiprocessing launches several isolated processes, each with its own address space and resources, allowing true parallelism at the CPU level.
Simply put, asynchrony is efficient for I/O tasks, threads are used for tasks with shared data, and processes are for resource-intensive computations where load distribution across cores is important.
tags: #interview
Please open Telegram to view this post
VIEW IN TELEGRAM
❤1
How to view an object's methods?
Answer:
tags: #interview
Please open Telegram to view this post
VIEW IN TELEGRAM
❤2🔥1
❔ Interview Question
What is the GIL (Global Interpreter Lock) in Python, and how does it impact the execution of multi-threaded programs?
Answer: The Global Interpreter Lock (GIL) is a mutex (or a lock) that allows only one thread to hold the control of the Python interpreter at any one time. This means that in a CPython process, only one thread can be executing Python bytecode at any given moment, even on a multi-core processor.
This has a significant impact on performance:
• For CPU-bound tasks: Multi-threaded Python programs see no performance gain from multiple CPU cores. If you have a task that performs heavy calculations (e.g., image processing, complex math), creating multiple threads will not make it run faster. The threads will execute sequentially, not in parallel, because they have to take turns acquiring the GIL.
• For I/O-bound tasks: The GIL is less of a problem. When a thread is waiting for Input/Output (I/O) operations (like waiting for a network response, reading from a file, or querying a database), it releases the GIL. This allows another thread to run. Therefore, the
How to achieve true parallelism?
To bypass the GIL and leverage multiple CPU cores for CPU-bound tasks, you must use the
tags: #Python #Interview #CodingInterview #GIL #Concurrency #Threading #Multiprocessing #SoftwareEngineering
━━━━━━━━━━━━━━━
By: @DataScienceQ ✨
What is the GIL (Global Interpreter Lock) in Python, and how does it impact the execution of multi-threaded programs?
Answer: The Global Interpreter Lock (GIL) is a mutex (or a lock) that allows only one thread to hold the control of the Python interpreter at any one time. This means that in a CPython process, only one thread can be executing Python bytecode at any given moment, even on a multi-core processor.
This has a significant impact on performance:
• For CPU-bound tasks: Multi-threaded Python programs see no performance gain from multiple CPU cores. If you have a task that performs heavy calculations (e.g., image processing, complex math), creating multiple threads will not make it run faster. The threads will execute sequentially, not in parallel, because they have to take turns acquiring the GIL.
• For I/O-bound tasks: The GIL is less of a problem. When a thread is waiting for Input/Output (I/O) operations (like waiting for a network response, reading from a file, or querying a database), it releases the GIL. This allows another thread to run. Therefore, the
threading module is still highly effective for tasks that spend most of their time waiting, as it allows for concurrency.How to achieve true parallelism?
To bypass the GIL and leverage multiple CPU cores for CPU-bound tasks, you must use the
multiprocessing module. It creates separate processes, each with its own Python interpreter and memory space, so the GIL of one process does not affect the others.tags: #Python #Interview #CodingInterview #GIL #Concurrency #Threading #Multiprocessing #SoftwareEngineering
━━━━━━━━━━━━━━━
By: @DataScienceQ ✨
❤1
What objects can be put into a set?
Answer:
Objects like list, dict, set, and other mutable structures cannot be put in: they do not have a hash function (hash) and will cause a TypeError.
ta
Please open Telegram to view this post
VIEW IN TELEGRAM
❤1
What can be a key in a dictionary?
Answer:
tags: #interview
Please open Telegram to view this post
VIEW IN TELEGRAM
❤3
What is a deep copy?
Answer:
In Python, this is done using copy.deepcopy(), which creates a fully independent data structure, including nested lists, dictionaries, and other objects.
tags: #interview
Please open Telegram to view this post
VIEW IN TELEGRAM
👍4❤1
Why does
list.sort() return None instead of the sorted list?Answer:
If a new sorted list is needed, the built-in sorted() function is used, which returns the result without changing the original.
tags: #interview
Please open Telegram to view this post
VIEW IN TELEGRAM
Are there generics in Python like in Java or C++?
Answer:
tags: #interview
Please open Telegram to view this post
VIEW IN TELEGRAM